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

Method statDisk

cli/stat.go:228–284  ·  view source on GitHub ↗
(fs afero.Fs)

Source from the content-addressed store, hash-verified

226}
227
228func (*RootCmd) statDisk(fs afero.Fs) *serpent.Command {
229 var (
230 pathArg string
231 prefixArg string
232 st *clistat.Statter
233 formatter = cliui.NewOutputFormatter(cliui.TextFormat(), cliui.JSONFormat())
234 )
235 cmd := &serpent.Command{
236 Use: "disk",
237 Short: "Show disk usage, in gigabytes.",
238 Middleware: initStatterMW(&st, fs),
239 Options: serpent.OptionSet{
240 {
241 Flag: "path",
242 Value: serpent.StringOf(&pathArg),
243 Description: "Path for which to check disk usage.",
244 Default: "/",
245 },
246 {
247 Flag: "prefix",
248 Default: clistat.PrefixHumanGibi,
249 Description: "SI Prefix for disk measurement.",
250 Value: serpent.EnumOf(&prefixArg,
251 clistat.PrefixHumanKibi,
252 clistat.PrefixHumanMebi,
253 clistat.PrefixHumanGibi,
254 clistat.PrefixHumanTebi,
255 ),
256 },
257 },
258 Handler: func(inv *serpent.Invocation) error {
259 pfx := clistat.ParsePrefix(prefixArg)
260 // Users may also call `coder stat disk <path>`.
261 if len(inv.Args) > 0 {
262 pathArg = inv.Args[0]
263 }
264 ds, err := st.Disk(pfx, pathArg)
265 if err != nil {
266 if os.IsNotExist(err) {
267 //nolint:gocritic // fmt.Errorf produces a more concise error.
268 return fmt.Errorf("not found: %q", pathArg)
269 }
270 return err
271 }
272
273 out, err := formatter.Format(inv.Context(), ds)
274 if err != nil {
275 return err
276 }
277 _, err = fmt.Fprintln(inv.Stdout, out)
278 return err
279 },
280 }
281
282 formatter.AttachOptions(&cmd.Options)
283 return cmd
284}
285

Callers 1

statMethod · 0.95

Calls 9

NewOutputFormatterFunction · 0.92
TextFormatFunction · 0.92
JSONFormatFunction · 0.92
initStatterMWFunction · 0.85
DiskMethod · 0.65
FormatMethod · 0.65
ContextMethod · 0.65
AttachOptionsMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected