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

Method scheduleShow

cli/schedule.go:76–144  ·  view source on GitHub ↗

scheduleShow() is just a wrapper for list() with some different defaults.

()

Source from the content-addressed store, hash-verified

74
75// scheduleShow() is just a wrapper for list() with some different defaults.
76func (r *RootCmd) scheduleShow() *serpent.Command {
77 var (
78 filter cliui.WorkspaceFilter
79 formatter = cliui.NewOutputFormatter(
80 cliui.TableFormat(
81 []scheduleListRow{},
82 []string{
83 "workspace",
84 "starts at",
85 "starts next",
86 "stops after",
87 "stops next",
88 },
89 ),
90 cliui.JSONFormat(),
91 )
92 )
93 showCmd := &serpent.Command{
94 Use: "show <workspace | --search <query> | --all>",
95 Short: "Show workspace schedules",
96 Long: scheduleShowDescriptionLong,
97 Middleware: serpent.Chain(
98 serpent.RequireRangeArgs(0, 1),
99 ),
100 Handler: func(inv *serpent.Invocation) error {
101 client, err := r.InitClient(inv)
102 if err != nil {
103 return err
104 }
105 // To preserve existing behavior, if an argument is passed we will
106 // only show the schedule for that workspace.
107 // This will clobber the search query if one is passed.
108 f := filter.Filter()
109 if len(inv.Args) == 1 {
110 // If the argument contains a slash, we assume it's a full owner/name reference
111 if strings.Contains(inv.Args[0], "/") {
112 _, workspaceName, err := codersdk.SplitWorkspaceIdentifier(inv.Args[0])
113 if err != nil {
114 return err
115 }
116 f.FilterQuery = fmt.Sprintf("name:%s", workspaceName)
117 } else {
118 // Otherwise, we assume it's a workspace name owned by the current user
119 f.FilterQuery = fmt.Sprintf("owner:me name:%s", inv.Args[0])
120 }
121 }
122 res, err := QueryConvertWorkspaces(inv.Context(), client, f, scheduleListRowFromWorkspace)
123 if err != nil {
124 return err
125 }
126
127 out, err := formatter.Format(inv.Context(), res)
128 if err != nil {
129 return err
130 }
131
132 if out == "" {
133 cliui.Infof(inv.Stderr, "No schedules found.")

Callers 1

schedulesMethod · 0.95

Calls 12

InitClientMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
SplitWorkspaceIdentifierFunction · 0.92
InfofFunction · 0.92
QueryConvertWorkspacesFunction · 0.85
ContextMethod · 0.65
FormatMethod · 0.65
AttachOptionsMethod · 0.65
FilterMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected