Skip to content

Commit 3d5fd18

Browse files
authored
Feat/overwrite category via cmdline (#18)
* feat(validate): Overwrite category * fix(validate): Recursive mode with overwrite includes all dirs instead of filtering
1 parent 7719d57 commit 3d5fd18

4 files changed

Lines changed: 51 additions & 24 deletions

File tree

cmd/validate.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
)
1010

1111
var (
12-
validatePresetPath string
13-
validateVerbose bool
14-
validateQuiet bool
15-
validateRecursive bool
12+
validatePresetPath string
13+
validateVerbose bool
14+
validateQuiet bool
15+
validateRecursive bool
16+
validateOverwriteCategory string
1617
)
1718

1819
var validateCmd = &cobra.Command{
@@ -26,6 +27,9 @@ the folder contents against the rules defined in the preset configuration file.
2627
When the recursive option (-r) is used, the command will search for valid
2728
release folders in all subdirectories of the specified folder(s).
2829
30+
The --overwrite flag allows you to bypass automatic category detection and
31+
manually specify a category for validation.
32+
2933
Examples:
3034
# Validate a single folder
3135
sfvbrr validate /path/to/release
@@ -34,14 +38,18 @@ Examples:
3438
sfvbrr validate /path/to/release1 /path/to/release2
3539
3640
# Validate recursively
37-
sfvbrr validate -r /path/to/releases`,
41+
sfvbrr validate -r /path/to/releases
42+
43+
# Override category detection
44+
sfvbrr validate --overwrite app /path/to/release`,
3845
Args: cobra.MinimumNArgs(1),
3946
Run: func(cmd *cobra.Command, args []string) {
4047
opts := validate.Options{
41-
PresetPath: validatePresetPath,
42-
Verbose: validateVerbose,
43-
Quiet: validateQuiet,
44-
Recursive: validateRecursive,
48+
PresetPath: validatePresetPath,
49+
Verbose: validateVerbose,
50+
Quiet: validateQuiet,
51+
Recursive: validateRecursive,
52+
OverwriteCategory: validateOverwriteCategory,
4553
}
4654

4755
if err := validate.ValidateFolders(args, opts); err != nil {
@@ -58,4 +66,5 @@ func init() {
5866
validateCmd.Flags().BoolVarP(&validateVerbose, "verbose", "v", false, "Show detailed validation results for each rule")
5967
validateCmd.Flags().BoolVarP(&validateQuiet, "quiet", "q", false, "Quiet mode - only show errors")
6068
validateCmd.Flags().BoolVarP(&validateRecursive, "recursive", "r", false, "Recursively search for release folders in subdirectories")
69+
validateCmd.Flags().StringVar(&validateOverwriteCategory, "overwrite", "", "Override category detection with specified category (bypasses automatic detection)")
6170
}

internal/validate/batch.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010

1111
// FindFoldersRecursive finds all folders recursively in the given directory
1212
// that can be validated (i.e., have a detectable category)
13-
func FindFoldersRecursive(dir string) ([]string, error) {
13+
// Note: overwriteCategory parameter is kept for API compatibility but not used here.
14+
// The overwrite category is applied during validation, not during folder discovery.
15+
func FindFoldersRecursive(dir string, overwriteCategory string) ([]string, error) {
1416
var folders []string
1517

1618
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
@@ -20,8 +22,9 @@ func FindFoldersRecursive(dir string) ([]string, error) {
2022
}
2123

2224
if info.IsDir() {
23-
// Try to detect category for this folder
24-
category, err := DetectCategory(path)
25+
// Always try to detect category for this folder to filter for valid releases
26+
// The overwrite category will be applied later during validation
27+
category, err := DetectCategory(path, "")
2528
if err == nil && category != "" {
2629
folders = append(folders, path)
2730
}
@@ -39,8 +42,8 @@ func FindFoldersRecursive(dir string) ([]string, error) {
3942

4043
// validateSingleFolder validates a single folder and displays results
4144
func validateSingleFolder(folderPath string, presetConfig *preset.PresetConfig, opts Options) (bool, error) {
42-
// Detect category
43-
category, err := DetectCategory(folderPath)
45+
// Detect category (or use overwrite if provided)
46+
category, err := DetectCategory(folderPath, opts.OverwriteCategory)
4447
if err != nil {
4548
return false, fmt.Errorf("failed to detect category for %s: %w", folderPath, err)
4649
}
@@ -72,6 +75,13 @@ func ValidateFolders(folders []string, opts Options) error {
7275
return fmt.Errorf("failed to load presets: %w", err)
7376
}
7477

78+
// Validate overwrite category if provided
79+
if opts.OverwriteCategory != "" {
80+
if _, exists := presetConfig.Rules[opts.OverwriteCategory]; !exists {
81+
return fmt.Errorf("invalid category '%s': category not found in preset configuration", opts.OverwriteCategory)
82+
}
83+
}
84+
7585
var hasErrors bool
7686

7787
for _, folder := range folders {
@@ -99,7 +109,7 @@ func ValidateFolders(folders []string, opts Options) error {
99109

100110
if opts.Recursive {
101111
// Find all folders recursively
102-
subFolders, err := FindFoldersRecursive(absPath)
112+
subFolders, err := FindFoldersRecursive(absPath, opts.OverwriteCategory)
103113
if err != nil {
104114
fmt.Fprintf(os.Stderr, "Error: failed to find folders recursively in %s: %v\n", folder, err)
105115
hasErrors = true

internal/validate/categories.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import (
88
)
99

1010
// DetectCategory detects the release category from a folder path
11-
func DetectCategory(folderPath string) (string, error) {
11+
// If overwriteCategory is provided and non-empty, it will be returned instead of detecting
12+
func DetectCategory(folderPath string, overwriteCategory string) (string, error) {
13+
// If overwrite category is provided, use it directly
14+
if overwriteCategory != "" {
15+
return overwriteCategory, nil
16+
}
17+
1218
// Extract folder name from path
1319
folderName := filepath.Base(folderPath)
1420

internal/validate/types.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ type ValidationResult struct {
2121

2222
// Options contains configuration options for validation
2323
type Options struct {
24-
PresetPath string // Path to preset YAML file (empty = auto-detect)
25-
Verbose bool // Verbose output
26-
Quiet bool // Quiet mode (minimal output)
27-
Recursive bool // Recursive mode - search subdirectories
24+
PresetPath string // Path to preset YAML file (empty = auto-detect)
25+
Verbose bool // Verbose output
26+
Quiet bool // Quiet mode (minimal output)
27+
Recursive bool // Recursive mode - search subdirectories
28+
OverwriteCategory string // Override category detection (empty = use auto-detection)
2829
}
2930

3031
// DefaultOptions returns default options for validation
3132
func DefaultOptions() Options {
3233
return Options{
33-
PresetPath: "",
34-
Verbose: false,
35-
Quiet: false,
36-
Recursive: false,
34+
PresetPath: "",
35+
Verbose: false,
36+
Quiet: false,
37+
Recursive: false,
38+
OverwriteCategory: "",
3739
}
3840
}
3941

0 commit comments

Comments
 (0)