MCPcopy
hub / github.com/cli/cli / Rebuild

Method Rebuild

pkg/cmd/codespace/rebuild.go:43–82  ·  view source on GitHub ↗
(ctx context.Context, selector *CodespaceSelector, full bool)

Source from the content-addressed store, hash-verified

41}
42
43func (a *App) Rebuild(ctx context.Context, selector *CodespaceSelector, full bool) (err error) {
44 ctx, cancel := context.WithCancel(ctx)
45 defer cancel()
46
47 codespace, err := selector.Select(ctx)
48 if err != nil {
49 return err
50 }
51
52 // There's no need to rebuild again because users can't modify their codespace while it rebuilds
53 if codespace.State == api.CodespaceStateRebuilding {
54 fmt.Fprintf(a.io.Out, "%s is already rebuilding\n", codespace.Name)
55 return nil
56 }
57
58 codespaceConnection, err := codespaces.GetCodespaceConnection(ctx, a, a.apiClient, codespace)
59 if err != nil {
60 return fmt.Errorf("error connecting to codespace: %w", err)
61 }
62
63 fwd, err := portforwarder.NewPortForwarder(ctx, codespaceConnection)
64 if err != nil {
65 return fmt.Errorf("failed to create port forwarder: %w", err)
66 }
67 defer safeClose(fwd, &err)
68
69 invoker, err := rpc.CreateInvoker(ctx, fwd)
70 if err != nil {
71 return err
72 }
73 defer safeClose(invoker, &err)
74
75 err = invoker.RebuildContainer(ctx, full)
76 if err != nil {
77 return fmt.Errorf("rebuilding codespace via session: %w", err)
78 }
79
80 fmt.Fprintf(a.io.Out, "%s is rebuilding\n", codespace.Name)
81 return nil
82}

Callers 2

newRebuildCmdFunction · 0.80

Calls 7

GetCodespaceConnectionFunction · 0.92
NewPortForwarderFunction · 0.92
CreateInvokerFunction · 0.92
safeCloseFunction · 0.70
SelectMethod · 0.65
ErrorfMethod · 0.65
RebuildContainerMethod · 0.65

Tested by 1