buildr/internal/cmd/exec_module.go

40 lines
824 B
Go
Raw Permalink Normal View History

package cmd
import (
"github.com/spf13/cobra"
2023-06-22 16:06:56 +00:00
"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,
2023-06-18 12:34:20 +00:00
argsProvider KnownTasksArgProvider,
opts ...ModuleCommandOption,
) *cobra.Command {
cmd := &cobra.Command{
Use: modules.CategoryName(category),
Args: cobra.ExactArgs(1),
SilenceUsage: true,
SilenceErrors: true,
2023-06-18 12:34:20 +00:00
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
}