diff --git a/cmd/cbzoptimizer/commands/flags.go b/cmd/cbzoptimizer/commands/flags.go index b6478f2..6bd6db6 100644 --- a/cmd/cbzoptimizer/commands/flags.go +++ b/cmd/cbzoptimizer/commands/flags.go @@ -9,8 +9,14 @@ import ( "github.com/thediveo/enumflag/v2" ) -// setupFormatFlag sets up the format flag for a command -// If bindViper is true, it will also bind the flag to viper +// setupFormatFlag sets up the format flag for a command. +// +// Parameters: +// - cmd: The Cobra command to add the format flag to +// - converterType: Pointer to the ConversionFormat variable that will store the flag value +// - bindViper: If true, binds the flag to viper for configuration file support. +// Set to true for commands that use viper for configuration (e.g., watch command), +// and false for commands that don't (e.g., optimize command). func setupFormatFlag(cmd *cobra.Command, converterType *constant.ConversionFormat, bindViper bool) { formatFlag := enumflag.New(converterType, "format", constant.CommandValue, enumflag.EnumCaseInsensitive) _ = formatFlag.RegisterCompletion(cmd, "format", constant.HelpText) diff --git a/cmd/cbzoptimizer/commands/optimize_command_test.go b/cmd/cbzoptimizer/commands/optimize_command_test.go index a01a520..65e92ef 100644 --- a/cmd/cbzoptimizer/commands/optimize_command_test.go +++ b/cmd/cbzoptimizer/commands/optimize_command_test.go @@ -173,7 +173,12 @@ func TestConvertCbzCommand(t *testing.T) { t.Logf("Found %d converted files", len(convertedFiles)) } -// setupTestCommand creates a test command with all required flags +// setupTestCommand creates a test command with all required flags for testing. +// It mocks the converter.Get function and sets up a complete command with all flags. +// +// Returns: +// - *cobra.Command: A configured command ready for testing +// - func(): A cleanup function that must be deferred to restore the original converter.Get func setupTestCommand(t *testing.T) (*cobra.Command, func()) { t.Helper() @@ -194,8 +199,8 @@ func setupTestCommand(t *testing.T) (*cobra.Command, func()) { cmd.Flags().BoolP("split", "s", false, "Split long pages into smaller chunks") cmd.Flags().DurationP("timeout", "t", 0, "Maximum time allowed for converting a single chapter") - // Reset converterType to default before test - converterType = constant.WebP + // Reset converterType to default before test for consistency + converterType = constant.DefaultConversion setupFormatFlag(cmd, &converterType, false) return cmd, cleanup