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

Method list

cli/list.go:78–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76}
77
78func (r *RootCmd) list() *serpent.Command {
79 var (
80 filter cliui.WorkspaceFilter
81 formatter = cliui.NewOutputFormatter(
82 cliui.TableFormat(
83 []WorkspaceListRow{},
84 []string{
85 "workspace",
86 "template",
87 "status",
88 "healthy",
89 "last built",
90 "current version",
91 "outdated",
92 "starts at",
93 "stops after",
94 },
95 ),
96 cliui.JSONFormat(),
97 )
98 sharedWithMe bool
99 )
100 cmd := &serpent.Command{
101 Annotations: workspaceCommand,
102 Use: "list",
103 Short: "List workspaces",
104 Aliases: []string{"ls"},
105 Middleware: serpent.Chain(
106 serpent.RequireNArgs(0),
107 ),
108 Options: serpent.OptionSet{
109 {
110 Name: "shared-with-me",
111 Description: "Show workspaces shared with you.",
112 Flag: "shared-with-me",
113 Value: serpent.BoolOf(&sharedWithMe),
114 Hidden: true,
115 },
116 },
117 Handler: func(inv *serpent.Invocation) error {
118 client, err := r.InitClient(inv)
119 if err != nil {
120 return err
121 }
122
123 workspaceFilter := filter.Filter()
124 if sharedWithMe {
125 user, err := client.User(inv.Context(), codersdk.Me)
126 if err != nil {
127 return xerrors.Errorf("fetch current user: %w", err)
128 }
129 workspaceFilter.SharedWithUser = user.ID.String()
130
131 // Unset the default query that conflicts with the --shared-with-me flag
132 if workspaceFilter.FilterQuery == "owner:me" {
133 workspaceFilter.FilterQuery = ""
134 }
135 }

Callers 1

CoreSubcommandsMethod · 0.95

Calls 12

InitClientMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
QueryConvertWorkspacesFunction · 0.85
UserMethod · 0.65
ContextMethod · 0.65
FormatMethod · 0.65
AttachOptionsMethod · 0.65
FilterMethod · 0.45
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected