Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

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

Merged
cmoog merged 4 commits intomasterfromwarn-on-rebuild-required-ch352
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 0 additions & 4 deletionscoder-sdk/env.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,10 +39,6 @@ type RebuildMessage struct {
Text string `json:"text"`
Required bool `json:"required"`
AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" tab:"-"`
RebuildMessages []struct {
Text string `json:"text"`
Required bool `json:"required"`
} `json:"rebuild_messages" tab:"-"`
}

// EnvironmentStat represents the state of an environment
Expand Down
1 change: 1 addition & 0 deletionsdocs/coder_sh.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ coder sh [environment_name] [<command [args...]>] [flags]

```
coder sh backend-env
coder sh front-end-dev cat ~/config.json
```

### Options
Expand Down
66 changes: 34 additions & 32 deletionsinternal/cmd/cmd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,24 +21,24 @@ func Make() *cobra.Command {
}

app.AddCommand(
makeLoginCmd(),
makeLogoutCmd(),
makeShellCmd(),
makeUsersCmd(),
makeConfigSSHCmd(),
makeSecretsCmd(),
envsCommand(),
makeSyncCmd(),
makeURLCmd(),
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.

cmoog reacted with thumbs up emoji
Copy link
ContributorAuthor

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 ofmake*

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
}

funcgenDocs(rootCmd *cobra.Command) *cobra.Command {
funcgenDocsCmd(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 DownExpand 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 deletioninternal/cmd/configssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import (
"golang.org/x/xerrors"
)

funcmakeConfigSSHCmd() *cobra.Command {
funcconfigSSHCmd() *cobra.Command {
var (
configpath string
remove = false
Expand Down
18 changes: 9 additions & 9 deletionsinternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ import (

const defaultImgTag = "latest"

funcenvsCommand() *cobra.Command {
funcenvsCmd() *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 DownExpand Up@@ -84,7 +84,7 @@ func lsEnvsCommand(user *string) *cobra.Command {
return cmd
}

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

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

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

funcrmEnvsCommand(user *string) *cobra.Command {
funcrmEnvsCmd(user *string) *cobra.Command {
var force bool
cmd := &cobra.Command{
Use: "rm [...environment_names]",
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/login.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import (
"golang.org/x/xerrors"
)

funcmakeLoginCmd() *cobra.Command {
funcloginCmd() *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 deletioninternal/cmd/logout.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ import (
"golang.org/x/xerrors"
)

funcmakeLogoutCmd() *cobra.Command {
funclogoutCmd() *cobra.Command {
return &cobra.Command{
Use: "logout",
Short: "Remove local authentication credentials if any exist",
Expand Down
18 changes: 9 additions & 9 deletionsinternal/cmd/secrets.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

funcmakeSecretsCmd() *cobra.Command {
funcsecretsCmd() *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:removeSecretsCmd(&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
}

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

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

funcmakeViewSecret(userEmail *string) func(cmd *cobra.Command, args []string) error {
funcviewSecretCmd(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
}
}

funcmakeRemoveSecrets(userEmail *string) func(c *cobra.Command, args []string) error {
funcremoveSecretsCmd(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
25 changes: 19 additions & 6 deletionsinternal/cmd/shell.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,11 +23,12 @@ import (

func getEnvsForCompletion(user string) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
client, err := newClient()
if err != nil {
return nil, cobra.ShellCompDirectiveDefault
}
envs, err := getEnvs(context.TODO(), client, user)
envs, err := getEnvs(ctx, client, user)
if err != nil {
return nil, cobra.ShellCompDirectiveDefault
}
Expand All@@ -40,7 +41,7 @@ func getEnvsForCompletion(user string) func(cmd *cobra.Command, args []string, t
}
}

funcmakeShellCmd() *cobra.Command {
funcshCmd() *cobra.Command {
return &cobra.Command{
Use: "sh [environment_name] [<command [args...]>]",
Short: "Open a shell and execute commands in a Coder environment",
Expand All@@ -49,13 +50,13 @@ func makeShellCmd() *cobra.Command {
DisableFlagParsing: true,
ValidArgsFunction: getEnvsForCompletion(coder.Me),
RunE: shell,
Example: "coder sh backend-env",
Example: `coder sh backend-env
coder sh front-end-dev cat ~/config.json`,
}
}

func shell(_ *cobra.Command, cmdArgs []string) error {
ctx := context.Background()

func shell(cmd *cobra.Command, cmdArgs []string) error {
ctx := cmd.Context()
command := "sh"
args := []string{"-c"}
if len(cmdArgs) > 1 {
Expand DownExpand Up@@ -106,6 +107,18 @@ func runCommand(ctx context.Context, envName, command string, args []string) err
return xerrors.Errorf("find environment: %w", err)
}

// check if a rebuild is required before attempting to open a shell
for _, r := range env.RebuildMessages {
// use the first rebuild message that is required
if r.Required {
return clog.Error(
fmt.Sprintf(`environment "%s" requires a rebuild`, env.Name),
clog.Causef(r.Text), clog.BlankLine,
clog.Tipf(`run "coder envs rebuild %s" to rebuild`, env.Name),
)
}
}

termFD := os.Stdout.Fd()

isInteractive := terminal.IsTerminal(int(termFD))
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/sync.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ import (
"golang.org/x/xerrors"
)

funcmakeSyncCmd()*cobra.Command {
funcsyncCmd()*cobra.Command {
varinitbool
cmd:=&cobra.Command{
Use:"sync [local directory] [<env name>:<remote directory>]",
Expand Down
10 changes: 5 additions & 5 deletionsinternal/cmd/urls.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

funcmakeURLCmd() *cobra.Command {
funcurlCmd() *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 DownExpand 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.
funcmakeListDevURLs(outputFmt *string) func(cmd *cobra.Command, args []string) error {
funclistDevURLsCmd(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 DownExpand Up@@ -120,7 +120,7 @@ func makeListDevURLs(outputFmt *string) func(cmd *cobra.Command, args []string)
}
}

funcmakeCreateDevURL() *cobra.Command {
funccreateDevURLCmd() *cobra.Command {
var (
access string
urlname string
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/users.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@ import (
"cdr.dev/coder-cli/internal/x/xtabwriter"
)

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

[8]ページ先頭

©2009-2025 Movatter.jp