Skip to content

Commit 9f4b3be

Browse files
committed
start using urfave-cli v3
- only used when SRC_INTERNAL_CLIFLAGS_V2 is 1 - add 'old' command, which runs the usual src cli commands until all commands are migrated
1 parent 10d1e1c commit 9f4b3be

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

cmd/src/main.go

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

33
import (
4+
"context"
45
"encoding/json"
56
"flag"
67
"io"
@@ -12,6 +13,8 @@ import (
1213
"slices"
1314
"strings"
1415

16+
"github.com/urfave/cli/v3"
17+
1518
"github.com/sourcegraph/sourcegraph/lib/errors"
1619

1720
"github.com/sourcegraph/src-cli/internal/api"
@@ -85,11 +88,56 @@ var (
8588
// commands contains all registered subcommands.
8689
var commands commander
8790

91+
var mainCmd = &cli.Command{
92+
Name: "src",
93+
Aliases: []string{},
94+
Usage: "Sourcegraph CLI tool",
95+
ArgsUsage: "command [options]",
96+
Version: "dev",
97+
Description: `src is a tool that provides access to Sourcegraph instances.
98+
For more information, see https://github.com/sourcegraph/src-cli`,
99+
DefaultCommand: "old",
100+
Category: "",
101+
Commands: []*cli.Command{
102+
oldSrcCmd,
103+
},
104+
Flags: []cli.Flag{},
105+
InvalidFlagAccessHandler: nil,
106+
Hidden: false,
107+
Authors: []any{},
108+
Copyright: "Sourcegraph, Inc.",
109+
HideVersion: false,
110+
}
111+
112+
// oldSrcCmd is a temporary command that just runs the old cli.
113+
//
114+
// Any top level flags like --help / -v will be capture by urfave parser
115+
var oldSrcCmd = &cli.Command{
116+
Name: "old",
117+
Description: "run the old src command line parser",
118+
Hidden: true,
119+
HideHelp: true,
120+
Action: func(ctx context.Context, c *cli.Command) error {
121+
oldRun()
122+
return nil
123+
},
124+
}
125+
88126
func main() {
89127
// Configure logging.
90128
log.SetFlags(0)
91129
log.SetPrefix("")
92130

131+
if os.Getenv("SRC_INTERNAL_CLIFLAGS_V2") == "1" {
132+
if err := mainCmd.Run(context.Background(), os.Args); err != nil {
133+
log.Fatal(err)
134+
}
135+
} else {
136+
oldRun()
137+
}
138+
}
139+
140+
func oldRun() {
93141
commands.run(flag.CommandLine, "src", usageText, normalizeDashHelp(os.Args[1:]))
94142
}
95143

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/sourcegraph/scip v0.6.1
3030
github.com/sourcegraph/sourcegraph/lib v0.0.0-20240709083501-1af563b61442
3131
github.com/stretchr/testify v1.11.1
32+
github.com/urfave/cli/v3 v3.6.1
3233
golang.org/x/net v0.44.0
3334
golang.org/x/sync v0.17.0
3435
google.golang.org/api v0.132.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD
451451
github.com/tetratelabs/wazero v1.3.0 h1:nqw7zCldxE06B8zSZAY0ACrR9OH5QCcPwYmYlwtcwtE=
452452
github.com/tetratelabs/wazero v1.3.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
453453
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
454+
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
455+
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
454456
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
455457
github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY=
456458
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=

0 commit comments

Comments
 (0)