Skip to content

Commit

Permalink
config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fentas committed Mar 28, 2024
1 parent 9ab14dc commit 1396a72
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type CmdBinaryOptions struct {
IO *streams.IO
Binaries []*binary.Binary
NoConfig bool
config *state.BinaryList

// Flags
Expand All @@ -37,6 +38,10 @@ func NewCmdBinary(options *CmdBinaryOptions) *cobra.Command {
options.ensure[b] = new(bool)
}

configExample := ""
if !options.NoConfig {
configExample = " and defined in b.yaml"

Check warning on line 43 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L41-L43

Added lines #L41 - L43 were not covered by tests
}
cmd := &cobra.Command{
Use: "b",
Short: "Manage all binaries",
Expand All @@ -46,12 +51,15 @@ func NewCmdBinary(options *CmdBinaryOptions) *cobra.Command {
if path == "" {
return cmdutil.UsageErrorf(cmd, "Could not find a suitable path to install binaries")
}
var err error
options.config, err = state.LoadConfig()
return err
if !options.NoConfig {
var err error
options.config, err = state.LoadConfig()
return err

Check warning on line 57 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L54-L57

Added lines #L54 - L57 were not covered by tests
}
return nil

Check warning on line 59 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L59

Added line #L59 was not covered by tests
},
Example: templates.Examples(`
# List all installed binaries and defined in b.yaml
# List all installed binaries` + configExample + `
b --all
# Print as JSON
Expand Down Expand Up @@ -85,7 +93,11 @@ func NewCmdBinary(options *CmdBinaryOptions) *cobra.Command {
}

func (o *CmdBinaryOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&o.all, "all", "a", false, "Binaries installed and defined in b.yaml")
all := "Binaries installed and defined in b.yaml"
if o.NoConfig {
all = "All binaries"

Check warning on line 98 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L96-L98

Added lines #L96 - L98 were not covered by tests
}
cmd.Flags().BoolVarP(&o.all, "all", "a", false, all)

Check warning on line 100 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L100

Added line #L100 was not covered by tests
for _, b := range o.Binaries {
cmd.Flags().BoolVar(o.ensure[b], b.Name, false, b.Name+" binary")
}
Expand Down Expand Up @@ -116,7 +128,7 @@ func (o *CmdBinaryOptions) Complete(cmd *cobra.Command, args []string) error {
}
} else if o.all {
for b, do := range o.ensure {
if b.BinaryExists() {
if !o.NoConfig || b.BinaryExists() {

Check warning on line 131 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L131

Added line #L131 was not covered by tests
*do = true
}
}
Expand Down

0 comments on commit 1396a72

Please sign in to comment.