func (w *YAMLConfigLoader) Wrap(cmd cli.Command) cli.Command { cmd.Flags = append(cmd.Flags, []cli.Flag{ cli.StringFlag{"config", w.DefaultPath, "path to YAML config file", ""}, }...) oldAction := cmd.Action cmd.Action = func(c *cli.Context) { configFile := c.String("config") if configFile != "" { err := w.LoadFromFile(configFile) if err != nil { fmt.Println(err) os.Exit(1) } } oldAction(c) } return cmd }
func (w *Logged) Wrap(cmd cli.Command) cli.Command { cmd.Flags = append(cmd.Flags, []cli.Flag{ cli.StringFlag{"log", w.DefaultTarget, "path to log file, 'stdout', 'stderr' or 'false'", ""}, cli.StringFlag{"log-level", w.DefaultLevel, "logging level", ""}, cli.StringFlag{"log-format", w.DefaultFormat, "log record format: 'term', 'logfmt', 'json'", ""}, }...) oldAction := cmd.Action cmd.Action = func(c *cli.Context) { handler, err := w.HandlerFor(c.String("log"), c.String("log-level"), c.String("log-format")) if err != nil { fmt.Println(err) os.Exit(1) } for _, l := range w.Loggers { l.SetHandler(handler) } oldAction(c) } return cmd }