MCPcopy Create free account
hub / github.com/cli/cli / UpdatePortVisibility

Method UpdatePortVisibility

pkg/cmd/codespace/ports.go:234–276  ·  view source on GitHub ↗
(ctx context.Context, selector *CodespaceSelector, args []string)

Source from the content-addressed store, hash-verified

232}
233
234func (a *App) UpdatePortVisibility(ctx context.Context, selector *CodespaceSelector, args []string) (err error) {
235 ports, err := a.parsePortVisibilities(args)
236 if err != nil {
237 return fmt.Errorf("error parsing port arguments: %w", err)
238 }
239
240 codespace, err := selector.Select(ctx)
241 if err != nil {
242 return err
243 }
244
245 codespaceConnection, err := codespaces.GetCodespaceConnection(ctx, a, a.apiClient, codespace)
246 if err != nil {
247 return fmt.Errorf("error connecting to codespace: %w", err)
248 }
249
250 fwd, err := portforwarder.NewPortForwarder(ctx, codespaceConnection)
251 if err != nil {
252 return fmt.Errorf("failed to create port forwarder: %w", err)
253 }
254 defer safeClose(fwd, &err)
255
256 // TODO: check if port visibility can be updated in parallel instead of sequentially
257 for _, port := range ports {
258 err := a.RunWithProgress(fmt.Sprintf("Updating port %d visibility to: %s", port.number, port.visibility), func() (err error) {
259 // wait for success or failure
260 ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
261 defer cancel()
262
263 err = fwd.UpdatePortVisibility(ctx, port.number, port.visibility)
264 if err != nil {
265 return fmt.Errorf("error updating port %d to %s: %w", port.number, port.visibility, err)
266 }
267 return nil
268 })
269 if err != nil {
270 return err
271 }
272
273 }
274
275 return nil
276}
277
278type portVisibility struct {
279 number int

Callers 1

runUpdateVisibilityTestFunction · 0.95

Calls 8

parsePortVisibilitiesMethod · 0.95
RunWithProgressMethod · 0.95
UpdatePortVisibilityMethod · 0.95
GetCodespaceConnectionFunction · 0.92
NewPortForwarderFunction · 0.92
safeCloseFunction · 0.70
ErrorfMethod · 0.65
SelectMethod · 0.65

Tested by 1

runUpdateVisibilityTestFunction · 0.76