MCPcopy Index your code
hub / github.com/coder/coder / patchProxy

Method patchProxy

enterprise/cli/workspaceproxy.go:90–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88}
89
90func (r *RootCmd) patchProxy() *serpent.Command {
91 var (
92 proxyName string
93 displayName string
94 proxyIcon string
95 formatter = cliui.NewOutputFormatter(
96 // Text formatter should be human readable.
97 cliui.ChangeFormatterData(cliui.TextFormat(), func(data any) (any, error) {
98 response, ok := data.(codersdk.WorkspaceProxy)
99 if !ok {
100 return nil, xerrors.Errorf("unexpected type %T", data)
101 }
102 return fmt.Sprintf("Workspace Proxy %q updated successfully.", response.Name), nil
103 }),
104 cliui.JSONFormat(),
105 // Table formatter expects a slice, make a slice of one.
106 cliui.ChangeFormatterData(cliui.TableFormat([]codersdk.WorkspaceProxy{}, []string{"name", "url"}),
107 func(data any) (any, error) {
108 response, ok := data.(codersdk.WorkspaceProxy)
109 if !ok {
110 return nil, xerrors.Errorf("unexpected type %T", data)
111 }
112 return []codersdk.WorkspaceProxy{response}, nil
113 }),
114 )
115 )
116 cmd := &serpent.Command{
117 Use: "edit <name|id>",
118 Short: "Edit a workspace proxy",
119 Middleware: serpent.Chain(
120 serpent.RequireNArgs(1),
121 ),
122 Handler: func(inv *serpent.Invocation) error {
123 ctx := inv.Context()
124 client, err := r.InitClient(inv)
125 if err != nil {
126 return err
127 }
128 if proxyIcon == "" && displayName == "" && proxyName == "" {
129 _ = inv.Command.HelpHandler(inv)
130 return xerrors.Errorf("specify at least one field to update")
131 }
132
133 // This is cheeky, but you can also use a uuid string in
134 // 'DeleteWorkspaceProxyByName' and it will work.
135 proxy, err := client.WorkspaceProxyByName(ctx, inv.Args[0])
136 if err != nil {
137 return xerrors.Errorf("fetch workspace proxy %q: %w", inv.Args[0], err)
138 }
139
140 // Use the existing values if the user didn't specify them.
141 if proxyName == "" {
142 proxyName = proxy.Name
143 }
144 if displayName == "" {
145 displayName = proxy.DisplayName
146 }
147 if proxyIcon == "" {

Callers 1

workspaceProxyMethod · 0.95

Calls 13

InitClientMethod · 0.95
NewOutputFormatterFunction · 0.92
ChangeFormatterDataFunction · 0.92
TextFormatFunction · 0.92
JSONFormatFunction · 0.92
TableFormatFunction · 0.92
WorkspaceProxyByNameMethod · 0.80
PatchWorkspaceProxyMethod · 0.80
ContextMethod · 0.65
FormatMethod · 0.65
AttachOptionsMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected