add 'test filesystems' subcommand for testing filesystem filters

This commit is contained in:
Christian Schwarz
2018-10-13 15:53:52 +02:00
parent 5c3c83b2cb
commit 63169c51b7
5 changed files with 145 additions and 3 deletions
+13 -2
View File
@@ -45,6 +45,7 @@ type Subcommand struct {
NoRequireConfig bool
Run func(subcommand *Subcommand, args []string) error
SetupFlags func(f *pflag.FlagSet)
SetupSubcommands func() []*Subcommand
config *config.Config
configErr error
@@ -86,15 +87,25 @@ func (s *Subcommand) tryParseConfig() {
}
func AddSubcommand(s *Subcommand) {
addSubcommandToCobraCmd(rootCmd, s)
}
func addSubcommandToCobraCmd(c *cobra.Command, s *Subcommand) {
cmd := cobra.Command{
Use: s.Use,
Short: s.Short,
Run: s.run,
}
if s.SetupSubcommands == nil {
cmd.Run = s.run
} else {
for _, sub := range s.SetupSubcommands() {
addSubcommandToCobraCmd(&cmd, sub)
}
}
if s.SetupFlags != nil {
s.SetupFlags(cmd.Flags())
}
rootCmd.AddCommand(&cmd)
c.AddCommand(&cmd)
}