@@ -13,32 +13,10 @@ import (
1313)
1414
1515/**************************************************************************************************
16- ** Application entry point. Sets up the CLI command structure using Cobra, including all
17- ** available commands and their associated flags. Handles command execution and error
18- ** reporting.
16+ ** bindFlags adds all persistent flags to the root command. This shared function eliminates
17+ ** duplication between CreateRootCommand and CreateTestableRootCommand.
1918**************************************************************************************************/
20- func main () {
21- var rootCmd = & cobra.Command {
22- Use : "immich-stack" ,
23- Short : "Immich Stack CLI" ,
24- Long : "A tool to automatically stack Immich assets." ,
25- Run : runStacker ,
26- }
27-
28- var duplicatesCmd = & cobra.Command {
29- Use : "duplicates" ,
30- Short : "List duplicate assets" ,
31- Long : "Scan your Immich library and list duplicate assets based on filename and timestamp." ,
32- Run : runDuplicates ,
33- }
34-
35- var fixTrashCmd = & cobra.Command {
36- Use : "fix-trash" ,
37- Short : "Fix incomplete stack trash operations" ,
38- Long : "Scan trash for assets and move related stack members to trash to maintain consistency." ,
39- Run : runFixTrash ,
40- }
41-
19+ func bindFlags (rootCmd * cobra.Command ) {
4220 rootCmd .PersistentFlags ().StringVar (& apiKey , "api-key" , "" , "API key (or set API_KEY env var)" )
4321 rootCmd .PersistentFlags ().StringVar (& apiURL , "api-url" , "" , "API URL (or set API_URL env var)" )
4422 rootCmd .PersistentFlags ().BoolVar (& resetStacks , "reset-stacks" , false , "Delete all existing stacks (or set RESET_STACKS=true)" )
@@ -53,10 +31,54 @@ func main() {
5331 rootCmd .PersistentFlags ().IntVar (& cronInterval , "cron-interval" , 0 , "Cron interval (or set CRON_INTERVAL env var)" )
5432 rootCmd .PersistentFlags ().StringVar (& logLevel , "log-level" , "" , "Log level: debug, info, warn, error (or set LOG_LEVEL env var)" )
5533 rootCmd .PersistentFlags ().BoolVar (& removeSingleAssetStacks , "remove-single-asset-stacks" , false , "Remove stacks with only one asset (or set REMOVE_SINGLE_ASSET_STACKS=true)" )
34+ }
35+
36+ /**************************************************************************************************
37+ ** addSubcommands adds all subcommands to the root command with their run functions.
38+ **************************************************************************************************/
39+ func addSubcommands (rootCmd * cobra.Command ) {
40+ var duplicatesCmd = & cobra.Command {
41+ Use : "duplicates" ,
42+ Short : "List duplicate assets" ,
43+ Long : "Scan your Immich library and list duplicate assets based on filename and timestamp." ,
44+ Run : runDuplicates ,
45+ }
46+
47+ var fixTrashCmd = & cobra.Command {
48+ Use : "fix-trash" ,
49+ Short : "Fix incomplete stack trash operations" ,
50+ Long : "Scan trash for assets and move related stack members to trash to maintain consistency." ,
51+ Run : runFixTrash ,
52+ }
5653
5754 rootCmd .AddCommand (duplicatesCmd )
5855 rootCmd .AddCommand (fixTrashCmd )
56+ }
57+
58+ /**************************************************************************************************
59+ ** CreateRootCommand creates and returns the root command with all subcommands and flags.
60+ ** This is exported to allow testing of the real command structure.
61+ **************************************************************************************************/
62+ func CreateRootCommand () * cobra.Command {
63+ var rootCmd = & cobra.Command {
64+ Use : "immich-stack" ,
65+ Short : "Immich Stack CLI" ,
66+ Long : "A tool to automatically stack Immich assets." ,
67+ Run : runStacker ,
68+ }
5969
70+ bindFlags (rootCmd )
71+ addSubcommands (rootCmd )
72+ return rootCmd
73+ }
74+
75+ /**************************************************************************************************
76+ ** Application entry point. Sets up the CLI command structure using Cobra, including all
77+ ** available commands and their associated flags. Handles command execution and error
78+ ** reporting.
79+ **************************************************************************************************/
80+ func main () {
81+ rootCmd := CreateRootCommand ()
6082 if err := rootCmd .Execute (); err != nil {
6183 os .Exit (1 )
6284 }
0 commit comments