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

feat(cli): add enterprise external-workspaces CLI command#19287

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kacpersaw merged 4 commits intomainfromkacpersaw/feat-coder-attach-cli
Aug 19, 2025
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
22 changes: 21 additions & 1 deletioncli/create.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,12 @@ const PresetNone = "none"

var ErrNoPresetFound = xerrors.New("no preset found")

func (r *RootCmd) create() *serpent.Command {
type CreateOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you should put a comment here explaining what these are for. E.g. "CreateOptions provides middleware for the workspace creation command so it can be extended for other create commands."

BeforeCreate func(ctx context.Context, client *codersdk.Client, template codersdk.Template, templateVersionID uuid.UUID) error
AfterCreate func(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, workspace codersdk.Workspace) error
}

func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
var (
templateName string
templateVersion string
Expand DownExpand Up@@ -305,6 +310,13 @@ func (r *RootCmd) create() *serpent.Command {
_, _ = fmt.Fprintf(inv.Stdout, "%s", cliui.Bold("No preset applied."))
}

if opts.BeforeCreate != nil {
err = opts.BeforeCreate(inv.Context(), client, template, templateVersionID)
if err != nil {
return xerrors.Errorf("before create: %w", err)
}
}

richParameters, err := prepWorkspaceBuild(inv, client, prepWorkspaceBuildArgs{
Action: WorkspaceCreate,
TemplateVersionID: templateVersionID,
Expand DownExpand Up@@ -366,6 +378,14 @@ func (r *RootCmd) create() *serpent.Command {
cliui.Keyword(workspace.Name),
cliui.Timestamp(time.Now()),
)

if opts.AfterCreate != nil {
err = opts.AfterCreate(inv.Context(), inv, client, workspace)
if err != nil {
return err
}
}

return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletioncli/exp_rpty.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ func handleRPTY(inv *serpent.Invocation, client *codersdk.Client, args handleRPT
reconnectID = uuid.New()
}

ws, agt, _, err :=getWorkspaceAndAgent(ctx, inv, client, true, args.NamedWorkspace)
ws, agt, _, err :=GetWorkspaceAndAgent(ctx, inv, client, true, args.NamedWorkspace)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletionscli/list.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import (
// workspaceListRow is the type provided to the OutputFormatter. This is a bit
// dodgy but it's the only way to do complex display code for one format vs. the
// other.
typeworkspaceListRow struct {
typeWorkspaceListRow struct {
// For JSON format:
codersdk.Workspace `table:"-"`

Expand All@@ -40,7 +40,7 @@ type workspaceListRow struct {
DailyCost string `json:"-" table:"daily cost"`
}

funcworkspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)workspaceListRow {
funcWorkspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)WorkspaceListRow {
status := codersdk.WorkspaceDisplayStatus(workspace.LatestBuild.Job.Status, workspace.LatestBuild.Transition)

lastBuilt := now.UTC().Sub(workspace.LatestBuild.Job.CreatedAt).Truncate(time.Second)
Expand All@@ -55,7 +55,7 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
favIco = "★"
}
workspaceName := favIco + " " + workspace.OwnerName + "/" + workspace.Name
returnworkspaceListRow{
returnWorkspaceListRow{
Favorite: workspace.Favorite,
Workspace: workspace,
WorkspaceName: workspaceName,
Expand All@@ -80,7 +80,7 @@ func (r *RootCmd) list() *serpent.Command {
filter cliui.WorkspaceFilter
formatter = cliui.NewOutputFormatter(
cliui.TableFormat(
[]workspaceListRow{},
[]WorkspaceListRow{},
[]string{
"workspace",
"template",
Expand All@@ -107,7 +107,7 @@ func (r *RootCmd) list() *serpent.Command {
r.InitClient(client),
),
Handler: func(inv *serpent.Invocation) error {
res, err :=queryConvertWorkspaces(inv.Context(), client, filter.Filter(),workspaceListRowFromWorkspace)
res, err :=QueryConvertWorkspaces(inv.Context(), client, filter.Filter(),WorkspaceListRowFromWorkspace)
if err != nil {
return err
}
Expand DownExpand Up@@ -137,9 +137,9 @@ func (r *RootCmd) list() *serpent.Command {
// queryConvertWorkspaces is a helper function for converting
// codersdk.Workspaces to a different type.
// It's used by the list command to convert workspaces to
//workspaceListRow, and by the schedule command to
//WorkspaceListRow, and by the schedule command to
// convert workspaces to scheduleListRow.
funcqueryConvertWorkspaces[T any](ctx context.Context, client *codersdk.Client, filter codersdk.WorkspaceFilter, convertF func(time.Time, codersdk.Workspace) T) ([]T, error) {
funcQueryConvertWorkspaces[T any](ctx context.Context, client *codersdk.Client, filter codersdk.WorkspaceFilter, convertF func(time.Time, codersdk.Workspace) T) ([]T, error) {
var empty []T
workspaces, err := client.Workspaces(ctx, filter)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletionscli/open.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,7 +72,7 @@ func (r *RootCmd) openVSCode() *serpent.Command {
// need to wait for the agent to start.
workspaceQuery := inv.Args[0]
autostart := true
workspace, workspaceAgent, otherWorkspaceAgents, err :=getWorkspaceAndAgent(ctx, inv, client, autostart, workspaceQuery)
workspace, workspaceAgent, otherWorkspaceAgents, err :=GetWorkspaceAndAgent(ctx, inv, client, autostart, workspaceQuery)
if err != nil {
return xerrors.Errorf("get workspace and agent: %w", err)
}
Expand DownExpand Up@@ -316,7 +316,7 @@ func (r *RootCmd) openApp() *serpent.Command {
}

workspaceName := inv.Args[0]
ws, agt, _, err :=getWorkspaceAndAgent(ctx, inv, client, false, workspaceName)
ws, agt, _, err :=GetWorkspaceAndAgent(ctx, inv, client, false, workspaceName)
if err != nil {
var sdkErr *codersdk.Error
if errors.As(err, &sdkErr) && sdkErr.StatusCode() == http.StatusNotFound {
Expand Down
2 changes: 1 addition & 1 deletioncli/ping.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -110,7 +110,7 @@ func (r *RootCmd) ping() *serpent.Command {
defernotifyCancel()

workspaceName:=inv.Args[0]
_,workspaceAgent,_,err:=getWorkspaceAndAgent(
_,workspaceAgent,_,err:=GetWorkspaceAndAgent(
ctx,inv,client,
false,// Do not autostart for a ping.
workspaceName,
Expand Down
2 changes: 1 addition & 1 deletioncli/portforward.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ func (r *RootCmd) portForward() *serpent.Command {
return xerrors.New("no port-forwards requested")
}

workspace, workspaceAgent, _, err :=getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
workspace, workspaceAgent, _, err :=GetWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletioncli/root.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,7 +108,7 @@ func (r *RootCmd) CoreSubcommands() []*serpent.Command {
// Workspace Commands
r.autoupdate(),
r.configSSH(),
r.create(),
r.Create(CreateOptions{}),
r.deleteWorkspace(),
r.favorite(),
r.list(),
Expand Down
4 changes: 2 additions & 2 deletionscli/schedule.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,7 +117,7 @@ func (r *RootCmd) scheduleShow() *serpent.Command {
f.FilterQuery = fmt.Sprintf("owner:me name:%s", inv.Args[0])
}
}
res, err :=queryConvertWorkspaces(inv.Context(), client, f, scheduleListRowFromWorkspace)
res, err :=QueryConvertWorkspaces(inv.Context(), client, f, scheduleListRowFromWorkspace)
if err != nil {
return err
}
Expand DownExpand Up@@ -307,7 +307,7 @@ func (r *RootCmd) scheduleExtend() *serpent.Command {
}

func displaySchedule(ws codersdk.Workspace, out io.Writer) error {
rows := []workspaceListRow{workspaceListRowFromWorkspace(time.Now(), ws)}
rows := []WorkspaceListRow{WorkspaceListRowFromWorkspace(time.Now(), ws)}
rendered, err := cliui.DisplayTable(rows, "workspace", []string{
"workspace", "starts at", "starts next", "stops after", "stops next",
})
Expand Down
2 changes: 1 addition & 1 deletioncli/speedtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
return xerrors.Errorf("--direct (-d) is incompatible with --%s", varDisableDirect)
}

_, workspaceAgent, _, err :=getWorkspaceAndAgent(ctx, inv, client, false, inv.Args[0])
_, workspaceAgent, _, err :=GetWorkspaceAndAgent(ctx, inv, client, false, inv.Args[0])
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletionscli/ssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -754,7 +754,7 @@ func findWorkspaceAndAgentByHostname(
hostname = strings.TrimSuffix(hostname, qualifiedSuffix)
}
hostname = normalizeWorkspaceInput(hostname)
ws, agent, _, err :=getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, hostname)
ws, agent, _, err :=GetWorkspaceAndAgent(ctx, inv, client, !disableAutostart, hostname)
return ws, agent, err
}

Expand DownExpand Up@@ -827,11 +827,11 @@ startWatchLoop:
}
}

//getWorkspaceAgent returns the workspace and agent selected using either the
//GetWorkspaceAndAgent returns the workspace and agent selected using either the
// `<workspace>[.<agent>]` syntax via `in`. It will also return any other agents
// in the workspace as a slice for use in child->parent lookups.
// If autoStart is true, the workspace will be started if it is not already running.
funcgetWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, input string) (codersdk.Workspace, codersdk.WorkspaceAgent, []codersdk.WorkspaceAgent, error) { //nolint:revive
funcGetWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *codersdk.Client, autostart bool, input string) (codersdk.Workspace, codersdk.WorkspaceAgent, []codersdk.WorkspaceAgent, error) { //nolint:revive
var (
workspace codersdk.Workspace
// The input will be `owner/name.agent`
Expand DownExpand Up@@ -880,7 +880,7 @@ func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *
switch cerr.StatusCode() {
case http.StatusConflict:
_, _ = fmt.Fprintln(inv.Stderr, "Unable to start the workspace due to conflict, the workspace may be starting, retrying without autostart...")
returngetWorkspaceAndAgent(ctx, inv, client, false, input)
returnGetWorkspaceAndAgent(ctx, inv, client, false, input)

case http.StatusForbidden:
_, err = startWorkspace(inv, client, workspace, workspaceParameterFlags{}, buildFlags{}, WorkspaceUpdate)
Expand Down
2 changes: 1 addition & 1 deletioncli/vscodessh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,7 +102,7 @@ func (r *RootCmd) vscodeSSH() *serpent.Command {
// will call this command after the workspace is started.
autostart := false

workspace, workspaceAgent, _, err :=getWorkspaceAndAgent(ctx, inv, client, autostart, fmt.Sprintf("%s/%s", owner, name))
workspace, workspaceAgent, _, err :=GetWorkspaceAndAgent(ctx, inv, client, autostart, fmt.Sprintf("%s/%s", owner, name))
if err != nil {
return xerrors.Errorf("find workspace and agent: %w", err)
}
Expand Down
20 changes: 20 additions & 0 deletionsdocs/manifest.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1159,6 +1159,26 @@
"description": "Print auth for an external provider",
"path": "reference/cli/external-auth_access-token.md"
},
{
"title": "external-workspaces",
"description": "Create or manage external workspaces",
"path": "reference/cli/external-workspaces.md"
},
{
"title": "external-workspaces agent-instructions",
"description": "Get the instructions for an external agent",
"path": "reference/cli/external-workspaces_agent-instructions.md"
},
{
"title": "external-workspaces create",
"description": "Create a new external workspace",
"path": "reference/cli/external-workspaces_create.md"
},
{
"title": "external-workspaces list",
"description": "List external workspaces",
"path": "reference/cli/external-workspaces_list.md"
},
{
"title": "favorite",
"description": "Add a workspace to your favorites",
Expand Down
29 changes: 29 additions & 0 deletionsdocs/reference/cli/external-workspaces.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

21 changes: 21 additions & 0 deletionsdocs/reference/cli/external-workspaces_agent-instructions.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp