| 1 | package cmdenv |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | |
| 6 | cmds "github.com/ipfs/go-ipfs-cmds" |
| 7 | ) |
| 8 | |
| 9 | // ProgressBarFullTemplate is the pb/v3 template used by transfer |
| 10 | // commands once the total byte count is known: byte counter, bar, |
| 11 | // speed, percent, and ETA. Explicit format args override pb's |
| 12 | // defaults so the rate renders as "MiB/s" (not "MiB p/s") and the |
| 13 | // remaining time falls back to "ETA ?" while speed is unknown. |
| 14 | const ProgressBarFullTemplate = `{{counters . }} {{bar . }} {{speed . "%s/s" "?/s"}} {{percent . }} {{rtime . "ETA %s" "%s" "ETA ?"}}` |
| 15 | |
| 16 | // ShouldShowProgress reports whether a progress bar should be rendered |
| 17 | // based on a boolean option. An explicit `--<flag>=true|false` always |
| 18 | // wins; when unset, it defaults to whether stderr is a terminal. |
| 19 | func ShouldShowProgress(req *cmds.Request, flag string) bool { |
| 20 | if v, ok := req.Options[flag].(bool); ok { |
| 21 | return v |
| 22 | } |
| 23 | return IsTerminal(os.Stderr) |
| 24 | } |