Skip to content

coder licenses add CLI command #3632

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 5 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion cli/clitest/clitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import (
// New creates a CLI instance with a configuration pointed to a
// temporary testing directory.
func New(t *testing.T, args ...string) (*cobra.Command, config.Root) {
cmd := cli.Root(cli.AGPL())
return NewWithSubcommands(t, cli.AGPL(), args...)
}

func NewWithSubcommands(
t *testing.T, subcommands []*cobra.Command, args ...string,
) (*cobra.Command, config.Root) {
cmd := cli.Root(subcommands)
dir := t.TempDir()
root := config.Root(dir)
cmd.SetArgs(append([]string{"--global-config", dir}, args...))
Expand Down
2 changes: 1 addition & 1 deletion cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func configSSH() *cobra.Command {
),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func create() *cobra.Command {
Use: "create [name]",
Short: "Create a workspace from a template",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func deleteWorkspace() *cobra.Command {
return err
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func featuresList() *cobra.Command {
Use: "list",
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func list() *cobra.Command {
Aliases: []string{"ls"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func logout() *cobra.Command {
Use: "logout",
Short: "Remove the local authenticated session",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/parameterslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func parameterList() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
scope, name := args[0], args[1]

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func portForward() *cobra.Command {
return xerrors.New("no port-forwards requested")
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/publickey.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func publickey() *cobra.Command {
Aliases: []string{"pubkey"},
Short: "Output your public key for Git operations",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return xerrors.Errorf("create codersdk client: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
return nil
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
// If the client is unauthenticated we can ignore the check.
// The child commands should handle an unauthenticated client.
if xerrors.Is(err, errUnauthenticated) {
Expand Down Expand Up @@ -190,9 +190,9 @@ func isTest() bool {
return flag.Lookup("test.v") != nil
}

// createClient returns a new client from the command context.
// CreateClient returns a new client from the command context.
// It reads from global configuration files if flags are not set.
func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
func CreateClient(cmd *cobra.Command) (*codersdk.Client, error) {
root := createConfig(cmd)
rawURL, err := cmd.Flags().GetString(varURL)
if err != nil || rawURL == "" {
Expand Down Expand Up @@ -226,7 +226,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
}

// createAgentClient returns a new client from the command context.
// It works just like createClient, but uses the agent token and URL instead.
// It works just like CreateClient, but uses the agent token and URL instead.
func createAgentClient(cmd *cobra.Command) (*codersdk.Client, error) {
rawURL, err := cmd.Flags().GetString(varAgentURL)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cli/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func scheduleShow() *cobra.Command {
Long: scheduleShowDescriptionLong,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func scheduleStart() *cobra.Command {
Long: scheduleStartDescriptionLong,
Args: cobra.RangeArgs(2, 4),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func scheduleStop() *cobra.Command {
Short: "Edit workspace stop schedule",
Long: scheduleStopDescriptionLong,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func scheduleOverride() *cobra.Command {
return err
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return xerrors.Errorf("create client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func show() *cobra.Command {
Short: "Show details of a workspace's resources and agents",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ssh() *cobra.Command {
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func start() *cobra.Command {
Short: "Build a workspace with the start state",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func statePull() *cobra.Command {
Use: "pull <workspace> [file]",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func statePush() *cobra.Command {
Use: "push <workspace> <file>",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func stop() *cobra.Command {
return err
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func templateCreate() *cobra.Command {
Short: "Create a template from the current directory or as specified by flag",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatedelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func templateDelete() *cobra.Command {
templates = []codersdk.Template{}
)

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templateedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func templateEdit() *cobra.Command {
Args: cobra.ExactArgs(1),
Short: "Edit the metadata of a template by name.",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return xerrors.Errorf("create client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func templateList() *cobra.Command {
Short: "List all the templates available for the organization",
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatepull.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func templatePull() *cobra.Command {
dest = args[1]
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return xerrors.Errorf("create client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatepush.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func templatePush() *cobra.Command {
Args: cobra.MaximumNArgs(1),
Short: "Push a new template version from the current directory or as specified by flag",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func templateVersionsList() *cobra.Command {
Args: cobra.ExactArgs(1),
Short: "List all the versions of the specified template",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return xerrors.Errorf("create client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func update() *cobra.Command {
Args: cobra.ExactArgs(1),
Short: "Update a workspace to the latest template version",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/usercreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func userCreate() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cli/userlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func userList() *cobra.Command {
Use: "list",
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func userSingle() *cobra.Command {
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/userstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
},
),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/wireguardtunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func wireguardPortForward() *cobra.Command {
return xerrors.New("no port-forwards requested")
}

client, err := createClient(cmd)
client, err := CreateClient(cmd)
if err != nil {
return err
}
Expand Down
Loading