Skip to content

Commit 5a93399

Browse files
authored
Use native --version support in urfave/cli/v2 (#97)
1 parent 1604358 commit 5a93399

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ NAME:
6060
USAGE:
6161
scip [global options] command [command options] [arguments...]
6262
63+
VERSION:
64+
v0.2.1-git
65+
6366
DESCRIPTION:
6467
For more details, see the project README at:
6568
@@ -69,11 +72,12 @@ COMMANDS:
6972
convert Convert a SCIP index to an LSIF index
7073
snapshot Generate snapshot files for golden testing
7174
stats Output useful statistics about a SCIP index
75+
print Print a SCIP index in a human-readable format for debugging
7276
help, h Shows a list of commands or help for one command
7377
7478
GLOBAL OPTIONS:
7579
--help, -h show help (default: false)
76-
--version, -v Print the current version and exit. (default: false)
80+
--version, -v print the version (default: false)
7781
```
7882

7983
### `scip convert`

cmd/main.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"log"
65
"os"
76

@@ -23,29 +22,13 @@ func commands() []*cli.Command {
2322
return []*cli.Command{&convert, &snapshot, &stats, &print}
2423
}
2524

26-
func scipApp() cli.App {
27-
var versionFlag bool
28-
app := cli.App{
25+
func scipApp() *cli.App {
26+
app := &cli.App{
2927
Name: "scip",
28+
Version: "v0.2.1-git",
3029
Usage: "SCIP Code Intelligence Protocol CLI",
3130
Description: "For more details, see the project README at:\n\n\thttps://github.com/sourcegraph/scip",
32-
Flags: []cli.Flag{
33-
&cli.BoolFlag{
34-
Name: "version",
35-
Usage: "Print the current version and exit.",
36-
Destination: &versionFlag,
37-
Aliases: []string{"v"},
38-
},
39-
},
40-
Action: func(c *cli.Context) error {
41-
if versionFlag {
42-
fmt.Println("0.1.0")
43-
os.Exit(0)
44-
}
45-
// FIXME: What is the right way to print help text and error here?
46-
return nil
47-
},
48-
Commands: commands(),
31+
Commands: commands(),
4932
}
5033
return app
5134
}

cmd/main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"strings"
1011
"testing"
1112

@@ -39,6 +40,8 @@ func TestReadmeInSync(t *testing.T) {
3940
helpBytes = helpBytes[:n-1] // ignore NULL at end
4041
require.Nil(t, err)
4142
help := strings.TrimSpace(string(helpBytes))
43+
re := regexp.MustCompile(`(?m)\s+$`) // strip trailing whitespace
44+
help = re.ReplaceAllString(help, "\n")
4245
require.Truef(t, strings.Contains(readme, help),
4346
"Readme.md missing help text %s for %s.\nRun `%s` and paste the output in the Readme.",
4447
help, commandName, strings.Join(append([]string{"scip"}, args...), " "))

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3
1313
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220511160847-5a43d3ea24eb
1414
github.com/stretchr/testify v1.7.1
15-
github.com/urfave/cli/v2 v2.8.1
15+
github.com/urfave/cli/v2 v2.17.1
1616
golang.org/x/tools v0.1.10
1717
google.golang.org/protobuf v1.28.0
1818
)
@@ -24,7 +24,7 @@ require (
2424
github.com/cockroachdb/errors v1.8.9 // indirect
2525
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
2626
github.com/cockroachdb/redact v1.1.3 // indirect
27-
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
27+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
2828
github.com/davecgh/go-spew v1.1.1 // indirect
2929
github.com/envoyproxy/protoc-gen-validate v0.3.0-java // indirect
3030
github.com/getsentry/sentry-go v0.12.0 // indirect
@@ -76,5 +76,5 @@ require (
7676
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 // indirect
7777
google.golang.org/grpc v1.45.0 // indirect
7878
gopkg.in/yaml.v2 v2.4.0 // indirect
79-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
79+
gopkg.in/yaml.v3 v3.0.1 // indirect
8080
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
5151
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
5252
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
5353
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
54+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
55+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
5456
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
5557
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5658
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -325,6 +327,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
325327
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
326328
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
327329
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
330+
github.com/urfave/cli/v2 v2.17.1 h1:UzjDEw2dJQUE3iRaiNQ1VrVFbyAtKGH3VdkMoHA58V0=
331+
github.com/urfave/cli/v2 v2.17.1/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
328332
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
329333
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
330334
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
@@ -534,5 +538,7 @@ gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C
534538
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
535539
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
536540
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
541+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
542+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
537543
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
538544
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 commit comments

Comments
 (0)