aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/main.go')
-rw-r--r--cmd/krino/main.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/cmd/krino/main.go b/cmd/krino/main.go
index 7a6a5f7..29da31a 100644
--- a/cmd/krino/main.go
+++ b/cmd/krino/main.go
@@ -61,7 +61,8 @@ Sort the files in the directories listed in krino.conf by their rules.
type globals struct {
yes, dry, verbose, json bool
noColor, noPager bool
- minAge string // --min-age as given; "" when not
+ minAge string // --min-age as given
+ minAgeSet bool // --min-age was given, even as an empty value
conf string
}
@@ -127,10 +128,26 @@ func flagSet(name string, g *globals) *flag.FlagSet {
fs.BoolVar(&g.noColor, "no-color", g.noColor, "")
fs.BoolVar(&g.noPager, "no-pager", g.noPager, "")
fs.BoolVar(&g.noPager, "P", g.noPager, "")
- fs.StringVar(&g.minAge, "min-age", g.minAge, "")
+ fs.Var(minAgeValue{g}, "min-age", "")
return fs
}
+// minAgeValue is --min-age as a flag.Value, so that a flag given with an
+// empty value (--min-age=) is told apart from one not given at all.
+type minAgeValue struct{ g *globals }
+
+func (v minAgeValue) String() string {
+ if v.g == nil {
+ return ""
+ }
+ return v.g.minAge
+}
+
+func (v minAgeValue) Set(s string) error {
+ v.g.minAge, v.g.minAgeSet = s, true
+ return nil
+}
+
// parse parses args into fs. On -h it prints the usage and returns (0, false);
// on a bad flag it reports it and returns (2, false).
func parse(fs *flag.FlagSet, args []string, stdout, stderr io.Writer) (int, bool) {