Skip to content

Commit 100ab03

Browse files
committed
add tool subcommand that uses urfave-cli v3
1 parent 9f4b3be commit 100ab03

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

cmd/src/main.go

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"slices"
1414
"strings"
1515

16-
"github.com/urfave/cli/v3"
17-
1816
"github.com/sourcegraph/sourcegraph/lib/errors"
1917

2018
"github.com/sourcegraph/src-cli/internal/api"
@@ -66,6 +64,7 @@ The commands are:
6664
search search for results on Sourcegraph
6765
search-jobs manages search jobs
6866
serve-git serves your local git repositories over HTTP for Sourcegraph to pull
67+
tool exposes tools for AI agents to interact with Sourcegraph
6968
users,user manages users
7069
codeowners manages code ownership information
7170
version display and compare the src-cli version against the recommended version for your instance
@@ -88,56 +87,19 @@ var (
8887
// commands contains all registered subcommands.
8988
var commands commander
9089

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-
12690
func main() {
12791
// Configure logging.
12892
log.SetFlags(0)
12993
log.SetPrefix("")
13094

131-
if os.Getenv("SRC_INTERNAL_CLIFLAGS_V2") == "1" {
132-
if err := mainCmd.Run(context.Background(), os.Args); err != nil {
95+
// Handle "tool" subcommand specially - it uses urfave/cli/v3
96+
if len(os.Args) >= 2 && os.Args[1] == "tool" {
97+
if err := toolCmd.Run(context.Background(), os.Args[1:]); err != nil {
13398
log.Fatal(err)
13499
}
135-
} else {
136-
oldRun()
100+
return
137101
}
138-
}
139102

140-
func oldRun() {
141103
commands.run(flag.CommandLine, "src", usageText, normalizeDashHelp(os.Args[1:]))
142104
}
143105

@@ -369,4 +331,4 @@ func expandHomeDir(filePath string) (string, error) {
369331
}
370332

371333
return filePath, nil
372-
}
334+
}

cmd/src/tool.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/urfave/cli/v3"
9+
)
10+
11+
var toolCmd = &cli.Command{
12+
Name: "src tool",
13+
Usage: "Exposes tools for AI agents to interact with Sourcegraph",
14+
Description: "The tool subcommand exposes tools that can be used by AI agents to perform tasks against Sourcegraph instances.",
15+
Commands: []*cli.Command{},
16+
Writer: os.Stdout,
17+
Action: func(ctx context.Context, c *cli.Command) error {
18+
fmt.Println("------ UNDER CONSTRUCTION -------")
19+
return nil
20+
},
21+
}

0 commit comments

Comments
 (0)