-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `cmd.ProcessArgs` is changed to contain only the arguments, skip the `argv[0]` process name - Internal `getCompletionRequest` returns adjusted index, where 0 is valid; return -1 when no completion request pending - Adjust all test feeding `cmd.ProcessArgs` to not include command name - Add `Name` and `SubCommands` fields to `Command` definition. - `Command.Run()` locates the requested sub-command, and invokes it in place of the root command.
- Loading branch information
1 parent
ddbac18
commit a11653e
Showing
10 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/maargenton/go-cli" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func main() { | ||
cli.Run(&cli.Command{ | ||
Handler: &ServerCmd{}, | ||
Description: "API server for demo service", | ||
|
||
SubCommands: []cli.Command{ | ||
{ | ||
Name: "migrate", | ||
Description: "run DB migration", | ||
Handler: &MigrateCmd{}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
type BaseOpts struct { | ||
Debug bool `opts:"-d,--debug" desc:"generating more diagnostic upon error"` | ||
Verbose bool `opts:"-v,--verbose" desc:"display additional information on startup"` | ||
|
||
DB string `opts:"--db" desc:"primary DB connection string"` | ||
DBPasswd string `opts:"--db-passwd" desc:"primary DB password"` | ||
} | ||
|
||
func (options *BaseOpts) Version() string { | ||
return "subcmd-demo v0.1.2" | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
type ServerCmd struct { | ||
BaseOpts | ||
} | ||
|
||
func (options *ServerCmd) Run() error { | ||
d, err := yaml.Marshal(options) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("Running server with options:\n%v\n", string(d)) | ||
return nil | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
type MigrateCmd struct { | ||
BaseOpts | ||
|
||
SkipDups bool `opts:"--skip-duplicates" desc:"skip duplicates during migration"` | ||
} | ||
|
||
func (options *MigrateCmd) Run() error { | ||
d, err := yaml.Marshal(options) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("Running migration with options:\n%v\n", string(d)) | ||
return nil | ||
} |