40 lines
824 B
Go
40 lines
824 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"code.icb4dc0.de/buildr/buildr/modules"
|
|
)
|
|
|
|
type ModuleCommandOption func(cmd *cobra.Command)
|
|
|
|
func WithShort(short string) ModuleCommandOption {
|
|
return func(cmd *cobra.Command) {
|
|
cmd.Short = short
|
|
}
|
|
}
|
|
|
|
func ExecuteModuleCommand(
|
|
category modules.Category,
|
|
cmder ModuleCommander,
|
|
argsProvider KnownTasksArgProvider,
|
|
opts ...ModuleCommandOption,
|
|
) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: modules.CategoryName(category),
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
ValidArgsFunction: argsProvider.ValidTasksArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return cmder.RunModule(cmd.Context(), category, args[0])
|
|
},
|
|
}
|
|
|
|
for i := range opts {
|
|
opts[i](cmd)
|
|
}
|
|
|
|
return cmd
|
|
}
|