feat: implement posh changs

This commit is contained in:
franklin 2023-03-20 11:44:56 +01:00
parent 9ed9d23049
commit f33d4c6291
21 changed files with 545 additions and 724 deletions

View File

@ -23,7 +23,7 @@ type (
l log.Logger l log.Logger
name string name string
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(command *Command) CommandOption func(command *Command)
) )
@ -40,15 +40,15 @@ func CommandWithName(v string) CommandOption {
func CommandWithGo() CommandOption { func CommandWithGo() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "go", Name: "go",
Description: "run golangci-lint", Description: "Run golangci-lint",
Args: tree.Args{o.pathArg("go.mod")}, Args: tree.Args{o.pathArg("go.mod")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
fs.String("timeout", "1m", "max excution timeout") fs.Default().String("timeout", "1m", "max excution timeout")
fs.String("out-format", "github-actions", "output format") fs.Default().String("out-format", "github-actions", "output format")
fs.Int("concurrency", 1, "num of concurrent processes") fs.Default().Int("concurrency", 1, "num of concurrent processes")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -58,7 +58,6 @@ func CommandWithGo() CommandOption {
if out, err := shell.New(ctx, o.l, "golangci-lint", "run"). if out, err := shell.New(ctx, o.l, "golangci-lint", "run").
Args("--path-prefix", dir). Args("--path-prefix", dir).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Output(); err != nil { Output(); err != nil {
@ -73,12 +72,12 @@ func CommandWithGo() CommandOption {
func CommandWithTSC() CommandOption { func CommandWithTSC() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "tsc", Name: "tsc",
Description: "run tsc", Description: "Run tsc",
Args: tree.Args{o.pathArg("tsconfig.json")}, Args: tree.Args{o.pathArg("tsconfig.json")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -88,7 +87,6 @@ func CommandWithTSC() CommandOption {
if out, err := shell.New(ctx, o.l, "tsc", "--noEmit"). if out, err := shell.New(ctx, o.l, "tsc", "--noEmit").
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Output(); err != nil { Output(); err != nil {
@ -103,12 +101,12 @@ func CommandWithTSC() CommandOption {
func CommandWithHelm() CommandOption { func CommandWithHelm() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "helm", Name: "helm",
Description: "run helm lint", Description: "Run helm lint",
Args: tree.Args{o.pathArg("Chart.yaml")}, Args: tree.Args{o.pathArg("Chart.yaml")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -117,7 +115,6 @@ func CommandWithHelm() CommandOption {
o.l.Info("└ " + dir) o.l.Info("└ " + dir)
if out, err := shell.New(ctx, o.l, "helm", "lint", dir). if out, err := shell.New(ctx, o.l, "helm", "lint", dir).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -131,13 +128,13 @@ func CommandWithHelm() CommandOption {
func CommandWithESLint() CommandOption { func CommandWithESLint() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "eslint", Name: "eslint",
Description: "run eslint", Description: "Run eslint",
Args: tree.Args{o.pathArg("package.json")}, Args: tree.Args{o.pathArg("package.json")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
fs.Bool("cache", false, "use cache") fs.Default().Bool("cache", false, "use cache")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -146,7 +143,6 @@ func CommandWithESLint() CommandOption {
o.l.Info("└ " + dir) o.l.Info("└ " + dir)
if out, err := shell.New(ctx, o.l, "eslint", "--quiet", "."). if out, err := shell.New(ctx, o.l, "eslint", "--quiet", ".").
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Output(); err != nil { Output(); err != nil {
@ -161,13 +157,12 @@ func CommandWithESLint() CommandOption {
func CommandWithGherkin() CommandOption { func CommandWithGherkin() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "gherkin", Name: "gherkin",
Description: "run gherkin lint", Description: "Run gherkin lint",
Args: tree.Args{o.pathArg("wdio.conf.ts")}, Args: tree.Args{o.pathArg("wdio.conf.ts")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { fs.Default().Bool("fix", false, "run quick fix")
fs.Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -177,7 +172,6 @@ func CommandWithGherkin() CommandOption {
if out, err := shell.New(ctx, o.l, "gherkin-lint", dir). if out, err := shell.New(ctx, o.l, "gherkin-lint", dir).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -191,12 +185,12 @@ func CommandWithGherkin() CommandOption {
func CommandWithTerraform() CommandOption { func CommandWithTerraform() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "terraform", Name: "terraform",
Description: "run tflint lint", Description: "Run tflint lint",
Args: tree.Args{o.pathArg("main.tf")}, Args: tree.Args{o.pathArg("main.tf")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -207,7 +201,6 @@ func CommandWithTerraform() CommandOption {
if out, err := shell.New(ctx, o.l, "tflint"). if out, err := shell.New(ctx, o.l, "tflint").
Dir(dir). Dir(dir).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -221,16 +214,16 @@ func CommandWithTerraform() CommandOption {
func CommandWithTerrascan() CommandOption { func CommandWithTerrascan() CommandOption {
return func(o *Command) { return func(o *Command) {
o.commandTree.Nodes = append(o.commandTree.Nodes, &tree.Node{ o.commandTree.Node().Nodes = append(o.commandTree.Node().Nodes, &tree.Node{
Name: "terrascan", Name: "terrascan",
Description: "run terrascan", Description: "Run terrascan",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "helm", Name: "helm",
Description: "run terrascan helm", Description: "Run terrascan helm",
Args: tree.Args{o.pathArg("Chart.yaml")}, Args: tree.Args{o.pathArg("Chart.yaml")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -241,7 +234,6 @@ func CommandWithTerrascan() CommandOption {
Args("--iac-dir", dir). Args("--iac-dir", dir).
Args("--iac-type", "docker"). Args("--iac-type", "docker").
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -252,10 +244,10 @@ func CommandWithTerrascan() CommandOption {
}, },
{ {
Name: "terraform", Name: "terraform",
Description: "run terrascan terraform", Description: "Run terrascan terraform",
Args: tree.Args{o.pathArg("main.tf")}, Args: tree.Args{o.pathArg("main.tf")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -266,7 +258,6 @@ func CommandWithTerrascan() CommandOption {
Args("--iac-dir", dir). Args("--iac-dir", dir).
Args("--iac-type", "docker"). Args("--iac-type", "docker").
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -277,10 +268,10 @@ func CommandWithTerrascan() CommandOption {
}, },
{ {
Name: "docker", Name: "docker",
Description: "run terrascan docker", Description: "Run terrascan docker",
Args: tree.Args{o.pathArg("Dockerfile")}, Args: tree.Args{o.pathArg("Dockerfile")},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("fix", false, "run quick fix") fs.Default().Bool("fix", false, "run quick fix")
return nil return nil
}, },
Execute: func(ctx context.Context, r *readline.Readline) error { Execute: func(ctx context.Context, r *readline.Readline) error {
@ -291,7 +282,6 @@ func CommandWithTerrascan() CommandOption {
Args("--iac-dir", dir). Args("--iac-dir", dir).
Args("--iac-type", "docker"). Args("--iac-type", "docker").
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Output(); err != nil { Output(); err != nil {
return errors.Wrap(err, string(out)) return errors.Wrap(err, string(out))
@ -314,16 +304,16 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
l: l.Named("lint"), l: l.Named("lint"),
name: "lint", name: "lint",
cache: c.Get("lint"), cache: c.Get("lint"),
commandTree: &tree.Root{ commandTree: tree.New(&tree.Node{
Description: "lint your code", Description: "Lint your code",
}, }),
} }
for _, opt := range opts { for _, opt := range opts {
if opt != nil { if opt != nil {
opt(inst) opt(inst)
} }
} }
inst.commandTree.Name = inst.name inst.commandTree.Node().Name = inst.name
return inst return inst
} }
@ -333,11 +323,11 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -349,14 +339,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Lint your code. return c.commandTree.Help(ctx, r)
Usage:
lint [linter] <path>
Examples:
lint go
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -382,7 +365,7 @@ func (c *Command) pathArg(filename string) *tree.Arg {
return &tree.Arg{ return &tree.Arg{
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.paths(ctx, filename)) return suggests.List(c.paths(ctx, filename))
}, },
} }

View File

@ -21,7 +21,7 @@ type (
cfg Config cfg Config
name string name string
configKey string configKey string
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -62,14 +62,13 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
return nil, err return nil, err
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "Open an external url", Description: "Open an external url",
Node: &tree.Node{
Args: tree.Args{ Args: tree.Args{
{ {
Name: "router", Name: "router",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
var ret []goprompt.Suggest var ret []goprompt.Suggest
for s, router := range inst.cfg { for s, router := range inst.cfg {
ret = append(ret, goprompt.Suggest{Text: s, Description: router.Description}) ret = append(ret, goprompt.Suggest{Text: s, Description: router.Description})
@ -79,7 +78,7 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
}, },
{ {
Name: "route", Name: "route",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
var ret []goprompt.Suggest var ret []goprompt.Suggest
if value, ok := inst.cfg[r.Args().At(0)]; ok { if value, ok := inst.cfg[r.Args().At(0)]; ok {
for s, route := range value.Routes { for s, route := range value.Routes {
@ -91,8 +90,7 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst, nil return inst, nil
} }
@ -102,11 +100,11 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -135,14 +133,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Connect to a open. return c.commandTree.Help(ctx, r)
Usage:
open [router] [route]
Examples:
open grafana home
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -19,7 +19,7 @@ type (
l log.Logger l log.Logger
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
squadron *squadron.Squadron squadron *squadron.Squadron
commandTree *tree.Root commandTree tree.Root
namespaceFn NamespaceFn namespaceFn NamespaceFn
} }
NamespaceFn func(cluster, fleet, squadron string) string NamespaceFn func(cluster, fleet, squadron string) string
@ -58,10 +58,9 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "k9s", Name: "k9s",
Description: "open the k9s dashboard", Description: "Open the k9s dashboard",
Node: &tree.Node{
Args: tree.Args{ Args: tree.Args{
{ {
Name: "cluster", Name: "cluster",
@ -77,9 +76,7 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -88,11 +85,11 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -104,14 +101,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Open the k9s dashboard. return c.commandTree.Help(ctx, r)
Usage:
k9s [cluster] [namespace]
Examples:
k9s example-cluster my-namespace
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -126,18 +116,18 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
Run() Run()
} }
func (c *Command) completeClusters(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeClusters(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.kubectl.Clusters()) return suggests.List(c.kubectl.Clusters())
} }
func (c *Command) completeFleets(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeFleets(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
if cluster, ok := c.squadron.Cluster(r.Args().At(0)); ok { if cluster, ok := c.squadron.Cluster(r.Args().At(0)); ok {
return suggests.List(cluster.Fleets) return suggests.List(cluster.Fleets)
} }
return nil return nil
} }
func (c *Command) completeSquadrons(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeSquadrons(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
if value, err := c.squadron.List(); err != nil { if value, err := c.squadron.List(); err != nil {
c.l.Debug(err.Error()) c.l.Debug(err.Error())
return nil return nil

View File

@ -77,14 +77,12 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
c.l.Info("bootstrapping a new zeus:", dir) c.l.Info("bootstrapping a new zeus:", dir)
return shell.New(ctx, c.l, "zeus", "bootstrap"). return shell.New(ctx, c.l, "zeus", "bootstrap").
Args(args...). Args(args...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(path.Join(dir, "..")). Dir(path.Join(dir, "..")).
Run() Run()
} else { } else {
return shell.New(ctx, c.l, "zeus", "-C", path.Dir(dir)). return shell.New(ctx, c.l, "zeus", "-C", path.Dir(dir)).
Args(args...). Args(args...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
} }

View File

@ -21,7 +21,7 @@ import (
type Command struct { type Command struct {
l log.Logger l log.Logger
etcd *ETCD etcd *ETCD
commandTree *tree.Root commandTree tree.Root
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -36,7 +36,7 @@ func NewCommand(l log.Logger, etcd *ETCD, opts ...Option) *Command {
pathArg := &tree.Arg{ pathArg := &tree.Arg{
Name: "path", Name: "path",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []prompt2.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []prompt2.Suggest {
if value, ok := inst.etcd.cfg.Cluster(r.Args().At(0)); ok { if value, ok := inst.etcd.cfg.Cluster(r.Args().At(0)); ok {
return suggests.List(value.Paths) return suggests.List(value.Paths)
} }
@ -44,9 +44,9 @@ func NewCommand(l log.Logger, etcd *ETCD, opts ...Option) *Command {
}, },
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "etcd", Name: "etcd",
Description: "read and write to etcd", Description: "Read and write to etcd",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "cluster", Name: "cluster",
@ -73,7 +73,7 @@ func NewCommand(l log.Logger, etcd *ETCD, opts ...Option) *Command {
}, },
}, },
}, },
} })
return inst return inst
} }
@ -83,11 +83,11 @@ func NewCommand(l log.Logger, etcd *ETCD, opts ...Option) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -99,19 +99,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Read and write to etcd. return c.commandTree.Help(ctx, r)
Usage:
etcd [cluster] [cmd]
Available commands:
get [path] Prints the value
edit [path] Edit the given value
Examples:
etcd example-cluster get config.yaml
etcd example-cluster edit config.yaml
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@ type (
op *onepassword.OnePassword op *onepassword.OnePassword
name string name string
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -56,26 +56,24 @@ func NewCommand(l log.Logger, cache cache.Cache, op *onepassword.OnePassword, op
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run gocontentful", Description: "Run gocontentful",
Node: &tree.Node{ Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { fs.Default().Bool("debug", false, "show debug output")
fs.Bool("debug", false, "show debug output")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
{ {
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.paths(ctx)) return suggests.List(inst.paths(ctx))
}, },
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -85,11 +83,11 @@ func NewCommand(l log.Logger, cache cache.Cache, op *onepassword.OnePassword, op
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -116,14 +114,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Generate gocontentful files. return c.commandTree.Help(ctx, r)
Usage:
gocontentful <path>
Examples:
gocontentful ./path/gocontentful.yml
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -157,7 +148,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
if err := shell.New(ctx, c.l, "gocontentful", if err := shell.New(ctx, c.l, "gocontentful",
"-spaceid", cfg.SpaceID, "-cmakey", cfg.CMAKey, "-spaceid", cfg.SpaceID, "-cmakey", cfg.CMAKey,
"-contenttypes", strings.Join(cfg.ContentTypes, ","), dir). "-contenttypes", strings.Join(cfg.ContentTypes, ","), dir).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run(); err != nil { Run(); err != nil {
return err return err

View File

@ -19,7 +19,7 @@ import (
type Command struct { type Command struct {
l log.Logger l log.Logger
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -31,12 +31,11 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
l: l.Named("gotsrpc"), l: l.Named("gotsrpc"),
cache: cache.Get("gotsrpc"), cache: cache.Get("gotsrpc"),
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "gotsrpc", Name: "gotsrpc",
Description: "run gotsrpc", Description: "Run gotsrpc",
Node: &tree.Node{ Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { fs.Default().Bool("debug", false, "show debug output")
fs.Bool("debug", false, "show debug output")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
@ -46,8 +45,7 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -57,11 +55,11 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -88,18 +86,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Generate gotsrpc files. return c.commandTree.Help(ctx, r)
Usage:
gotsrpc <path> <options>
Available options:
debug
skipgotsrpc
Examples:
gotsrpc ./path/gotsrpc.yml
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -131,7 +118,7 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
return nil return nil
} }
func (c *Command) completePaths(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completePaths(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.paths(ctx)) return suggests.List(c.paths(ctx))
} }

View File

@ -30,7 +30,7 @@ type (
slackChannelID string slackChannelID string
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
squadron *Squadron squadron *Squadron
commandTree *tree.Root commandTree tree.Root
namespaceFn NamespaceFn namespaceFn NamespaceFn
} }
NamespaceFn func(cluster, fleet, squadron string) string NamespaceFn func(cluster, fleet, squadron string) string
@ -88,7 +88,7 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
Name: "unit", Name: "unit",
Repeat: true, Repeat: true,
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
if value, err := inst.squadron.ListUnits(ctx, r.Args().At(2), r.Args().At(0), r.Args().At(1), true); err != nil { if value, err := inst.squadron.ListUnits(ctx, r.Args().At(2), r.Args().At(0), r.Args().At(1), true); err != nil {
return nil return nil
} else { } else {
@ -96,10 +96,15 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
} }
}, },
} }
commonFlags := func(fs *readline.FlagSet) { slackFlag := func(fs *readline.FlagSets) {
fs.Bool("no-override", false, "ignore override files") if inst.slack != nil {
fs.Bool("verbose", inst.l.IsLevel(log.LevelDebug), "set verbose level") fs.Internal().Bool("slack", false, "send slack notification")
fs.Bool("debug", inst.l.IsLevel(log.LevelTrace), "set debug level") }
}
commonFlags := func(fs *readline.FlagSets) {
fs.Internal().Bool("no-override", false, "ignore override files")
fs.Default().Bool("verbose", inst.l.IsLevel(log.LevelDebug), "set verbose level")
fs.Default().Bool("debug", inst.l.IsLevel(log.LevelTrace), "set debug level")
} }
clusterValues := func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { clusterValues := func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -112,9 +117,9 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
return suggests.List(ret) return suggests.List(ret)
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "squadron", Name: "squadron",
Description: "manage your squadron", Description: "Manage your squadron",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "cluster", Name: "cluster",
@ -143,78 +148,73 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "up", Name: "up",
Description: "installs a squadron chart", Description: "Installs a squadron chart",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
slackFlag(fs)
commonFlags(fs) commonFlags(fs)
fs.Bool("diff", false, "show diff") fs.Default().Bool("diff", false, "show diff")
fs.Bool("push", false, "push image") fs.Default().Bool("push", false, "push image")
fs.Bool("build", false, "build image") fs.Default().Bool("build", false, "build image")
fs.String("tag", "", "image tag") fs.Internal().Int64("parallel", 0, "number of parallel processes")
fs.Int64("parallel", 0, "number of parallel processes") fs.Internal().String("tag", "", "image tag")
if inst.slack != nil { fs.Internal().Bool("create-namespace", false, "create namespace if not exist")
fs.Bool("slack", false, "send slack notification")
}
return nil
},
PassThroughFlags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error {
fs.Bool("create-namespace", false, "create namespace if not exist")
return nil return nil
}, },
Execute: inst.up, Execute: inst.up,
}, },
{ {
Name: "list", Name: "list",
Description: "list squadron units", Description: "List squadron units",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.Bool("prefix-squadron", false, "prefix unit names with squadron") fs.Default().Bool("prefix-squadron", false, "prefix unit names with squadron")
return nil return nil
}, },
Execute: inst.list, Execute: inst.list,
}, },
{ {
Name: "down", Name: "down",
Description: "uninstalls the squadron chart", Description: "Uninstalls the squadron chart",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
if inst.slack != nil { slackFlag(fs)
fs.Bool("slack", false, "send slack notification")
}
return nil return nil
}, },
Execute: inst.down, Execute: inst.down,
}, },
{ {
Name: "push", Name: "push",
Description: "push squadron units", Description: "Push squadron units",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.Bool("build", false, "build image") fs.Default().Bool("build", false, "build image")
fs.Internal().String("tag", "", "image tag")
fs.Internal().Int64("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Execute: inst.push, Execute: inst.push,
}, },
{ {
Name: "build", Name: "build",
Description: "build or rebuild squadron units", Description: "Build or rebuild squadron units",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.Bool("push", false, "push image") fs.Default().Bool("push", false, "push image")
fs.String("tag", "", "image tag") fs.Internal().String("tag", "", "image tag")
fs.Int64("parallel", 0, "number of parallel processes") fs.Internal().Int64("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Execute: inst.build, Execute: inst.build,
}, },
{ {
Name: "status", Name: "status",
Description: "display the status of the units", Description: "Display the status of the units",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
return nil return nil
}, },
@ -222,34 +222,32 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
}, },
{ {
Name: "config", Name: "config",
Description: "view generated squadron config", Description: "View generated squadron config",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.Bool("no-render", false, "push image") fs.Default().Bool("no-render", false, "push image")
return nil return nil
}, },
Execute: inst.config, Execute: inst.config,
}, },
{ {
Name: "rollback", Name: "rollback",
Description: "roll back the squadron chart", Description: "Roll back the squadron chart",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.String("revision", "", "revision number to rollback to") fs.Default().String("revision", "", "revision number to rollback to")
if inst.slack != nil { slackFlag(fs)
fs.Bool("slack", false, "send slack notification")
}
return nil return nil
}, },
Execute: inst.rollback, Execute: inst.rollback,
}, },
{ {
Name: "generate", Name: "generate",
Description: "generate and view the squadron chart", Description: "Generate and view the squadron chart",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
return nil return nil
}, },
@ -257,10 +255,11 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
}, },
{ {
Name: "template", Name: "template",
Description: "render chart templates locally and display the output", Description: "Render chart templates locally and display the output",
Args: tree.Args{unitsArg}, Args: tree.Args{unitsArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
commonFlags(fs) commonFlags(fs)
fs.Internal().String("tag", "", "image tag")
return nil return nil
}, },
Execute: inst.template, Execute: inst.template,
@ -272,7 +271,7 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
}, },
}, },
}, },
} })
return inst return inst
} }
@ -282,11 +281,11 @@ func NewCommand(l log.Logger, squadron *Squadron, kubectl *kubectl.Kubectl, op *
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -298,18 +297,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Manage your squadron. return c.commandTree.Help(ctx, r)
Usage:
squadron [cluster] [fleet] [squadron] [cmd]
Available Commands:
up <fleet...>
down <fleet...>
Examples:
k9s example-cluster my-namespace
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -357,9 +345,17 @@ func (c *Command) template(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) execute(ctx context.Context, r *readline.Readline) error { func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
flags := r.Flags() var env []string
var squadrons []string
ifs := r.FlagSets().Internal()
passFlags := []string{"--"}
cluster, fleet, squadron, cmd, units := r.Args()[0], r.Args()[1], r.Args()[2], r.Args()[3], r.Args()[4:] cluster, fleet, squadron, cmd, units := r.Args()[0], r.Args()[1], r.Args()[2], r.Args()[3], r.Args()[4:]
// retrieve flags
tag, _ := ifs.GetString("tag")
noOverride := log.MustGet(ifs.GetBool("no-override"))(c.l)
{ // handle 1password
if c.op != nil { if c.op != nil {
if ok, _ := c.op.Session(); !ok { if ok, _ := c.op.Session(); !ok {
c.l.Info("missing 1password session, please login") c.l.Info("missing 1password session, please login")
@ -368,24 +364,28 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
} }
} }
} }
passFlags := r.PassThroughFlags()
if slices.Contains([]string{"up", "template"}, cmd) {
if len(passFlags) == 0 {
passFlags = append(passFlags, "--")
} }
{ // handle pass through flags
if slices.Contains([]string{"up", "template"}, cmd) {
passFlags = append(passFlags, "--set", fmt.Sprintf("fleet=%v", fleet)) passFlags = append(passFlags, "--set", fmt.Sprintf("fleet=%v", fleet))
} }
if slices.Contains([]string{"up"}, cmd) {
if log.MustGet(ifs.GetBool("create-namespace"))(c.l) {
passFlags = append(passFlags, "--create-namespace")
}
}
}
var env []string { // handle env
env = append(env, fmt.Sprintf("FLEET=%s", fleet)) env = append(env, fmt.Sprintf("FLEET=%s", fleet))
if value := r.FlagSet().GetString("tag"); value != "" { if tag != "" {
env = append(env, fmt.Sprintf("TAG=%q", value)) env = append(env, fmt.Sprintf("TAG=%q", tag))
flags = flags.Splice(flags.IndexOf("--tag"), 2)
} }
env = append(env, c.kubectl.Cluster(cluster).Env()) env = append(env, c.kubectl.Cluster(cluster).Env())
}
var squadrons []string { // handle squadrons
if squadron == All { if squadron == All {
if value, err := c.squadron.List(); err == nil { if value, err := c.squadron.List(); err == nil {
squadrons = value squadrons = value
@ -393,18 +393,20 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
} else { } else {
squadrons = []string{squadron} squadrons = []string{squadron}
} }
}
if c.slack != nil && r.FlagSet().GetBool("slack") { { // handle slack
flags = flags.Splice(flags.IndexOf("--slack"), 1) if ok, _ := ifs.GetBool("slack"); ok {
if err := c.notify(ctx, cmd, cluster, fleet, squadron, r.FlagSet().GetString("tag"), units); err != nil { if err := c.notify(ctx, cmd, cluster, fleet, squadron, tag, units); err != nil {
return err return err
} }
} }
}
for _, s := range squadrons { for _, s := range squadrons {
env := append(env, fmt.Sprintf("SQUADRON=%s", s)) env := append(env, fmt.Sprintf("SQUADRON=%s", s))
flags := flags flags := r.FlagSets().Default().Args()
files := strings.Join(c.squadron.GetFiles(s, cluster, fleet, !r.FlagSet().GetBool("no-override")), ",") files := strings.Join(c.squadron.GetFiles(s, cluster, fleet, !noOverride), ",")
if slices.Contains([]string{"up", "down", "rollback", "status", "template"}, cmd) { if slices.Contains([]string{"up", "down", "rollback", "status", "template"}, cmd) {
flags = append(flags, "--namespace", c.namespaceFn(cluster, fleet, s)) flags = append(flags, "--namespace", c.namespaceFn(cluster, fleet, s))
} }

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/1Password/connect-sdk-go v1.5.0 github.com/1Password/connect-sdk-go v1.5.0
github.com/c-bata/go-prompt v0.2.6 github.com/c-bata/go-prompt v0.2.6
github.com/cloudrecipes/packagejson v1.0.0 github.com/cloudrecipes/packagejson v1.0.0
github.com/foomo/posh v0.3.1-0.20230220152511-db05bf278428 github.com/foomo/posh v0.3.1-0.20230320104124-535c54a232e7
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.54 github.com/pterm/pterm v0.12.54

4
go.sum
View File

@ -86,8 +86,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/foomo/posh v0.3.1-0.20230220152511-db05bf278428 h1:uIpD2sUh6FDnmuo1CI+737irVZiCKK80wNNb5AItEac= github.com/foomo/posh v0.3.1-0.20230320104124-535c54a232e7 h1:CE0FLumvmm5EzGLIbA7x15vklA5RmYYIfEN7bieRQBM=
github.com/foomo/posh v0.3.1-0.20230220152511-db05bf278428/go.mod h1:/vQBAKq672FEktZN3KbWc7Ofnhxz4r+I9oU+9/t14pI= github.com/foomo/posh v0.3.1-0.20230320104124-535c54a232e7/go.mod h1:/vQBAKq672FEktZN3KbWc7Ofnhxz4r+I9oU+9/t14pI=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/franklinkim/go-prompt v0.2.7-0.20210427061716-a8f4995d7aa5 h1:kXNtle4AoQnngdm+gwt4ku6Llbzw3EFHgZYpL618JaI= github.com/franklinkim/go-prompt v0.2.7-0.20210427061716-a8f4995d7aa5 h1:kXNtle4AoQnngdm+gwt4ku6Llbzw3EFHgZYpL618JaI=
github.com/franklinkim/go-prompt v0.2.7-0.20210427061716-a8f4995d7aa5/go.mod h1:+syUfnvYJUO5A+6QMQYXAyzkxHMNlj9dH2LIeQfBSjc= github.com/franklinkim/go-prompt v0.2.7-0.20210427061716-a8f4995d7aa5/go.mod h1:+syUfnvYJUO5A+6QMQYXAyzkxHMNlj9dH2LIeQfBSjc=

View File

@ -21,7 +21,7 @@ import (
type Command struct { type Command struct {
l log.Logger l log.Logger
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -37,7 +37,7 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
pathModArg := &tree.Arg{ pathModArg := &tree.Arg{
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, p *tree.Root, r *readline.Readline) []prompt2.Suggest { Suggest: func(ctx context.Context, p tree.Root, r *readline.Readline) []prompt2.Suggest {
return inst.completePaths(ctx, "go.mod", true) return inst.completePaths(ctx, "go.mod", true)
}, },
} }
@ -45,24 +45,24 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
pathGenerateArg := &tree.Arg{ pathGenerateArg := &tree.Arg{
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, p *tree.Root, r *readline.Readline) []prompt2.Suggest { Suggest: func(ctx context.Context, p tree.Root, r *readline.Readline) []prompt2.Suggest {
return inst.completePaths(ctx, "generate.go", false) return inst.completePaths(ctx, "generate.go", false)
}, },
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "go", Name: "go",
Description: "go related tasks", Description: "Go related tasks",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "mod", Name: "mod",
Description: "run go mod commands", Description: "Run go mod commands",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "tidy", Name: "tidy",
Description: "run go mod tidy", Description: "Run go mod tidy",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathModArg}, Args: []*tree.Arg{pathModArg},
@ -70,9 +70,9 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "download", Name: "download",
Description: "run go mod download", Description: "Run go mod download",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathModArg}, Args: []*tree.Arg{pathModArg},
@ -80,9 +80,9 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "outdated", Name: "outdated",
Description: "show go mod outdated", Description: "Show go mod outdated",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathModArg}, Args: []*tree.Arg{pathModArg},
@ -92,16 +92,16 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "work", Name: "work",
Description: "manage go.work file", Description: "Manage go.work file",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "init", Name: "init",
Description: "generate go.work file", Description: "Generate go.work file",
Execute: inst.workInit, Execute: inst.workInit,
}, },
{ {
Name: "use", Name: "use",
Description: "add go.work entry", Description: "Add go.work entry",
Args: []*tree.Arg{ Args: []*tree.Arg{
{ {
Name: "path", Name: "path",
@ -114,9 +114,9 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "generate", Name: "generate",
Description: "run go mod commands", Description: "Run go mod commands",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathGenerateArg}, Args: []*tree.Arg{pathGenerateArg},
@ -124,9 +124,9 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "test", Name: "test",
Description: "run go test", Description: "Run go test",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathModArg}, Args: []*tree.Arg{pathModArg},
@ -134,16 +134,16 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
}, },
{ {
Name: "build", Name: "build",
Description: "run go build", Description: "Run go build",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Internal().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: []*tree.Arg{pathModArg}, Args: []*tree.Arg{pathModArg},
Execute: inst.build, Execute: inst.build,
}, },
}, },
} })
return inst return inst
} }
@ -152,11 +152,11 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -168,22 +168,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Looks for go.mod files and runs the given command. return c.commandTree.Help(ctx, r)
Usage:
go [command]
Available commands:
mod [command] run go mod
generate <path> run go generate
test <path> run go test
build <path> run go build
SubCommands mod:
tidy <path>
download <path>
outdated <path>
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -207,7 +192,6 @@ func (c *Command) build(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, return shell.New(ctx, c.l,
"go", "build", "-v", "./...", // TODO select test "go", "build", "-v", "./...", // TODO select test
). ).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(value). Dir(value).
Run() Run()
@ -233,7 +217,6 @@ func (c *Command) test(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, return shell.New(ctx, c.l,
"go", "test", "-v", "./...", // TODO select test "go", "test", "-v", "./...", // TODO select test
). ).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(value). Dir(value).
Run() Run()
@ -380,7 +363,7 @@ func (c *Command) paths(ctx context.Context, filename string, dir bool) []string
func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) { func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) {
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
if value, err := r.FlagSet().GetInt("parallel"); err == nil && value != 0 { if value, _ := r.FlagSets().Internal().GetInt("parallel"); value != 0 {
wg.SetLimit(value) wg.SetLimit(value)
} else { } else {
wg.SetLimit(1) wg.SetLimit(1)

View File

@ -26,7 +26,7 @@ type (
op *onepassword.OnePassword op *onepassword.OnePassword
gcloud *GCloud gcloud *GCloud
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
commandTree *tree.Root commandTree tree.Root
clusterNameFn ClusterNameFn clusterNameFn ClusterNameFn
} }
ClusterNameFn func(name string, cluster Cluster) string ClusterNameFn func(name string, cluster Cluster) string
@ -74,12 +74,10 @@ func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "Run google cloud sdk commands", Description: "Run google cloud sdk commands",
Node: &tree.Node{
Execute: inst.execute, Execute: inst.execute,
},
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "login", Name: "login",
@ -88,7 +86,7 @@ func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...
{ {
Name: "account", Name: "account",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.gcloud.cfg.AccountNames()) return suggests.List(inst.gcloud.cfg.AccountNames())
}, },
}, },
@ -106,7 +104,7 @@ func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...
Args: tree.Args{ Args: tree.Args{
{ {
Name: "cluster", Name: "cluster",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.gcloud.cfg.ClusterNames()) return suggests.List(inst.gcloud.cfg.ClusterNames())
}, },
}, },
@ -114,7 +112,7 @@ func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...
Execute: inst.containerClustersGetCredentials, Execute: inst.containerClustersGetCredentials,
}, },
}, },
} })
return inst return inst
} }
@ -124,11 +122,11 @@ func NewCommand(l log.Logger, gcloud *GCloud, kubectl *kubectl.Kubectl, opts ...
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -140,16 +138,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Execute google-cloud-sdk commands. return c.commandTree.Help(ctx, r)
Usage:
gcloud [cmd]
Available commands:
login <account> Login into your google cloud account (optional service account)
docker Configure docker access
kubeconfig [cluster] Retrieve kube config for the given cluster
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -160,7 +149,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, "gcloud"). return shell.New(ctx, c.l, "gcloud").
Args(r.Args()...). Args(r.Args()...).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
} }

View File

@ -18,7 +18,7 @@ type (
l log.Logger l log.Logger
name string name string
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -43,33 +43,33 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
name: "helm", name: "helm",
kubectl: kubectl, kubectl: kubectl,
} }
allFlags := func(fs *readline.FlagSet) { allFlags := func(fs *readline.FlagSets) {
fs.Bool("help", false, "help for helm") fs.Default().Bool("help", false, "help for helm")
fs.Bool("debug", false, "enable verbose output") fs.Default().Bool("debug", false, "enable verbose output")
fs.String("namespace", "", "namespace scope for this request") fs.Default().String("namespace", "", "namespace scope for this request")
fs.Bool("all-namespaces", false, "all namespace scope for this request") fs.Default().Bool("all-namespaces", false, "all namespace scope for this request")
fs.Bool("create-namespace", false, "create the release namespace if not present") fs.Default().Bool("create-namespace", false, "create the release namespace if not present")
fs.Bool("dependency-update", false, "update dependencies") fs.Default().Bool("dependency-update", false, "update dependencies")
fs.Bool("dry-run", false, "assume aws profile") fs.Default().Bool("dry-run", false, "assume aws profile")
fs.Bool("atomic", false, "delete installation on failure") fs.Default().Bool("atomic", false, "delete installation on failure")
fs.Bool("wait", false, "wait until all resources a ready") fs.Default().Bool("wait", false, "wait until all resources a ready")
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run helm commands", Description: "Run helm commands",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "cluster", Name: "cluster",
Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.kubectl.Clusters()) return suggests.List(inst.kubectl.Clusters())
}, },
Description: "cluster to run against", Description: "Cluster to run against",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "create", Name: "create",
Description: "create a new chart with the given name", Description: "Create a new chart with the given name",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -77,8 +77,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "dependency", Name: "dependency",
Description: "manage a chart's dependencies", Description: "Manage a chart's dependencies",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -86,8 +86,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "diff", Name: "diff",
Description: "preview helm upgrade changes as a diff", Description: "Preview helm upgrade changes as a diff",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -95,8 +95,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "env", Name: "env",
Description: "helm client environment information", Description: "Helm client environment information",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -104,10 +104,10 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "get", Name: "get",
Description: "download extended information of a named release", Description: "Download extended information of a named release",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
fs.String("revision", "", "get the named release with revision") fs.Default().String("revision", "", "get the named release with revision")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
@ -115,13 +115,13 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
Name: "value", Name: "value",
Repeat: false, Repeat: false,
Optional: false, Optional: false,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return []goprompt.Suggest{ return []goprompt.Suggest{
{Text: "all", Description: "download all information for a named release"}, {Text: "all", Description: "Download all information for a named release"},
{Text: "hooks", Description: "download all hooks for a named release"}, {Text: "hooks", Description: "Download all hooks for a named release"},
{Text: "manifest", Description: "download the manifest for a named release"}, {Text: "manifest", Description: "Download the manifest for a named release"},
{Text: "notes", Description: "download the notes for a named release"}, {Text: "notes", Description: "Download the notes for a named release"},
{Text: "values", Description: "download the values file for a named release"}, {Text: "values", Description: "Download the values file for a named release"},
} }
}, },
}, },
@ -131,7 +131,7 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
{ {
Name: "help", Name: "help",
Description: "Help about any command", Description: "Help about any command",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -139,8 +139,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "history", Name: "history",
Description: "fetch release history", Description: "Fetch release history",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -148,8 +148,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "install", Name: "install",
Description: "install a chart", Description: "Install a chart",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -157,8 +157,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "lint", Name: "lint",
Description: "examine a chart for possible issues", Description: "Examine a chart for possible issues",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -166,8 +166,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "list", Name: "list",
Description: "list releases", Description: "List releases",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -175,8 +175,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "package", Name: "package",
Description: "package a chart directory into a chart archive", Description: "Package a chart directory into a chart archive",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -184,8 +184,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "plugin", Name: "plugin",
Description: "install, list, or uninstall Helm plugins", Description: "Install, list, or uninstall Helm plugins",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -193,8 +193,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "pull", Name: "pull",
Description: "download a chart from a repository and (optionally) unpack it in local directory", Description: "Download a chart from a repository and (optionally) unpack it in local directory",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -202,8 +202,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "repo", Name: "repo",
Description: "add, list, remove, update, and index chart repositories", Description: "Add, list, remove, update, and index chart repositories",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -211,8 +211,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "rollback", Name: "rollback",
Description: "roll back a release to a previous revision", Description: "Roll back a release to a previous revision",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -220,8 +220,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "search", Name: "search",
Description: "search for a keyword in charts", Description: "Search for a keyword in charts",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -229,8 +229,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "show", Name: "show",
Description: "show information of a chart", Description: "Show information of a chart",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -238,18 +238,18 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "status", Name: "status",
Description: "display the status of the named release", Description: "Display the status of the named release",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
fs.Bool("show-desc", false, "show description") fs.Default().Bool("show-desc", false, "show description")
return nil return nil
}, },
Execute: inst.execute, Execute: inst.execute,
}, },
{ {
Name: "template", Name: "template",
Description: "locally render templates", Description: "Locally render templates",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -257,8 +257,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "test", Name: "test",
Description: "run tests for a release", Description: "Run tests for a release",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -266,8 +266,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "uninstall", Name: "uninstall",
Description: "uninstall a release", Description: "Uninstall a release",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -275,8 +275,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "upgrade", Name: "upgrade",
Description: "upgrade a release", Description: "Upgrade a release",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -284,8 +284,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "verify", Name: "verify",
Description: "verify that a chart at the given path has been signed and is valid", Description: "Verify that a chart at the given path has been signed and is valid",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -293,8 +293,8 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
{ {
Name: "version", Name: "version",
Description: "print the client version information", Description: "Print the client version information",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
allFlags(fs) allFlags(fs)
return nil return nil
}, },
@ -303,7 +303,7 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
}, },
}, },
} })
return inst return inst
} }
@ -313,11 +313,11 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -342,18 +342,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Generate helm files. return c.commandTree.Help(ctx, r)
Usage:
helm <path> <options>
Available options:
debug
skiphelm
Examples:
helm ./path/helm.yml
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -366,7 +355,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, "helm"). return shell.New(ctx, c.l, "helm").
Args(args...). Args(args...).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Env(cluster.Env()). Env(cluster.Env()).
Run() Run()

View File

@ -15,7 +15,7 @@ import (
type Command struct { type Command struct {
l log.Logger l log.Logger
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
commandTree *tree.Root commandTree tree.Root
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -27,10 +27,9 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
l: l.Named("kubeprompt"), l: l.Named("kubeprompt"),
kubectl: kubectl, kubectl: kubectl,
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "kubeprompt", Name: "kubeprompt",
Description: "open the kubectl prompt", Description: "Open the kubectl prompt",
Node: &tree.Node{
Args: tree.Args{ Args: tree.Args{
{ {
Name: "cluster", Name: "cluster",
@ -38,8 +37,7 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -49,11 +47,11 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -65,14 +63,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Open interactive kubectl prompt. return c.commandTree.Help(ctx, r)
Usage:
kubeprompt [cluster]
Examples:
kubeprompt example-cluster
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -86,6 +77,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
Run() Run()
} }
func (c *Command) completeClusters(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeClusters(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.kubectl.Clusters()) return suggests.List(c.kubectl.Clusters())
} }

View File

@ -23,7 +23,7 @@ type (
name string name string
cache cache.Namespace cache cache.Namespace
templateDir string templateDir string
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -60,34 +60,32 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run hygen", Description: "Run hygen",
Node: &tree.Node{
Args: tree.Args{ Args: tree.Args{
{ {
Name: "path", Name: "path",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.paths(ctx)) return suggests.List(inst.paths(ctx))
}, },
}, },
}, },
},
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "template", Name: "template",
Description: "render template", Description: "Render template",
Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.paths(ctx)) return suggests.List(inst.paths(ctx))
}, },
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Bool("dry", false, "Perform a dry run. Files will be generated but not saved") fs.Default().Bool("dry", false, "Perform a dry run. Files will be generated but not saved")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
{ {
Name: "path", Name: "path",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return nil return nil
}, },
}, },
@ -95,7 +93,7 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
Execute: inst.execute, Execute: inst.execute,
}, },
}, },
} })
return inst return inst
} }
@ -105,11 +103,11 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -138,14 +136,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Generate hygen files. return c.commandTree.Help(ctx, r)
Usage:
hygen [template] [path]
Examples:
hygen example ./target/path
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -156,7 +147,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, "hygen", "scaffold"). return shell.New(ctx, c.l, "hygen", "scaffold").
Args(r.Args()...). Args(r.Args()...).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Env(fmt.Sprintf("HYGEN_TMPLS=%s", path.Dir(c.templateDir))). Env(fmt.Sprintf("HYGEN_TMPLS=%s", path.Dir(c.templateDir))).
Run() Run()

View File

@ -23,7 +23,7 @@ type (
l log.Logger l log.Logger
name string name string
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -53,26 +53,24 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run mjml", Description: "Run mjml",
Node: &tree.Node{ Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { fs.Internal().Int("parallel", 0, "number of parallel processes")
fs.Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
{ {
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.paths(ctx)) return suggests.List(inst.paths(ctx))
}, },
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -82,11 +80,11 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -113,14 +111,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Generate mjml files. return c.commandTree.Help(ctx, r)
Usage:
mjml <path>
Examples:
mjml ./path/mjml.yml
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -142,7 +133,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
out := strings.ReplaceAll(src, ".mjml", ".html") out := strings.ReplaceAll(src, ".mjml", ".html")
out = strings.ReplaceAll(out, "/src/", "/html/") out = strings.ReplaceAll(out, "/src/", "/html/")
return shell.New(ctx, c.l, "mjml", src, "-o", out). return shell.New(ctx, c.l, "mjml", src, "-o", out).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
}) })
@ -192,7 +182,7 @@ func (c *Command) files(ctx context.Context, root string) []string {
func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) { func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) {
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
if value, err := r.FlagSet().GetInt("parallel"); err == nil && value != 0 { if value, _ := r.FlagSets().Internal().GetInt("parallel"); value != 0 {
wg.SetLimit(value) wg.SetLimit(value)
} else { } else {
wg.SetLimit(1) wg.SetLimit(1)

View File

@ -14,7 +14,7 @@ type (
Command struct { Command struct {
l log.Logger l log.Logger
op *OnePassword op *OnePassword
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) error CommandOption func(*Command) error
) )
@ -39,37 +39,40 @@ func NewCommand(l log.Logger, op *OnePassword, opts ...CommandOption) (*Command,
} }
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "op", Name: "op",
Description: "execute 1Password commands", Description: "Execute 1Password commands",
Execute: inst.signin,
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{
Name: "signin",
Description: "Sign into your account",
Execute: inst.signin,
},
{ {
Name: "get", Name: "get",
Description: "retrieve item", Description: "Retrieve an item",
Args: tree.Args{ Args: tree.Args{
{ {
Name: "id", Name: "id",
Description: "Item name or uuid",
}, },
}, },
Execute: inst.get, Execute: inst.get,
}, },
{
Name: "signin",
Description: "sign into your account",
Execute: inst.signin,
},
{ {
Name: "register", Name: "register",
Description: "register an account", Description: "Register an account",
Args: tree.Args{ Args: tree.Args{
{ {
Name: "email", Name: "email",
Description: "User email address",
}, },
}, },
Execute: inst.register, Execute: inst.register,
}, },
}, },
} })
return inst, nil return inst, nil
} }
@ -78,11 +81,11 @@ func NewCommand(l log.Logger, op *OnePassword, opts ...CommandOption) (*Command,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -94,16 +97,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `1Password session helper. return c.commandTree.Help(ctx, r)
Usage:
op [command]
Available commands:
get [id] Retrieve an entry from your account
signin Sign into your 1Password account for the session
register [email] Add your 1Password account
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -24,7 +24,7 @@ type (
name string name string
cache cache.Namespace cache cache.Namespace
configKey string configKey string
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -80,16 +80,14 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
Execute: inst.execute, Execute: inst.execute,
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run license finder", Description: "Run license finder",
Node: &tree.Node{
Execute: inst.execute, Execute: inst.execute,
},
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "restricted_licenses", Name: "restricted_licenses",
Description: "manage restricted licenses", Description: "Manage restricted licenses",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
&addNode, &addNode,
&listNode, &listNode,
@ -98,7 +96,7 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
}, },
{ {
Name: "ignored_dependencies", Name: "ignored_dependencies",
Description: "manage ignored dependencies", Description: "Manage ignored dependencies",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
&addNode, &addNode,
&listNode, &listNode,
@ -107,7 +105,7 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
}, },
{ {
Name: "permitted_licenses", Name: "permitted_licenses",
Description: "manage permitted licenses", Description: "Manage permitted licenses",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
&addNode, &addNode,
&listNode, &listNode,
@ -116,7 +114,7 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
}, },
{ {
Name: "approvals", Name: "approvals",
Description: "manage approvals", Description: "Manage approvals",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
&addNode, &addNode,
&removeNode, &removeNode,
@ -124,14 +122,14 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
}, },
{ {
Name: "licenses", Name: "licenses",
Description: "manage licenses", Description: "Manage licenses",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
&addNode, &addNode,
&removeNode, &removeNode,
}, },
}, },
}, },
} })
return inst return inst
} }
@ -141,11 +139,11 @@ func NewCommand(l log.Logger, cache cache.Cache, opts ...CommandOption) *Command
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -183,11 +181,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Check project licenses. return c.commandTree.Help(ctx, r)
Usage:
licensefinder
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -209,7 +203,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
Args(args...). Args(args...).
Args(r.Args()...). Args(r.Args()...).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
} }

View File

@ -19,7 +19,7 @@ type (
l log.Logger l log.Logger
kubectl *kubectl.Kubectl kubectl *kubectl.Kubectl
squadron *squadron.Squadron squadron *squadron.Squadron
commandTree *tree.Root commandTree tree.Root
namespaceFn NamespaceFn namespaceFn NamespaceFn
} }
NamespaceFn func(cluster, fleet, squadron string) string NamespaceFn func(cluster, fleet, squadron string) string
@ -58,18 +58,17 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
opt(inst) opt(inst)
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: "stern", Name: "stern",
Description: "tail your logs with stern", Description: "Tail your logs with stern",
Node: &tree.Node{ Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { fs.Default().String("container", "", "Container name when multiple containers in pod (default \".*\")")
fs.String("container", "", "Container name when multiple containers in pod (default \".*\")") fs.Default().String("exclude", "", "Regex of log lines to exclude")
fs.String("exclude", "", "Regex of log lines to exclude") fs.Default().String("exclude-container", "", "Exclude a Container name")
fs.String("exclude-container", "", "Exclude a Container name") fs.Default().String("include", "", "Regex of log lines to include")
fs.String("include", "", "Regex of log lines to include") fs.Default().String("selector", "", "Selector (label query) to filter on. If present, default to \".*\" for the pod-query.")
fs.String("selector", "", "Selector (label query) to filter on. If present, default to \".*\" for the pod-query.") fs.Default().String("since", "", "Return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to 48h")
fs.String("since", "", "Return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to 48h") fs.Default().String("tail", "", "The number of lines from the end of the logs to show. Defaults to -1, showing all logs. (default -1)")
fs.String("tail", "", "The number of lines from the end of the logs to show. Defaults to -1, showing all logs. (default -1)")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
@ -91,8 +90,7 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
}, },
}, },
Execute: inst.execute, Execute: inst.execute,
}, })
}
return inst return inst
} }
@ -102,11 +100,11 @@ func NewCommand(l log.Logger, kubectl *kubectl.Kubectl, squadron *squadron.Squad
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -118,14 +116,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Tail your logs with stern. return c.commandTree.Help(ctx, r)
Usage:
stern [cluster] [fleet] [squadron] [unit]
Examples:
stern example-cluster my-namespace my-deployment
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -138,23 +129,22 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
Env(c.kubectl.Cluster(cluster).Env()). Env(c.kubectl.Cluster(cluster).Env()).
Args("--namespace", c.namespaceFn(cluster, fleet, squad)). Args("--namespace", c.namespaceFn(cluster, fleet, squad)).
Args("--selector", "\"app.kubernetes.io/name="+squad+"-"+unit+"\""). Args("--selector", "\"app.kubernetes.io/name="+squad+"-"+unit+"\"").
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
} }
func (c *Command) completeClusters(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeClusters(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.kubectl.Clusters()) return suggests.List(c.kubectl.Clusters())
} }
func (c *Command) completeFleets(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeFleets(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
if cluster, ok := c.squadron.Cluster(r.Args().At(0)); ok { if cluster, ok := c.squadron.Cluster(r.Args().At(0)); ok {
return suggests.List(cluster.Fleets) return suggests.List(cluster.Fleets)
} }
return nil return nil
} }
func (c *Command) completeSquadrons(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeSquadrons(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
if value, err := c.squadron.List(); err != nil { if value, err := c.squadron.List(); err != nil {
c.l.Debug(err.Error()) c.l.Debug(err.Error())
return nil return nil
@ -162,7 +152,7 @@ func (c *Command) completeSquadrons(ctx context.Context, t *tree.Root, r *readli
return suggests.List(value) return suggests.List(value)
} }
} }
func (c *Command) completeSquadronUnits(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { func (c *Command) completeSquadronUnits(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
cluster, fleet, squad := r.Args().At(0), r.Args().At(1), r.Args().At(2) cluster, fleet, squad := r.Args().At(0), r.Args().At(1), r.Args().At(2)
if value, err := c.squadron.ListUnits(ctx, squad, cluster, fleet, true); err != nil { if value, err := c.squadron.ListUnits(ctx, squad, cluster, fleet, true); err != nil {
c.l.Debug(err.Error()) c.l.Debug(err.Error())

View File

@ -28,7 +28,7 @@ type (
name string name string
cache cache.Namespace cache cache.Namespace
configKey string configKey string
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -70,54 +70,59 @@ func NewCommand(l log.Logger, c cache.Cache, op *onepassword.OnePassword, opts .
return nil, err return nil, err
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run wdio commands", Description: "Run wdio commands",
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "mode", Name: "mode",
Description: "run mode", Description: "Run mode",
Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.cfg.Modes.Keys()) return suggests.List(inst.cfg.Modes.Keys())
}, },
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "site", Name: "site",
Description: "configured site", Description: "Configured site",
Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.cfg.Sites.Keys()) return suggests.List(inst.cfg.Sites.Keys())
}, },
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "env", Name: "env",
Description: "configured env", Description: "Configured env",
Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest { Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
if value, ok := inst.cfg.Sites[r.Args().At(1)]; ok { if value, ok := inst.cfg.Sites[r.Args().At(1)]; ok {
return suggests.List(value.Keys()) return suggests.List(value.Keys())
} }
return nil return nil
}, },
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.String("tag", "", "run suite on specific tag") fs.Default().String("spec", "", "Run suite on specific specs")
fs.String("spec", "", "run suite on specific specs") fs.Default().String("suite", "", "Run suite on test suite")
fs.String("suite", "", "run suite on test suite") fs.Internal().String("tag", "", "Run suite on specific tag")
fs.String("scenario", "", "run suite on specific specs") fs.Internal().String("scenario", "", "Run suite on specific specs")
fs.String("log-level", "info", "set the log level") fs.Internal().String("log-level", "info", "Set the log level")
fs.Bool("headless", false, "run suite in headless mode") fs.Internal().Bool("ci", false, "Run suite on CI")
fs.Bool("debug", false, "run in debug mode and leave browser open after test failure") fs.Internal().Bool("headless", false, "Run suite in headless mode")
fs.Bool("bail", false, "stop test runner after specific amount of tests have failed") fs.Internal().Bool("debug", false, "Run in debug mode and leave browser open after test failure")
fs.Internal().Bool("bail", false, "Stop test runner after specific amount of tests have failed")
if r.Args().LenGte(4) { if r.Args().LenGte(4) {
if err := fs.SetValues("spec", inst.specs(ctx, r.Args().At(3))...); err != nil { if err := fs.Default().SetValues("spec", inst.specs(ctx, r.Args().At(3))...); err != nil {
return err return err
} }
if err := fs.SetValues("tag", inst.tags(ctx, r.Args().At(3), fs.GetString("spec"))...); err != nil { spec, err := fs.Default().GetString("spec")
if err != nil {
return err return err
} }
if err := fs.SetValues("scenario", inst.scenarios(ctx, r.Args().At(3), fs.GetString("spec"))...); err != nil { if err := fs.Internal().SetValues("tag", inst.tags(ctx, r.Args().At(3), spec)...); err != nil {
return err
}
if err := fs.Internal().SetValues("scenario", inst.scenarios(ctx, r.Args().At(3), spec)...); err != nil {
return err return err
} }
} }
if err := fs.SetValues("log-level", "info", "warn", "debug"); err != nil { if err := fs.Internal().SetValues("log-level", "info", "warn", "debug"); err != nil {
return err return err
} }
return nil return nil
@ -127,7 +132,7 @@ func NewCommand(l log.Logger, c cache.Cache, op *onepassword.OnePassword, opts .
Name: "path", Name: "path",
Repeat: false, Repeat: false,
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.paths(ctx)) return suggests.List(inst.paths(ctx))
}, },
}, },
@ -139,7 +144,7 @@ func NewCommand(l log.Logger, c cache.Cache, op *onepassword.OnePassword, opts .
}, },
}, },
}, },
} })
return inst, nil return inst, nil
} }
@ -149,11 +154,11 @@ func NewCommand(l log.Logger, c cache.Cache, op *onepassword.OnePassword, opts .
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -165,11 +170,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Run wdio commands. return c.commandTree.Help(ctx, r)
Usage:
wdio [mode] [site] [env] [path]
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -177,39 +178,38 @@ Usage:
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) execute(ctx context.Context, r *readline.Readline) error { func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
fs := r.FlagSets().Default()
ifs := r.FlagSets().Internal()
mode, site, env := r.Args().At(0), r.Args().At(1), r.Args().At(2) mode, site, env := r.Args().At(0), r.Args().At(1), r.Args().At(2)
siteConfig := c.cfg.Sites[site][env] siteConfig := c.cfg.Sites[site][env]
modeConfig := c.cfg.Modes[mode] modeConfig := c.cfg.Modes[mode]
logLevel := log.MustGet(ifs.GetString("log-level"))(c.l)
envs := []string{ envs := []string{
"LOG_LEVEL=" + r.FlagSet().GetString("log-level"), "LOG_LEVEL=" + logLevel,
"NODE_TLS_REJECT_UNAUTHORIZED=0", // allow TLS errors when in local mode with self-signed certificates "NODE_TLS_REJECT_UNAUTHORIZED=0", // allow TLS errors when in local mode with self-signed certificates
} }
var args []string var args []string
if r.FlagSet().GetBool("debug") { if log.MustGet(ifs.GetBool("debug"))(c.l) {
envs = append(envs, fmt.Sprintf("debug=%s", "true")) envs = append(envs, fmt.Sprintf("debug=%s", "true"))
} }
if r.FlagSet().GetBool("headless") { if log.MustGet(ifs.GetBool("headless"))(c.l) {
envs = append(envs, fmt.Sprintf("HEADLESS=%s", "true")) envs = append(envs, fmt.Sprintf("HEADLESS=%s", "true"))
} }
if r.FlagSet().GetBool("ci") { if log.MustGet(ifs.GetBool("ci"))(c.l) {
envs = append(envs, fmt.Sprintf("E2E_ENV=%s", "ci")) envs = append(envs, fmt.Sprintf("E2E_ENV=%s", "ci"))
} else { } else {
envs = append(envs, fmt.Sprintf("E2E_ENV=%s", "chromium")) envs = append(envs, fmt.Sprintf("E2E_ENV=%s", "chromium"))
} }
if value := r.FlagSet().GetString("scenario"); value != "" { if value := log.MustGet(ifs.GetString("scenario"))(c.l); value != "" {
envs = append(envs, fmt.Sprintf("SCENARIOS=%s", strings.Trim(value, "\""))) envs = append(envs, fmt.Sprintf("SCENARIOS=%s", strings.Trim(value, "\"")))
} }
if value := r.FlagSet().GetString("tag"); value != "" { if value := log.MustGet(ifs.GetString("tag"))(c.l); value != "" {
args = append(args, "--cucumberOpts.tagExpression", "'"+strings.Trim(value, "\"")+"'") args = append(args, "--cucumberOpts.tagExpression", "'"+strings.Trim(value, "\"")+"'")
} }
if value := r.FlagSet().GetString("spec"); value != "" {
args = append(args, "--spec", value)
}
if value := r.FlagSet().GetString("suite"); value != "" {
args = append(args, "--suite", value)
}
// base url // base url
baseURL := siteConfig.Domain baseURL := siteConfig.Domain
if modeConfig.HostPrefix != "" { if modeConfig.HostPrefix != "" {
@ -242,7 +242,7 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
c.l.Info("└ " + dir) c.l.Info("└ " + dir)
if err := shell.New(ctx, c.l, "wdio", "run", "e2e/wdio.conf.ts"). if err := shell.New(ctx, c.l, "wdio", "run", "e2e/wdio.conf.ts").
Args(args...). Args(args...).
Args(r.PassThroughFlags()...). Args(fs.Visited().Args()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Env(envs...). Env(envs...).

View File

@ -23,7 +23,7 @@ type (
l log.Logger l log.Logger
name string name string
cache cache.Namespace cache cache.Namespace
commandTree *tree.Root commandTree tree.Root
} }
CommandOption func(*Command) CommandOption func(*Command)
) )
@ -54,27 +54,25 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
} }
} }
inst.commandTree = &tree.Root{ inst.commandTree = tree.New(&tree.Node{
Name: inst.name, Name: inst.name,
Description: "run yarn commands", Description: "Run yarn commands",
Node: &tree.Node{
Execute: inst.execute, Execute: inst.execute,
},
Nodes: tree.Nodes{ Nodes: tree.Nodes{
{ {
Name: "install", Name: "install",
Description: "install dependencies", Description: "Install dependencies",
Args: tree.Args{inst.pathArg()}, Args: tree.Args{inst.pathArg()},
Execute: inst.install, Execute: inst.install,
}, },
{ {
Name: "run", Name: "run",
Description: "run script", Description: "Run script",
Args: tree.Args{ Args: tree.Args{
inst.pathArg(), inst.pathArg(),
{ {
Name: "script", Name: "script",
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(inst.scripts(ctx, r.Args().At(1))) return suggests.List(inst.scripts(ctx, r.Args().At(1)))
}, },
}, },
@ -83,9 +81,9 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
}, },
{ {
Name: "run-all", Name: "run-all",
Description: "run script in all", Description: "Run script in all",
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSet) error { Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Int("parallel", 0, "number of parallel processes") fs.Default().Int("parallel", 0, "number of parallel processes")
return nil return nil
}, },
Args: tree.Args{ Args: tree.Args{
@ -96,7 +94,7 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
Execute: inst.runAll, Execute: inst.runAll,
}, },
}, },
} })
return inst return inst
} }
@ -106,11 +104,11 @@ func NewCommand(l log.Logger, c cache.Cache, opts ...CommandOption) *Command {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (c *Command) Name() string { func (c *Command) Name() string {
return c.commandTree.Name return c.commandTree.Node().Name
} }
func (c *Command) Description() string { func (c *Command) Description() string {
return c.commandTree.Description return c.commandTree.Node().Description
} }
func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest { func (c *Command) Complete(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
@ -122,16 +120,7 @@ func (c *Command) Execute(ctx context.Context, r *readline.Readline) error {
} }
func (c *Command) Help(ctx context.Context, r *readline.Readline) string { func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
return `Run yarn commands. return c.commandTree.Help(ctx, r)
Usage:
yarn [cmd]
Available Commands:
install <path> install dependencies
run [path] [script] run script
run-all [script] run script in all
`
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -142,7 +131,6 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l, "yarn"). return shell.New(ctx, c.l, "yarn").
Args(r.Args()...). Args(r.Args()...).
Args(r.Flags()...). Args(r.Flags()...).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Run() Run()
} }
@ -151,7 +139,6 @@ func (c *Command) run(ctx context.Context, r *readline.Readline) error {
dir, script := r.Args().At(1), r.Args().At(2) dir, script := r.Args().At(1), r.Args().At(2)
c.l.Infof("Running script %q in %q", script, dir) c.l.Infof("Running script %q in %q", script, dir)
return shell.New(ctx, c.l, "yarn", "run", script). return shell.New(ctx, c.l, "yarn", "run", script).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Run() Run()
@ -166,7 +153,6 @@ func (c *Command) runAll(ctx context.Context, r *readline.Readline) error {
wg.Go(func() error { wg.Go(func() error {
c.l.Info("└ " + dir) c.l.Info("└ " + dir)
return shell.New(ctx, c.l, "yarn", "run", script). return shell.New(ctx, c.l, "yarn", "run", script).
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Run() Run()
@ -183,7 +169,6 @@ func (c *Command) install(ctx context.Context, r *readline.Readline) error {
} }
c.l.Infof("Running install in %q", dir) c.l.Infof("Running install in %q", dir)
return shell.New(ctx, c.l, "yarn", "install"). return shell.New(ctx, c.l, "yarn", "install").
Args(r.PassThroughFlags()...).
Args(r.AdditionalArgs()...). Args(r.AdditionalArgs()...).
Dir(dir). Dir(dir).
Run() Run()
@ -227,7 +212,7 @@ func (c *Command) pathArg() *tree.Arg {
return &tree.Arg{ return &tree.Arg{
Name: "path", Name: "path",
Optional: true, Optional: true,
Suggest: func(ctx context.Context, t *tree.Root, r *readline.Readline) []goprompt.Suggest { Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return suggests.List(c.paths(ctx)) return suggests.List(c.paths(ctx))
}, },
} }
@ -235,7 +220,7 @@ func (c *Command) pathArg() *tree.Arg {
func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) { func (c *Command) wg(ctx context.Context, r *readline.Readline) (context.Context, *errgroup.Group) {
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
if value, err := r.FlagSet().GetInt("parallel"); err == nil && value != 0 { if value, err := r.FlagSets().Default().GetInt("parallel"); err == nil && value != 0 {
wg.SetLimit(value) wg.SetLimit(value)
} else { } else {
wg.SetLimit(1) wg.SetLimit(1)