diff --git a/cmd/scip/convert.go b/cmd/scip/convert.go index e72391e9..ee7b29a1 100644 --- a/cmd/scip/convert.go +++ b/cmd/scip/convert.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "errors" "fmt" "io" @@ -13,7 +14,7 @@ import ( "strings" "github.com/klauspost/compress/zstd" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "google.golang.org/protobuf/proto" "zombiezen.com/go/sqlite" "zombiezen.com/go/sqlite/sqlitex" @@ -51,15 +52,18 @@ Occurrences are stored opaquely as a blob to prevent the DB size from growing ve Value: "", }, }, - Action: func(c *cli.Context) error { - indexPath = c.Args().Get(0) + Action: func(ctx context.Context, cmd *cli.Command) error { + indexPath = cmd.Args().Get(0) if indexPath == "" { return errors.New("missing argument for path to SCIP index") } - err := convertMain(indexPath, outputPath, cpuProfilePath, chunkSizeHint, c.App.Writer) + err := convertMain(indexPath, outputPath, cpuProfilePath, chunkSizeHint) if err == nil { - fmt.Fprintf(c.App.Writer, "Successfully converted SCIP index to SQLite database at %s\n", outputPath) + fmt.Fprintf( + cmd.Root().Writer, + "Successfully converted SCIP index to SQLite database at %s\n", + outputPath) } return err }, @@ -67,7 +71,7 @@ Occurrences are stored opaquely as a blob to prevent the DB size from growing ve return command } -func convertMain(indexPath, sqliteDBPath, cpuProfilePath string, chunkSize int, out io.Writer) (err error) { +func convertMain(indexPath, sqliteDBPath, cpuProfilePath string, chunkSize int) (err error) { index, err := readFromOption(indexPath) if err != nil { return err @@ -76,7 +80,7 @@ func convertMain(indexPath, sqliteDBPath, cpuProfilePath string, chunkSize int, // Create the output directory if it doesn't exist outputDir := filepath.Dir(sqliteDBPath) if outputDir != "." { - if err := os.MkdirAll(outputDir, 0755); err != nil { + if err := os.MkdirAll(outputDir, 0o755); err != nil { return fmt.Errorf("failed to create output directory %s: %w", outputDir, err) } } diff --git a/cmd/scip/lint.go b/cmd/scip/lint.go index 0d7d0e37..c1ad60fa 100644 --- a/cmd/scip/lint.go +++ b/cmd/scip/lint.go @@ -1,12 +1,13 @@ package main import ( + "context" stderrors "errors" "fmt" "sort" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/scip-code/scip/bindings/go/scip" ) @@ -18,8 +19,8 @@ func lintCommand() cli.Command { Description: "Example usage:\n\n scip lint /path/to/index.scip\n\n" + "You may want to filter the output using `grep -v `\n" + "to narrow down on certain classes of errors.", - Action: func(c *cli.Context) error { - indexPath := c.Args().Get(0) + Action: func(ctx context.Context, cmd *cli.Command) error { + indexPath := cmd.Args().Get(0) if indexPath == "" { return stderrors.New("missing argument for path to SCIP index") } diff --git a/cmd/scip/main.go b/cmd/scip/main.go index 554ddfa4..c801b029 100644 --- a/cmd/scip/main.go +++ b/cmd/scip/main.go @@ -1,6 +1,7 @@ package main import ( + "context" _ "embed" "fmt" "log" @@ -8,12 +9,12 @@ import ( "runtime/debug" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func main() { app := scipApp() - if err := app.Run(os.Args); err != nil { + if err := app.Run(context.Background(), os.Args); err != nil { log.Fatal(err) } } @@ -56,8 +57,8 @@ func gitSuffix() string { return fmt.Sprintf("-dev\nSHA: %s\ntimestamp: %s\nclean: %s", rev, timestamp, clean) } -func scipApp() *cli.App { - app := &cli.App{ +func scipApp() *cli.Command { + app := &cli.Command{ Name: "scip", Version: fmt.Sprintf("v%s%s", strings.TrimSpace(version), gitSuffix()), Usage: "SCIP Code Intelligence Protocol CLI", diff --git a/cmd/scip/main_test.go b/cmd/scip/main_test.go index bd83e8cf..8fbdb987 100644 --- a/cmd/scip/main_test.go +++ b/cmd/scip/main_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "os" "path/filepath" @@ -28,7 +29,7 @@ func TestCLIReferenceInSync(t *testing.T) { os.Stdout = w defer func() { os.Stdout = origStdout }() - require.Nil(t, app.Run(args)) + require.Nil(t, app.Run(context.Background(), args)) _, err = w.Write([]byte{0}) // needed for Read below to terminate require.Nil(t, err) helpBytes := make([]byte, 1024*1024) diff --git a/cmd/scip/print.go b/cmd/scip/print.go index a1873ceb..798150ed 100644 --- a/cmd/scip/print.go +++ b/cmd/scip/print.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "io" "os" @@ -9,7 +10,7 @@ import ( "errors" "github.com/k0kubun/pp/v3" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func printCommand() cli.Command { @@ -33,8 +34,8 @@ Do not rely on non-JSON output in scripts`, DefaultText: "true", }, }, - Action: func(c *cli.Context) error { - indexPath := c.Args().Get(0) + Action: func(ctx context.Context, cmd *cli.Command) error { + indexPath := cmd.Args().Get(0) if indexPath == "" { return errors.New("missing argument for path to SCIP index") } @@ -49,7 +50,7 @@ Do not rely on non-JSON output in scripts`, colorOutput = true } } - return printMain(indexPath, colorOutput, jsonOutput, c.App.Writer) + return printMain(indexPath, colorOutput, jsonOutput, cmd.Root().Writer) }, } return snapshot diff --git a/cmd/scip/print_test.go b/cmd/scip/print_test.go index 2f218844..11fb308c 100644 --- a/cmd/scip/print_test.go +++ b/cmd/scip/print_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "encoding/json" "io" "io/ioutil" @@ -40,7 +41,8 @@ func TestJSONPrinting(t *testing.T) { } // Run the JSON command with the temporary file - runErr := app.Run([]string{"scip", "print", "--json", file.Name()}) + runErr := app.Run( + context.Background(), []string{"scip", "print", "--json", file.Name()}) if runErr != nil { log.Fatal(runErr) } diff --git a/cmd/scip/snapshot.go b/cmd/scip/snapshot.go index ea7def65..2f27fcd2 100644 --- a/cmd/scip/snapshot.go +++ b/cmd/scip/snapshot.go @@ -1,11 +1,12 @@ package main import ( + "context" "fmt" "os" "path/filepath" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/scip-code/scip/bindings/go/scip" "github.com/scip-code/scip/bindings/go/scip/testutil" @@ -50,7 +51,7 @@ along with 'git diff' or equivalent, or you can use the dedicated }, commentSyntaxFlag(&snapshotFlags.commentSyntax), }, - Action: func(c *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return snapshotMain(snapshotFlags) }, } diff --git a/cmd/scip/stats.go b/cmd/scip/stats.go index c1a75fd0..789ad5ed 100644 --- a/cmd/scip/stats.go +++ b/cmd/scip/stats.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "log" @@ -12,7 +13,7 @@ import ( "github.com/hhatto/gocloc" "github.com/montanaflynn/stats" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "google.golang.org/protobuf/proto" "github.com/scip-code/scip/bindings/go/scip" @@ -32,7 +33,7 @@ func statsCommand() cli.Command { fromFlag(&statsFlags.from), projectRootFlag(&statsFlags.customProjectRoot), }, - Action: func(c *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return statsMain(statsFlags) }, } diff --git a/cmd/scip/test.go b/cmd/scip/test.go index da4b967e..cf63936a 100644 --- a/cmd/scip/test.go +++ b/cmd/scip/test.go @@ -1,10 +1,11 @@ package main import ( + "context" "fmt" "os" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/scip-code/scip/bindings/go/scip/testutil" ) @@ -12,7 +13,7 @@ import ( type testFlags struct { from string // default: 'index.scip' commentSyntax string // default: '//' - pathFilters cli.StringSlice + pathFilters []string checkDocuments bool // default: false } @@ -50,16 +51,22 @@ use the 'snapshot' subcommand.`, version), Value: false, }, }, - Action: func(c *cli.Context) error { - dir := c.Args().Get(0) + Action: func(ctx context.Context, cmd *cli.Command) error { + dir := cmd.Args().Get(0) index, err := readFromOption(testFlags.from) if err != nil { return err } - err = testutil.RunTests(dir, testFlags.pathFilters.Value(), testFlags.checkDocuments, index, testFlags.commentSyntax, os.Stdout) - if err != nil { + if err = testutil.RunTests( + dir, + testFlags.pathFilters, + testFlags.checkDocuments, + index, + testFlags.commentSyntax, + os.Stdout, + ); err != nil { return cli.Exit("", 1) } return nil diff --git a/docs/CLI.md b/docs/CLI.md index 9a5dc0a7..719fe0f4 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -15,7 +15,7 @@ NAME: scip - SCIP Code Intelligence Protocol CLI USAGE: - scip [global options] command [command options] [arguments...] + scip [global options] [command [command options]] VERSION: v0.7.1 @@ -46,7 +46,7 @@ NAME: scip lint - Flag potential issues with a SCIP index USAGE: - scip lint [command options] [arguments...] + scip lint [options] DESCRIPTION: Example usage: @@ -67,14 +67,14 @@ NAME: scip print - Print a SCIP index for debugging USAGE: - scip print [command options] [arguments...] + scip print [options] DESCRIPTION: WARNING: The TTY output may change over time. Do not rely on non-JSON output in scripts OPTIONS: - --json Output in JSON format (default: false) + --json Output in JSON format --color Enable color output for TTY (no effect for JSON) (default: true) --help, -h show help ``` @@ -86,7 +86,7 @@ NAME: scip snapshot - Generate snapshot files for golden testing USAGE: - scip snapshot [command options] [arguments...] + scip snapshot [options] DESCRIPTION: The snapshot subcommand generates snapshot files which @@ -100,12 +100,12 @@ DESCRIPTION: OPTIONS: - --from value Path to SCIP index file (default: "index.scip") - --to value Path to output directory for snapshot files (default: "scip-snapshot") - --project-root value Override project root in the SCIP file. This can be helpful when the SCIP index was created on another computer - --strict If true, fail fast on errors (default: true) - --comment-syntax value Comment syntax to use for snapshot files (default: "//") - --help, -h show help + --from string Path to SCIP index file (default: "index.scip") + --to string Path to output directory for snapshot files (default: "scip-snapshot") + --project-root string Override project root in the SCIP file. This can be helpful when the SCIP index was created on another computer + --strict If true, fail fast on errors + --comment-syntax string Comment syntax to use for snapshot files (default: "//") + --help, -h show help ``` ## `scip test` @@ -115,7 +115,7 @@ NAME: scip test - Validate a SCIP index against test files USAGE: - scip test [command options] [arguments...] + scip test [options] DESCRIPTION: Validates whether the SCIP data present in an index @@ -133,11 +133,11 @@ DESCRIPTION: use the 'snapshot' subcommand. OPTIONS: - --from value Path to SCIP index file (default: "index.scip") - --comment-syntax value Comment syntax to use for snapshot files (default: "//") - --filter value, -f value [ --filter value, -f value ] Explicit list of test files to check. Can be specified multiple times. If not specified, all files are tested. - --check-documents Whether or not to validate whether every file in the test directory has a correlating document in the SCIP index. (default: false) - --help, -h show help + --from string Path to SCIP index file (default: "index.scip") + --comment-syntax string Comment syntax to use for snapshot files (default: "//") + --filter string, -f string [ --filter string, -f string ] Explicit list of test files to check. Can be specified multiple times. If not specified, all files are tested. + --check-documents Whether or not to validate whether every file in the test directory has a correlating document in the SCIP index. + --help, -h show help ``` ## `scip stats` @@ -147,12 +147,12 @@ NAME: scip stats - Output useful statistics about a SCIP index USAGE: - scip stats [command options] [arguments...] + scip stats [options] OPTIONS: - --from value Path to SCIP index file (default: "index.scip") - --project-root value Override project root in the SCIP file. This can be helpful when the SCIP index was created on another computer - --help, -h show help + --from string Path to SCIP index file (default: "index.scip") + --project-root string Override project root in the SCIP file. This can be helpful when the SCIP index was created on another computer + --help, -h show help ``` ## `scip expt-convert` @@ -162,7 +162,7 @@ NAME: scip expt-convert - [EXPERIMENTAL] Convert a SCIP index to a SQLite database USAGE: - scip expt-convert [command options] [arguments...] + scip expt-convert [options] DESCRIPTION: Converts a SCIP index to a SQLite database. @@ -173,7 +173,7 @@ DESCRIPTION: Occurrences are stored opaquely as a blob to prevent the DB size from growing very quickly. OPTIONS: - --output value Path to output SQLite database file (default: "index.db") - --cpu-profile value Path to output prof file - --help, -h show help + --output string Path to output SQLite database file (default: "index.db") + --cpu-profile string Path to output prof file + --help, -h show help ``` diff --git a/flake.nix b/flake.nix index 0fad9a70..beb95f26 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ inherit version; src = ./.; - vendorHash = "sha256-s3CTaI8rw8bjFMz4KAIQBGEtQy587H1DAC5C9ueUMu4="; + vendorHash = "sha256-WheG2CpEUDtzpqRuzRu+g0hDrfqVZu+2GNCntNJdfDQ="; proxyVendor = true; subPackages = [ "cmd/scip" ]; diff --git a/go.mod b/go.mod index 85bc2b42..8890e314 100644 --- a/go.mod +++ b/go.mod @@ -11,13 +11,12 @@ require ( github.com/montanaflynn/stats v0.9.0 github.com/scip-code/scip/bindings/go/scip v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.11.1 - github.com/urfave/cli/v2 v2.25.7 + github.com/urfave/cli/v3 v3.9.0 google.golang.org/protobuf v1.36.11 zombiezen.com/go/sqlite v1.4.2 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/fatih/color v1.19.0 // indirect @@ -30,10 +29,8 @@ require ( github.com/ncruces/go-strftime v0.1.9 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a // indirect github.com/spf13/afero v1.10.0 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect golang.org/x/sys v0.42.0 // indirect golang.org/x/text v0.34.0 // indirect diff --git a/go.sum b/go.sum index e5287cba..3791182d 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0= -github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -169,8 +167,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a h1:j/CQ27s679M9wRGBRJYyXGrfkYuQA6VMnD7R08mHD9c= github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a/go.mod h1:JG1sdvGTKWwe/oH3/3UKQ26vfcHIN//7fwEJhoqaBcM= github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= @@ -182,10 +178,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= -github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/urfave/cli/v3 v3.9.0 h1:AV9lIiPv3ukYnxunaCUsHnEozptYmDN2F0+yWqLMn/c= +github.com/urfave/cli/v3 v3.9.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/go.work.sum b/go.work.sum index 03052b17..2f3df4b6 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,3 +1,9 @@ +crawshaw.io/iox v0.0.0-20181124134642-c51c3df30797/go.mod h1:sXBiorCo8c46JlQV3oXPKINnZ8mcqnye1EkVkqsectk= +github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM= golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4/go.mod h1:g5NllXBEermZrmR51cJDQxmJUHUOfRAaNyWBM+R+548=