lib: Update for urfave/cli v2

This commit is contained in:
Felix Frank
2019-11-12 01:47:26 +01:00
parent 4b4b7dc169
commit 7cc9ab9083
8 changed files with 120 additions and 120 deletions

View File

@@ -66,21 +66,21 @@ type GAPI struct {
// CliFlags returns a list of flags used by the specified subcommand.
func (obj *GAPI) CliFlags(command string) []cli.Flag {
result := []cli.Flag{}
modulePath := cli.StringFlag{
Name: flagModulePath,
Value: "", // empty by default
Usage: "choose the modules path (absolute)",
EnvVar: "MGMT_MODULE_PATH",
modulePath := &cli.StringFlag{
Name: flagModulePath,
Value: "", // empty by default
Usage: "choose the modules path (absolute)",
EnvVars: []string{"MGMT_MODULE_PATH"},
}
// add this only to run (not needed for get or deploy)
if command == gapi.CommandRun {
runFlags := []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: flagDownload,
Usage: "download any missing imports (as the get command does)",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "update",
Usage: "update all dependencies to the latest versions",
},
@@ -91,12 +91,12 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
switch command {
case gapi.CommandGet:
flags := []cli.Flag{
cli.IntFlag{
&cli.IntFlag{
Name: "depth d",
Value: -1,
Usage: "max recursion depth limit (-1 is unlimited)",
},
cli.IntFlag{
&cli.IntFlag{
Name: "retry r",
Value: 0, // any error is a failure by default
Usage: "max number of retries (-1 is unlimited)",
@@ -110,7 +110,7 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
case gapi.CommandDeploy:
flags := []cli.Flag{
// TODO: removed (temporarily?)
//cli.BoolFlag{
//*cli.BoolFlag{
// Name: "stdin",
// Usage: "use passthrough stdin",
//},
@@ -140,7 +140,7 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
// is passed in.
func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
c := cliInfo.CliContext
cliContext := c.Parent()
cliContext := c.Lineage()[1]
if cliContext == nil {
return nil, fmt.Errorf("could not get cli context")
}
@@ -397,8 +397,8 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
return &gapi.Deploy{
Name: Name,
Noop: c.GlobalBool("noop"),
Sema: c.GlobalInt("sema"),
Noop: c.Bool("noop"),
Sema: c.Int("sema"),
GAPI: &GAPI{
InputURI: fs.URI(),
// TODO: add properties here...
@@ -611,7 +611,7 @@ func (obj *GAPI) Close() error {
// also work when called with the download flag during a normal execution run.
func (obj *GAPI) Get(getInfo *gapi.GetInfo) error {
c := getInfo.CliContext
cliContext := c.Parent()
cliContext := c.Lineage()[1]
if cliContext == nil {
return fmt.Errorf("could not get cli context")
}

View File

@@ -73,13 +73,13 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
langFlags := (&lang.GAPI{}).CliFlags(command)
puppetFlags := (&puppet.GAPI{}).CliFlags(command)
l := cli.StringFlag{
l := &cli.StringFlag{
Name: fmt.Sprintf("%s, %s", lang.Name, lang.Name[0:1]),
Value: "",
Usage: "code to deploy",
}
langFlags = append(langFlags, l)
p := cli.StringFlag{
p := &cli.StringFlag{
Name: fmt.Sprintf("%s, %s", puppet.Name, puppet.Name[0:1]),
Value: "",
Usage: "load graph from puppet, optionally takes a manifest or path to manifest file",
@@ -89,9 +89,9 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
var childFlags []cli.Flag
for _, flag := range append(langFlags, puppetFlags...) {
childFlags = append(childFlags, &cli.StringFlag{
Name: FlagPrefix + strings.Split(flag.GetName(), ",")[0],
Name: FlagPrefix + flag.Names()[0],
Value: "",
Usage: fmt.Sprintf("equivalent for '%s' when using the lang/puppet entrypoint", flag.GetName()),
Usage: fmt.Sprintf("equivalent for '%s' when using the lang/puppet entrypoint", flag.Names()[0]),
})
}
@@ -136,14 +136,14 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
var puppetDeploy *gapi.Deploy
// XXX: put the c.String(FlagPrefix+lang.Name) into the argv here!
langCliInfo := &gapi.CliInfo{
CliContext: cli.NewContext(c.App, flagSet, c.Parent()),
CliContext: cli.NewContext(c.App, flagSet, c.Lineage()[1]),
Fs: fs,
Debug: debug,
Logf: logf, // TODO: wrap logf?
}
// XXX: put the c.String(FlagPrefix+puppet.Name) into the argv here!
puppetCliInfo := &gapi.CliInfo{
CliContext: cli.NewContext(c.App, flagSet, c.Parent()),
CliContext: cli.NewContext(c.App, flagSet, c.Lineage()[1]),
Fs: fs,
Debug: debug,
Logf: logf, // TODO: wrap logf?
@@ -160,8 +160,8 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
return &gapi.Deploy{
Name: Name,
Noop: c.GlobalBool("noop"),
Sema: c.GlobalInt("sema"),
Noop: c.Bool("noop"),
Sema: c.Int("sema"),
GAPI: &GAPI{
langGAPI: langDeploy.GAPI,
puppetGAPI: puppetDeploy.GAPI,

View File

@@ -41,155 +41,155 @@ func CLI(program, version string, flags Flags) error {
}
// All of these flags can be accessed in your GAPI implementation with
// the `c.Parent().Type` and `c.Parent().IsSet` functions. Their own
// the `c.Lineage()[1].Type` and `c.Lineage()[1].IsSet` functions. Their own
// flags can be accessed with `c.Type` and `c.IsSet` directly.
runFlags := []cli.Flag{
// common flags which all can use
// useful for testing multiple instances on same machine
cli.StringFlag{
&cli.StringFlag{
Name: "hostname",
Value: "",
Usage: "hostname to use",
},
cli.StringFlag{
Name: "prefix",
Usage: "specify a path to the working prefix directory",
EnvVar: "MGMT_PREFIX",
&cli.StringFlag{
Name: "prefix",
Usage: "specify a path to the working prefix directory",
EnvVars: []string{"MGMT_PREFIX"},
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "tmp-prefix",
Usage: "request a pseudo-random, temporary prefix to be used",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "allow-tmp-prefix",
Usage: "allow creation of a new temporary prefix if main prefix is unavailable",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-watch",
Usage: "do not update graph under any switch events",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-stream-watch",
Usage: "do not update graph on stream switch events",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-deploy-watch",
Usage: "do not change deploys after an initial deploy",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "noop",
Usage: "globally force all resources into no-op mode",
},
cli.IntFlag{
&cli.IntFlag{
Name: "sema",
Value: -1,
Usage: "globally add a semaphore to all resources with this lock count",
},
cli.StringFlag{
&cli.StringFlag{
Name: "graphviz, g",
Value: "",
Usage: "output file for graphviz data",
},
cli.StringFlag{
&cli.StringFlag{
Name: "graphviz-filter, gf",
Value: "",
Usage: "graphviz filter to use",
},
cli.Int64Flag{
Name: "converged-timeout, t",
Value: -1,
Usage: "after approximately this many seconds without activity, we're considered to be in a converged state",
EnvVar: "MGMT_CONVERGED_TIMEOUT",
&cli.Int64Flag{
Name: "converged-timeout, t",
Value: -1,
Usage: "after approximately this many seconds without activity, we're considered to be in a converged state",
EnvVars: []string{"MGMT_CONVERGED_TIMEOUT"},
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "converged-timeout-no-exit",
Usage: "don't exit on converged-timeout",
},
cli.StringFlag{
&cli.StringFlag{
Name: "converged-status-file",
Value: "",
Usage: "file to append the current converged state to, mostly used for testing",
},
cli.IntFlag{
Name: "max-runtime",
Value: 0,
Usage: "exit after a maximum of approximately this many seconds",
EnvVar: "MGMT_MAX_RUNTIME",
&cli.IntFlag{
Name: "max-runtime",
Value: 0,
Usage: "exit after a maximum of approximately this many seconds",
EnvVars: []string{"MGMT_MAX_RUNTIME"},
},
// if empty, it will startup a new server
cli.StringSliceFlag{
Name: "seeds, s",
Value: &cli.StringSlice{}, // empty slice
Usage: "default etc client endpoint",
EnvVar: "MGMT_SEEDS",
&cli.StringSliceFlag{
Name: "seeds, s",
Value: &cli.StringSlice{}, // empty slice
Usage: "default etc client endpoint",
EnvVars: []string{"MGMT_SEEDS"},
},
// port 2379 and 4001 are common
cli.StringSliceFlag{
Name: "client-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for client traffic",
EnvVar: "MGMT_CLIENT_URLS",
&cli.StringSliceFlag{
Name: "client-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for client traffic",
EnvVars: []string{"MGMT_CLIENT_URLS"},
},
// port 2380 and 7001 are common
cli.StringSliceFlag{
Name: "server-urls, peer-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for server (peer) traffic",
EnvVar: "MGMT_SERVER_URLS",
&cli.StringSliceFlag{
Name: "server-urls, peer-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for server (peer) traffic",
EnvVars: []string{"MGMT_SERVER_URLS"},
},
// port 2379 and 4001 are common
cli.StringSliceFlag{
Name: "advertise-client-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for client traffic",
EnvVar: "MGMT_ADVERTISE_CLIENT_URLS",
&cli.StringSliceFlag{
Name: "advertise-client-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for client traffic",
EnvVars: []string{"MGMT_ADVERTISE_CLIENT_URLS"},
},
// port 2380 and 7001 are common
cli.StringSliceFlag{
Name: "advertise-server-urls, advertise-peer-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for server (peer) traffic",
EnvVar: "MGMT_ADVERTISE_SERVER_URLS",
&cli.StringSliceFlag{
Name: "advertise-server-urls, advertise-peer-urls",
Value: &cli.StringSlice{},
Usage: "list of URLs to listen on for server (peer) traffic",
EnvVars: []string{"MGMT_ADVERTISE_SERVER_URLS"},
},
cli.IntFlag{
Name: "ideal-cluster-size",
Value: -1,
Usage: "ideal number of server peers in cluster; only read by initial server",
EnvVar: "MGMT_IDEAL_CLUSTER_SIZE",
&cli.IntFlag{
Name: "ideal-cluster-size",
Value: -1,
Usage: "ideal number of server peers in cluster; only read by initial server",
EnvVars: []string{"MGMT_IDEAL_CLUSTER_SIZE"},
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-server",
Usage: "do not start embedded etcd server (do not promote from client to peer)",
},
cli.BoolFlag{
Name: "no-network",
Usage: "run single node instance without clustering or opening tcp ports to the outside",
EnvVar: "MGMT_NO_NETWORK",
&cli.BoolFlag{
Name: "no-network",
Usage: "run single node instance without clustering or opening tcp ports to the outside",
EnvVars: []string{"MGMT_NO_NETWORK"},
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-pgp",
Usage: "don't create pgp keys",
},
cli.StringFlag{
&cli.StringFlag{
Name: "pgp-key-path",
Value: "",
Usage: "path for instance key pair",
},
cli.StringFlag{
&cli.StringFlag{
Name: "pgp-identity",
Value: "",
Usage: "default identity used for generation",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "prometheus",
Usage: "start a prometheus instance",
},
cli.StringFlag{
&cli.StringFlag{
Name: "prometheus-listen",
Value: "",
Usage: "specify prometheus instance binding",
@@ -197,51 +197,51 @@ func CLI(program, version string, flags Flags) error {
}
deployFlags := []cli.Flag{
// common flags which all can use
cli.StringSliceFlag{
Name: "seeds, s",
Value: &cli.StringSlice{}, // empty slice
Usage: "default etc client endpoint",
EnvVar: "MGMT_SEEDS",
&cli.StringSliceFlag{
Name: "seeds, s",
Value: &cli.StringSlice{}, // empty slice
Usage: "default etc client endpoint",
EnvVars: []string{"MGMT_SEEDS"},
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "noop",
Usage: "globally force all resources into no-op mode",
},
cli.IntFlag{
&cli.IntFlag{
Name: "sema",
Value: -1,
Usage: "globally add a semaphore to all resources with this lock count",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-git",
Usage: "don't look at git commit id for safe deploys",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "force",
Usage: "force a new deploy, even if the safety chain would break",
},
}
getFlags := []cli.Flag{
// common flags which all can use
cli.BoolFlag{
&cli.BoolFlag{
Name: "noop",
Usage: "simulate the download (can't recurse)",
},
cli.IntFlag{
&cli.IntFlag{
Name: "sema",
Value: -1, // maximum parallelism
Usage: "globally add a semaphore to downloads with this lock count",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "update",
Usage: "update all dependencies to the latest versions",
},
}
subCommandsRun := []cli.Command{} // run sub commands
subCommandsDeploy := []cli.Command{} // deploy sub commands
subCommandsGet := []cli.Command{} // get (download) sub commands
subCommandsRun := []*cli.Command{} // run sub commands
subCommandsDeploy := []*cli.Command{} // deploy sub commands
subCommandsGet := []*cli.Command{} // get (download) sub commands
names := []string{}
for name := range gapi.RegisteredGAPIs {
@@ -253,7 +253,7 @@ func CLI(program, version string, flags Flags) error {
fn := gapi.RegisteredGAPIs[name]
gapiObj := fn()
commandRun := cli.Command{
commandRun := &cli.Command{
Name: name,
Usage: fmt.Sprintf("run using the `%s` frontend", name),
Action: func(c *cli.Context) error {
@@ -268,7 +268,7 @@ func CLI(program, version string, flags Flags) error {
}
subCommandsRun = append(subCommandsRun, commandRun)
commandDeploy := cli.Command{
commandDeploy := &cli.Command{
Name: name,
Usage: fmt.Sprintf("deploy using the `%s` frontend", name),
Action: func(c *cli.Context) error {
@@ -284,7 +284,7 @@ func CLI(program, version string, flags Flags) error {
subCommandsDeploy = append(subCommandsDeploy, commandDeploy)
if _, ok := gapiObj.(gapi.GettableGAPI); ok {
commandGet := cli.Command{
commandGet := &cli.Command{
Name: name,
Usage: fmt.Sprintf("get (download) using the `%s` frontend", name),
Action: func(c *cli.Context) error {
@@ -329,13 +329,13 @@ func CLI(program, version string, flags Flags) error {
// global flags
app.Flags = []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "license",
Usage: "prints the software license",
},
}
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
//{
// Name: gapi.CommandTODO,
// Aliases: []string{"TODO"},
@@ -350,7 +350,7 @@ func CLI(program, version string, flags Flags) error {
// agnostic to which frontend is running, in fact, you can deploy with
// multiple different frontends, one after another, on the same engine.
if len(subCommandsRun) > 0 {
commandRun := cli.Command{
commandRun := &cli.Command{
Name: gapi.CommandRun,
Aliases: []string{"r"},
Usage: "run",
@@ -361,7 +361,7 @@ func CLI(program, version string, flags Flags) error {
}
if len(subCommandsDeploy) > 0 {
commandDeploy := cli.Command{
commandDeploy := &cli.Command{
Name: gapi.CommandDeploy,
Aliases: []string{"d"},
Usage: "deploy",
@@ -372,7 +372,7 @@ func CLI(program, version string, flags Flags) error {
}
if len(subCommandsGet) > 0 {
commandGet := cli.Command{
commandGet := &cli.Command{
Name: gapi.CommandGet,
Aliases: []string{"g"},
Usage: "get",

View File

@@ -44,7 +44,7 @@ const (
// deploy is the cli target to manage deploys to our cluster.
// TODO: add a timeout and/or cancel signal to replace context.TODO()
func deploy(c *cli.Context, name string, gapiObj gapi.GAPI) error {
cliContext := c.Parent()
cliContext := c.Lineage()[1]
if cliContext == nil {
return fmt.Errorf("could not get cli context")
}

View File

@@ -28,7 +28,7 @@ import (
// get is the cli target to run code/import downloads.
func get(c *cli.Context, name string, gapiObj gapi.GAPI) error {
cliContext := c.Parent()
cliContext := c.Lineage()[1]
if cliContext == nil {
return fmt.Errorf("could not get cli context")
}

View File

@@ -35,7 +35,7 @@ import (
// run is the main run target.
func run(c *cli.Context, name string, gapiObj gapi.GAPI) error {
cliContext := c.Parent() // these are the flags from `run`
cliContext := c.Lineage()[1] // these are the flags from `run`
if cliContext == nil {
return fmt.Errorf("could not get cli context")
}

View File

@@ -70,7 +70,7 @@ func (obj *GAPI) CliFlags(command string) []cli.Flag {
fallthrough
case gapi.CommandDeploy:
return []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "puppet-conf",
Value: "",
Usage: "the path to an alternate puppet.conf file",
@@ -157,8 +157,8 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
return &gapi.Deploy{
Name: Name,
Noop: c.GlobalBool("noop"),
Sema: c.GlobalInt("sema"),
Noop: c.Bool("noop"),
Sema: c.Int("sema"),
GAPI: &GAPI{
InputURI: fs.URI(),
Mode: mode,

View File

@@ -93,8 +93,8 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
return &gapi.Deploy{
Name: Name,
Noop: c.GlobalBool("noop"),
Sema: c.GlobalInt("sema"),
Noop: c.Bool("noop"),
Sema: c.Int("sema"),
GAPI: &GAPI{
InputURI: fs.URI(),
// TODO: add properties here...