Skip to content

chore: early merge clibase foundations #6542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port over some of clibase
  • Loading branch information
ammario committed Mar 9, 2023
commit a57639b34fd59bea0749882bdd1649b784b24583
1 change: 1 addition & 0 deletions cli/clibase/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (i *Invokation) run(state *runState) error {

if i.parsedFlags == nil {
i.parsedFlags = pflag.NewFlagSet(i.Command.Name(), pflag.ContinueOnError)
// We handle Usage ourselves.
i.parsedFlags.Usage = func() {}
}

Expand Down
21 changes: 0 additions & 21 deletions cli/clibase/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,3 @@ func TestCommand_HyphenHypen(t *testing.T) {

require.Equal(t, "--verbose --friendly", stdio.Stdout.String())
}

func TestCommand_Help(t *testing.T) {
t.Parallel()

cmd := &clibase.Cmd{
Options: []clibase.Option{
{
Flag: "superautopets",
},
},
Handler: func(i *clibase.Invokation) error {
t.Fatalf("should not be called")
return nil
},
}

inv, stdio := clibasetest.Invoke(cmd, "-h")
err := inv.Run()
require.NoError(t, err)
require.Contains(t, stdio.Stdout.String(), "superautopets")
}
4 changes: 2 additions & 2 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ReadGitAuthProvidersFromEnv(environ []string) ([]codersdk.GitAuthConfig, er
sort.Strings(environ)

var providers []codersdk.GitAuthConfig
for _, v := range clibase.EnvsWithPrefix(environ, envPrefix+"GITAUTH_") {
for _, v := range clibase.ParseEnviron(environ, envPrefix+"GITAUTH_") {
tokens := strings.SplitN(v.Name, "_", 2)
if len(tokens) != 2 {
return nil, xerrors.Errorf("invalid env var: %s", v.Name)
Expand Down Expand Up @@ -184,7 +184,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
return xerrors.Errorf("set defaults: %w", err)
}

err = cliOpts.ParseEnv(envPrefix, os.Environ())
err = cliOpts.ParseEnv(clibase.ParseEnviron(os.Environ(), envPrefix))
if err != nil {
return xerrors.Errorf("parse env: %w", err)
}
Expand Down