(fs afero.Fs)
| 226 | } |
| 227 | |
| 228 | func (*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 |
no test coverage detected