diff options
Diffstat (limited to 'cmd/krino/common.go')
| -rw-r--r-- | cmd/krino/common.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/krino/common.go b/cmd/krino/common.go index 15c32f6..5b6869a 100644 --- a/cmd/krino/common.go +++ b/cmd/krino/common.go @@ -33,6 +33,30 @@ func minAgeOverride(g *globals) (d time.Duration, set bool, err error) { return d, true, nil } +// refuseUnusedFlags refuses the global flags a command does not use - +// -y and -n unless usesYesDry, and --json and -v - instead of silently +// ignoring them, so "krino -n new ...", meant as a preview, cannot write +// config (re-review cli F4). It reports whether it refused. +func refuseUnusedFlags(g *globals, stderr io.Writer, cmd string, usesYesDry bool) (int, bool) { + var given []string + if !usesYesDry && g.yes { + given = append(given, "-y") + } + if !usesYesDry && g.dry { + given = append(given, "-n") + } + if g.json { + given = append(given, "--json") + } + if g.verbose { + given = append(given, "-v") + } + if len(given) == 0 { + return 0, false + } + return usageError(stderr, fmt.Sprintf("%s does not take %s", cmd, strings.Join(given, ", "))), true +} + // cacheDir is where every directory's keyword cache lives (spec ยง6.1). func cacheDir() string { return filepath.Join(xdg.CacheHome(), "krino") |
