11package main
22
33import (
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.
8689var 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+
88126func 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
0 commit comments