Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -s -w -X github.com/ViRb3/wgcf/v2/cmd.version=v{{.Version}}
flags:
- -trimpath
goos:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ You can find pre-compiled binaries on the [releases page](https://github.com/ViR
## Usage
Run `wgcf` in a terminal without any arguments to display the help screen. All commands and parameters are documented.

### Check version

To display the current wgcf version, run:

```bash
wgcf --version
```

The output contains only the version string, matching the GitHub release tag (e.g., `v2.3.1`). Development builds report `dev` unless a version is specified at build time.

### Register new account
Run the following command in a terminal:
```bash
Expand Down
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (
"github.com/spf13/viper"
)

var version = "dev"
var cfgFile string

var RootCmd = &cobra.Command{
Use: "wgcf",
Short: "WireGuard Cloudflare Warp utility",
Version: version,
Use: "wgcf",
Short: "WireGuard Cloudflare Warp utility",
Long: FormatMessage("", `
wgcf is a utility for Cloudflare Warp that allows you to create and
manage accounts, assign license keys, and generate WireGuard profiles.
Expand All @@ -37,6 +39,7 @@ func Execute() error {

func init() {
cobra.OnInitialize(initConfig)
RootCmd.SetVersionTemplate("{{.Version}}\n")
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "wgcf-account.toml", "Configuration file")
RootCmd.AddCommand(register.Cmd)
RootCmd.AddCommand(update.Cmd)
Expand Down
59 changes: 59 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"bytes"
"os/exec"
"path/filepath"
"runtime"
"testing"
)

func TestVersionDevOutputFormat(t *testing.T) {
var output bytes.Buffer

RootCmd.SetOut(&output)
RootCmd.SetArgs([]string{"--version"})

t.Cleanup(func() {
RootCmd.SetOut(nil)
RootCmd.SetArgs(nil)
})

if err := RootCmd.Execute(); err != nil {
t.Fatal(err)
}

want := version + "\n"
if got := output.String(); got != want {
t.Errorf("got %q, want %q", got, want)
}
}

func TestVersionSetOnBuild(t *testing.T) {
const want = "v5.5.5\n"

binary := filepath.Join(t.TempDir(), "wgcf")
if runtime.GOOS == "windows" {
binary += ".exe"
}

build := exec.Command(
"go", "build",
"-ldflags", "-X github.com/ViRb3/wgcf/v2/cmd.version=v5.5.5",
"-o", binary,
"..",
)

if output, err := build.CombinedOutput(); err != nil {
t.Fatalf("go build failed: %v\n%s", err, string(output))
}

output, err := exec.Command(binary, "--version").Output()
if err != nil {
t.Fatalf("go version failed: %v\n%s", err, string(output))
}

if string(output) != want {
t.Errorf("got %q, want %q", string(output), want)
}
}