Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Error coder sh commands if the env requires a rebuild #163

Merged
merged 4 commits into from
Oct 29, 2020
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
fixup! Error coder sh commands if the env requires a rebuild
  • Loading branch information
cmoog committed Oct 29, 2020
commit d0adddcd00fb9508919fc3468a30fcde3f0cd9d5
64 changes: 33 additions & 31 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ func Make() *cobra.Command {
}

app.AddCommand(
makeLoginCmd(),
makeLogoutCmd(),
loginCmd(),
logoutCmd(),
shCmd(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the rename of this particular command? Consistency seems better here, so we should change them all or not change this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair point. Just updated all uses of make*

makeUsersCmd(),
makeConfigSSHCmd(),
makeSecretsCmd(),
envsCommand(),
makeSyncCmd(),
makeURLCmd(),
usersCmd(),
configSSHCmd(),
secretsCmd(),
envsCmd(),
syncCmd(),
urlCmd(),
resourceCmd(),
completionCmd,
genDocs(app),
completionCmd(),
genDocsCmd(app),
)
app.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
return app
}

func genDocs(rootCmd *cobra.Command) *cobra.Command {
func genDocsCmd(rootCmd *cobra.Command) *cobra.Command {
return &cobra.Command{
Use: "gen-docs [dir_path]",
Short: "Generate a markdown documentation tree for the root command.",
Expand All @@ -52,17 +52,18 @@ func genDocs(rootCmd *cobra.Command) *cobra.Command {
}

// reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Example: `coder completion fish > ~/.config/fish/completions/coder.fish
func completionCmd() *cobra.Command {
return &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Example: `coder completion fish > ~/.config/fish/completions/coder.fish
coder completion zsh > "${fpath[1]}/_coder"

Linux:
$ coder completion bash > /etc/bash_completion.d/coder
MacOS:
$ coder completion bash > /usr/local/etc/bash_completion.d/coder`,
Long: `To load completions:
Long: `To load completions:

Bash:

Expand Down Expand Up @@ -93,19 +94,20 @@ $ coder completion fish | source
To load completions for each session, execute once:
$ coder completion fish > ~/.config/fish/completions/coder.fish
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletion(os.Stdout) // Best effort.
case "zsh":
_ = cmd.Root().GenZshCompletion(os.Stdout) // Best effort.
case "fish":
_ = cmd.Root().GenFishCompletion(os.Stdout, true) // Best effort.
case "powershell":
_ = cmd.Root().GenPowerShellCompletion(os.Stdout) // Best effort.
}
},
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletion(os.Stdout) // Best effort.
case "zsh":
_ = cmd.Root().GenZshCompletion(os.Stdout) // Best effort.
case "fish":
_ = cmd.Root().GenFishCompletion(os.Stdout, true) // Best effort.
case "powershell":
_ = cmd.Root().GenPowerShellCompletion(os.Stdout) // Best effort.
}
},
}
}
2 changes: 1 addition & 1 deletion internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"golang.org/x/xerrors"
)

func makeConfigSSHCmd() *cobra.Command {
func configSSHCmd() *cobra.Command {
var (
configpath string
remove = false
Expand Down
18 changes: 9 additions & 9 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

const defaultImgTag = "latest"

func envsCommand() *cobra.Command {
func envsCmd() *cobra.Command {
var user string
cmd := &cobra.Command{
Use: "envs",
Expand All @@ -28,12 +28,12 @@ func envsCommand() *cobra.Command {

cmd.AddCommand(
lsEnvsCommand(&user),
stopEnvsCommand(&user),
rmEnvsCommand(&user),
stopEnvsCmd(&user),
rmEnvsCmd(&user),
watchBuildLogCommand(&user),
rebuildEnvCommand(&user),
createEnvCommand(&user),
editEnvCommand(&user),
createEnvCmd(&user),
editEnvCmd(&user),
)
return cmd
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func lsEnvsCommand(user *string) *cobra.Command {
return cmd
}

func stopEnvsCommand(user *string) *cobra.Command {
func stopEnvsCmd(user *string) *cobra.Command {
return &cobra.Command{
Use: "stop [...environment_names]",
Short: "stop Coder environments by name",
Expand Down Expand Up @@ -131,7 +131,7 @@ coder envs --user charlie@coder.com ls -o json \
}
}

func createEnvCommand(user *string) *cobra.Command {
func createEnvCmd(user *string) *cobra.Command {
var (
org string
img string
Expand Down Expand Up @@ -239,7 +239,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
return cmd
}

func editEnvCommand(user *string) *cobra.Command {
func editEnvCmd(user *string) *cobra.Command {
var (
org string
img string
Expand Down Expand Up @@ -336,7 +336,7 @@ coder envs edit back-end-env --disk 20`,
return cmd
}

func rmEnvsCommand(user *string) *cobra.Command {
func rmEnvsCmd(user *string) *cobra.Command {
var force bool
cmd := &cobra.Command{
Use: "rm [...environment_names]",
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"golang.org/x/xerrors"
)

func makeLoginCmd() *cobra.Command {
func loginCmd() *cobra.Command {
return &cobra.Command{
Use: "login [Coder Enterprise URL eg. https://my.coder.domain/]",
Short: "Authenticate this client for future operations",
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/xerrors"
)

func makeLogoutCmd() *cobra.Command {
func logoutCmd() *cobra.Command {
return &cobra.Command{
Use: "logout",
Short: "Remove local authentication credentials if any exist",
Expand Down
18 changes: 9 additions & 9 deletions internal/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

func makeSecretsCmd() *cobra.Command {
func secretsCmd() *cobra.Command {
var user string
cmd := &cobra.Command{
Use: "secrets",
Expand All @@ -26,28 +26,28 @@ func makeSecretsCmd() *cobra.Command {
&cobra.Command{
Use: "ls",
Short: "List all secrets owned by the active user",
RunE: listSecrets(&user),
RunE: listSecretsCmd(&user),
},
makeCreateSecret(&user),
createSecretCmd(&user),
&cobra.Command{
Use: "rm [...secret_name]",
Short: "Remove one or more secrets by name",
Args: cobra.MinimumNArgs(1),
RunE: makeRemoveSecrets(&user),
RunE: remoteSecretsCmd(&user),
Example: "coder secrets rm mysql-password mysql-user",
},
&cobra.Command{
Use: "view [secret_name]",
Short: "View a secret by name",
Args: cobra.ExactArgs(1),
RunE: makeViewSecret(&user),
RunE: viewSecretCmd(&user),
Example: "coder secrets view mysql-password",
},
)
return cmd
}

func makeCreateSecret(userEmail *string) *cobra.Command {
func createSecretCmd(userEmail *string) *cobra.Command {
var (
fromFile string
fromLiteral string
Expand Down Expand Up @@ -136,7 +136,7 @@ coder secrets create aws-credentials --from-file ./credentials.json`,
return cmd
}

func listSecrets(userEmail *string) func(cmd *cobra.Command, _ []string) error {
func listSecretsCmd(userEmail *string) func(cmd *cobra.Command, _ []string) error {
return func(cmd *cobra.Command, _ []string) error {
client, err := newClient()
if err != nil {
Expand Down Expand Up @@ -169,7 +169,7 @@ func listSecrets(userEmail *string) func(cmd *cobra.Command, _ []string) error {
}
}

func makeViewSecret(userEmail *string) func(cmd *cobra.Command, args []string) error {
func viewSecretCmd(userEmail *string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
var (
name = args[0]
Expand All @@ -196,7 +196,7 @@ func makeViewSecret(userEmail *string) func(cmd *cobra.Command, args []string) e
}
}

func makeRemoveSecrets(userEmail *string) func(c *cobra.Command, args []string) error {
func remoteSecretsCmd(userEmail *string) func(c *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
client, err := newClient()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"golang.org/x/xerrors"
)

func makeSyncCmd() *cobra.Command {
func syncCmd() *cobra.Command {
var init bool
cmd := &cobra.Command{
Use: "sync [local directory] [<env name>:<remote directory>]",
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

func makeURLCmd() *cobra.Command {
func urlCmd() *cobra.Command {
var outputFmt string
cmd := &cobra.Command{
Use: "urls",
Expand All @@ -29,7 +29,7 @@ func makeURLCmd() *cobra.Command {
Short: "List all DevURLs for an environment",
Args: cobra.ExactArgs(1),
ValidArgsFunction: getEnvsForCompletion(coder.Me),
RunE: makeListDevURLs(&outputFmt),
RunE: listDevURLsCmd(&outputFmt),
}
lsCmd.Flags().StringVarP(&outputFmt, "output", "o", "human", "human|json")

Expand All @@ -43,7 +43,7 @@ func makeURLCmd() *cobra.Command {
cmd.AddCommand(
lsCmd,
rmCmd,
makeCreateDevURL(),
createDevURLCmd(),
)

return cmd
Expand Down Expand Up @@ -89,7 +89,7 @@ func accessLevelIsValid(level string) bool {

// Run gets the list of active devURLs from the cemanager for the
// specified environment and outputs info to stdout.
func makeListDevURLs(outputFmt *string) func(cmd *cobra.Command, args []string) error {
func listDevURLsCmd(outputFmt *string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
envName := args[0]
devURLs, err := urlList(cmd.Context(), envName)
Expand Down Expand Up @@ -120,7 +120,7 @@ func makeListDevURLs(outputFmt *string) func(cmd *cobra.Command, args []string)
}
}

func makeCreateDevURL() *cobra.Command {
func createDevURLCmd() *cobra.Command {
var (
access string
urlname string
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

func makeUsersCmd() *cobra.Command {
func usersCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "users",
Short: "Interact with Coder user accounts",
Expand Down