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

Unide envs (create|edit) commands#168

Merged
cmoog merged 6 commits intomasterfromunhide-create
Nov 4, 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
2 changes: 1 addition & 1 deletionci/integration/envs_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,7 +108,7 @@ func TestEnvsCLI(t *testing.T) {
// Successfully output help.
c.Run(ctx, "coder envs create --help").Assert(t,
tcli.Success(),
tcli.StdoutMatches(regexp.QuoteMeta("Create a newenvironment under the active user.")),
tcli.StdoutMatches(regexp.QuoteMeta("Create a newCoder environment.")),
tcli.StderrEmpty(),
)

Expand Down
2 changes: 1 addition & 1 deletioncoder-sdk/client.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import (
"net/url"
)

// Me is theroute param to access resources of the authenticated user.
// Me is theuser ID of the authenticated user.
const Me = "me"

// Client wraps the Coder HTTP API.
Expand Down
10 changes: 2 additions & 8 deletionscoder-sdk/error.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/http/httputil"

"golang.org/x/xerrors"
)
Expand DownExpand Up@@ -34,22 +33,17 @@ type HTTPError struct {
}

func (e *HTTPError) Error() string {
dump, err := httputil.DumpResponse(e.Response, false)
if err != nil {
return fmt.Sprintf("dump response: %+v", err)
}

var msg APIError
// Try to decode the payload as an error, if it fails or if there is no error message,
// return the response URL with the dump.
if err := json.NewDecoder(e.Response.Body).Decode(&msg); err != nil || msg.Err.Msg == "" {
return fmt.Sprintf("%s\n%s", e.Response.Request.URL,dump)
return fmt.Sprintf("%s: %d %s", e.Request.URL,e.StatusCode, e.Status)
}

// If the payload was a in the expected error format with a message, include it.
return msg.Err.Msg
}

func bodyError(resp *http.Response) error {
return &HTTPError{resp}
return &HTTPError{Response:resp}
}
2 changes: 2 additions & 0 deletionsdocs/coder_envs.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,8 @@ Perform operations on the Coder environments owned by the active user.
### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
* [coder envs create](coder_envs_create.md) - create a new environment.
* [coder envs edit](coder_envs_edit.md) - edit an existing environment and initiate a rebuild.
* [coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
* [coder envs rebuild](coder_envs_rebuild.md) - rebuild a Coder environment
* [coder envs rm](coder_envs_rm.md) - remove Coder environments by name
Expand Down
45 changes: 45 additions & 0 deletionsdocs/coder_envs_create.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
## coder envs create

create a new environment.

### Synopsis

Create a new Coder environment.

```
coder envs create [environment_name] [flags]
```

### Examples

```
# create a new environment using default resource amounts
coder envs create my-new-env --image ubuntu
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu
```

### Options

```
-c, --cpu float32 number of cpu cores the environment should be provisioned with.
-d, --disk int GB of disk storage an environment should be provisioned with.
--follow follow buildlog after initiating rebuild
-g, --gpus int number GPUs an environment should be provisioned with.
-h, --help help for create
-i, --image string name of the image to base the environment off of.
-m, --memory float32 GB of RAM an environment should be provisioned with.
-o, --org string ID of the organization the environment should be created under.
-t, --tag string tag of the image the environment will be based off of. (default "latest")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO

* [coder envs](coder_envs.md) - Interact with Coder environments

45 changes: 45 additions & 0 deletionsdocs/coder_envs_edit.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
## coder envs edit

edit an existing environment and initiate a rebuild.

### Synopsis

Edit an existing environment and initate a rebuild.

```
coder envs edit [flags]
```

### Examples

```
coder envs edit back-end-env --cpu 4

coder envs edit back-end-env --disk 20
```

### Options

```
-c, --cpu float32 The number of cpu cores the environment should be provisioned with.
-d, --disk int The amount of disk storage an environment should be provisioned with.
--follow follow buildlog after initiating rebuild
-g, --gpu int The amount of disk storage to provision the environment with.
-h, --help help for edit
-i, --image string name of the image you want the environment to be based off of.
-m, --memory float32 The amount of RAM an environment should be provisioned with.
-o, --org string name of the organization the environment should be created under.
-t, --tag string image tag of the image you want to base the environment off of. (default "latest")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO

* [coder envs](coder_envs.md) - Interact with Coder environments

29 changes: 12 additions & 17 deletionsinternal/cmd/ceapi.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,27 +84,23 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
}

type findImgConf struct {
client *coder.Client
email string
imgName string
orgName string
}

func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
func findImg(ctx context.Context,client *coder.Client,conf findImgConf) (*coder.Image, error) {
switch {
case conf.email == "":
return nil, xerrors.New("user email unset")
case conf.imgName == "":
return nil, xerrors.New("image name unset")
}

imgs, err := getImgs(ctx,
getImgsConf{
client: conf.client,
email: conf.email,
orgName: conf.orgName,
},
)
imgs, err := getImgs(ctx, client, getImgsConf{
email: conf.email,
orgName: conf.orgName,
})
if err != nil {
return nil, err
}
Expand All@@ -129,38 +125,37 @@ func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
return nil, xerrors.New("image not found - did you forget to import this image?")
}

lines := []string{clog.Tipf("Did you mean?")}
lines := []string{clog.Hintf("Did you mean?")}

for _, img := range possibleMatches {
lines = append(lines, img.Repository)
lines = append(lines,fmt.Sprintf(" %s",img.Repository))
}
return nil, clog.Fatal(
fmt.Sprintf("Found %d possible matches for %q.", len(possibleMatches), conf.imgName),
fmt.Sprintf("image %s not found", conf.imgName),
lines...,
)
}

type getImgsConf struct {
client *coder.Client
email string
orgName string
}

func getImgs(ctx context.Context, conf getImgsConf) ([]coder.Image, error) {
u, err :=conf.client.UserByEmail(ctx, conf.email)
func getImgs(ctx context.Context,client *coder.Client,conf getImgsConf) ([]coder.Image, error) {
u, err := client.UserByEmail(ctx, conf.email)
if err != nil {
return nil, err
}

orgs, err :=conf.client.Organizations(ctx)
orgs, err := client.Organizations(ctx)
if err != nil {
return nil, err
}

orgs = lookupUserOrgs(u, orgs)

for _, org := range orgs {
imgs, err :=conf.client.OrganizationImages(ctx, org.ID)
imgs, err := client.OrganizationImages(ctx, org.ID)
if err != nil {
return nil, err
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp