Skip to content
Merged
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
18 changes: 11 additions & 7 deletions cmd/scip/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"errors"
"fmt"
"io"
Expand All @@ -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"
Expand Down Expand Up @@ -51,23 +52,26 @@ 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
},
}
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
Expand All @@ -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)
}
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/scip/lint.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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 <pattern>`\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")
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/scip/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package main

import (
"context"
_ "embed"
"fmt"
"log"
"os"
"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)
}
}
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion cmd/scip/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions cmd/scip/print.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"io"
"os"
Expand All @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion cmd/scip/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/scip/snapshot.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/scip/stats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"fmt"
"log"
Expand All @@ -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"
Expand All @@ -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)
},
}
Expand Down
19 changes: 13 additions & 6 deletions cmd/scip/test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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"
)

type testFlags struct {
from string // default: 'index.scip'
commentSyntax string // default: '//'
pathFilters cli.StringSlice
pathFilters []string
checkDocuments bool // default: false
}

Expand Down Expand Up @@ -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
Expand Down
Loading
Loading