// runs here func runFlag(x *xEnv, argv ...string) error { c := app.AppCtx() app.Dprintf("flag %v\n", argv) switch len(argv) { case 1: flgs := "" if c.Debug { flgs += "D" } if x.debugX { flgs += "X" } if x.debugL { flgs += "L" } if x.iflag { flgs += "i" } app.Printf("flags %s\n", flgs) return nil case 2: default: app.Eprintf("usage: flags [±]flags\n") return dbg.ErrUsage } flg := argv[1] set := flg[0] == '+' clear := flg[0] != '-' if !set && !clear { // clear all flags c.Debug = false x.debugX = false x.debugL = false // then set those named set = true } else { flg = flg[1:] } for _, r := range flg { switch r { case 'D': c.Debug = (c.Debug && !clear) || set case 'X': x.debugX = (x.debugX && !clear) || set case 'L': x.debugL = (x.debugL && !clear) || set case 'i': app.Warn("'-i' cannot be changed") default: app.Warn("unknown flag '%c'", r) } } return nil }
// Print to stderr a description of the usage. func (f *Flags) Usage() { if f.Argv0 == "" { f.Argv0 = os.Args[0] } ks := []string{} for k := range f.defs { ks = append(ks, k) } sort.Sort(sort.StringSlice(ks)) opts := f.optUsage(ks) app.Eprintf("usage: %s %s %s\n", f.Argv0, opts, f.usage) if f.plus != nil { sep := "" if !strings.Contains(f.plus.help, ":") { sep = ":" } app.Eprintf("\t+%s%s %s\n", f.plus.name, sep, f.plus.help) } if f.minus != nil { sep := "" if !strings.Contains(f.minus.help, ":") { sep = ":" } app.Eprintf("\t-%s %s\n", f.minus.name, sep, f.minus.help) } for _, k := range ks { def := f.defs[k] sep := "" if !strings.Contains(def.help, ":") { sep = ":" } switch def.valp.(type) { case *Counter: app.Eprintf("\t-%s%s %s\n", def.name, sep, def.help) app.Eprintf("\t\tcan be repeated\n") default: app.Eprintf("\t-%s%s %s\n", def.name, sep, def.help) } } }
func (l *lex) dprintf(fmts string, args ...interface{}) { if l.debug { app.Eprintf(fmts, args...) } }
func (t *Fs) Dprintf(fmts string, args ...interface{}) { if t.Dbg { app.Eprintf(fmts, args...) } }