diff --git a/cmd/internal/flags.go b/cmd/internal/flags.go index f8038ac86494..ed8f4e35b7ca 100644 --- a/cmd/internal/flags.go +++ b/cmd/internal/flags.go @@ -42,7 +42,7 @@ func PersistentFlags(parentCmd *cobra.Command, opts *ToolboxOptions) { // ConfigFileFlags defines flags related to the configuration file. // It should be applied to any command that requires configuration loading. -func ConfigFileFlags(flags *pflag.FlagSet, opts *ToolboxOptions) { +func ConfigFileFlags(parentCmd *cobra.Command, flags *pflag.FlagSet, opts *ToolboxOptions) { flags.StringVar(&opts.Config, "config", "", "File path specifying the tool configuration. Cannot be used with --configs, or --config-folder.") flags.StringVar(&opts.Config, "tools-file", "", "File path specifying the tool configuration. Cannot be used with --tools-files, or --tools-folder.") _ = flags.MarkDeprecated("tools-file", "please use --config instead") // DEPRECATED @@ -52,6 +52,7 @@ func ConfigFileFlags(flags *pflag.FlagSet, opts *ToolboxOptions) { flags.StringVar(&opts.ConfigFolder, "config-folder", "", "Directory path containing YAML tool configuration files. All .yaml and .yml files in the directory will be loaded and merged. Cannot be used with --config, or --configs.") flags.StringVar(&opts.ConfigFolder, "tools-folder", "", "Directory path containing YAML tool configuration files. All .yaml and .yml files in the directory will be loaded and merged. Cannot be used with --tools-file, or --tools-files.") _ = flags.MarkDeprecated("tools-folder", "please use --config-folder instead") // DEPRECATED + parentCmd.MarkFlagsMutuallyExclusive("config", "configs", "config-folder", "tools-file", "tools-files", "tools-folder") // Fetch prebuilt tools sources to customize the help description prebuiltHelp := fmt.Sprintf( "Use a prebuilt tool configuration by source type. Allowed: '%s'. Can be specified multiple times.", diff --git a/cmd/internal/invoke/command.go b/cmd/internal/invoke/command.go index 531fbfcfd70c..714318bd1738 100644 --- a/cmd/internal/invoke/command.go +++ b/cmd/internal/invoke/command.go @@ -42,7 +42,7 @@ Example: }, } flags := cmd.Flags() - internal.ConfigFileFlags(flags, opts) + internal.ConfigFileFlags(cmd, flags, opts) return cmd } diff --git a/cmd/internal/migrate/command.go b/cmd/internal/migrate/command.go index a5b6489b41ed..3c7f64e0b673 100644 --- a/cmd/internal/migrate/command.go +++ b/cmd/internal/migrate/command.go @@ -39,7 +39,7 @@ func NewCommand(opts *internal.ToolboxOptions) *cobra.Command { Long: "Migrate all configuration files provided to the flat format, updating deprecated fields and ensuring compatibility.", } flags := cmd.Flags() - internal.ConfigFileFlags(flags, opts) + internal.ConfigFileFlags(cmd.Command, flags, opts) flags.BoolVar(&cmd.dryRun, "dry-run", false, "Preview the converted format without applying actual changes.") cmd.RunE = func(*cobra.Command, []string) error { return runMigrate(cmd, opts) } return cmd.Command diff --git a/cmd/internal/options.go b/cmd/internal/options.go index 3affd3aaf4ee..d1f648c7c907 100644 --- a/cmd/internal/options.go +++ b/cmd/internal/options.go @@ -148,15 +148,6 @@ func (opts *ToolboxOptions) GetCustomConfigFiles(ctx context.Context) ([]string, // Load Custom Configurations if isCustomConfigured { - // Enforce exclusivity among custom flags (tools-file vs tools-files vs tools-folder) - if (opts.Config != "" && len(opts.Configs) > 0) || - (opts.Config != "" && opts.ConfigFolder != "") || - (len(opts.Configs) > 0 && opts.ConfigFolder != "") { - errMsg := fmt.Errorf("--config/--tools-file, --configs/--tools-files, and --config-folder/--tools-folder flags cannot be used simultaneously") - logger.ErrorContext(ctx, errMsg.Error()) - return nil, isCustomConfigured, errMsg - } - if len(opts.Configs) > 0 { // Use tools-files logger.InfoContext(ctx, fmt.Sprintf("retrieving %d tool configuration files", len(opts.Configs))) diff --git a/cmd/internal/skills/command.go b/cmd/internal/skills/command.go index a51196c0de9f..68d26679eec5 100644 --- a/cmd/internal/skills/command.go +++ b/cmd/internal/skills/command.go @@ -57,7 +57,7 @@ func NewCommand(opts *internal.ToolboxOptions) *cobra.Command { } flags := cmd.Flags() - internal.ConfigFileFlags(flags, opts) + internal.ConfigFileFlags(cmd.Command, flags, opts) flags.StringVar(&cmd.name, "name", "", "Name of the generated skill.") flags.StringVar(&cmd.description, "description", "", "Description of the generated skill") flags.StringVar(&cmd.toolset, "toolset", "", "Name of the toolset to convert into a skill. If not provided, all tools will be included.") diff --git a/cmd/root.go b/cmd/root.go index d5d8f40e7de0..f8233ea7e313 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -115,7 +115,7 @@ func NewCommand(opts *internal.ToolboxOptions) *cobra.Command { // setup flags that are common across all commands internal.PersistentFlags(cmd, opts) flags := cmd.Flags() - internal.ConfigFileFlags(flags, opts) + internal.ConfigFileFlags(cmd, flags, opts) internal.ServeFlags(flags, opts) flags.BoolVar(&opts.Cfg.DisableReload, "disable-reload", false, "Disables dynamic reloading of tools file.") flags.BoolVar(&opts.Cfg.IgnoreUnknownTools, "ignore-unknown-tools", false, "Log warnings and skip unknown/unsupported tool types instead of failing to start.") diff --git a/cmd/root_test.go b/cmd/root_test.go index 263809844fb5..7c3cf1b19085 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -666,12 +666,12 @@ func TestMutuallyExclusiveFlags(t *testing.T) { { desc: "--config and --configs", args: []string{"--config", "my.yaml", "--configs", "a.yaml,b.yaml"}, - errString: "--config/--tools-file, --configs/--tools-files, and --config-folder/--tools-folder flags cannot be used simultaneously", + errString: "if any flags in the group [config configs config-folder tools-file tools-files tools-folder] are set none of the others can be; [config configs] were all set", }, { desc: "--config-folder and --configs", args: []string{"--config-folder", "./", "--configs", "a.yaml,b.yaml"}, - errString: "--config/--tools-file, --configs/--tools-files, and --config-folder/--tools-folder flags cannot be used simultaneously", + errString: "if any flags in the group [config configs config-folder tools-file tools-files tools-folder] are set none of the others can be; [config-folder configs] were all set", }, }