root.go.bak3
1 // Package cmd implements the command-line interface for KeepSync 2 package cmd 3 4 import ( 5 "keepSync/internal/adapter" 6 "keepSync/internal/logging" 7 "keepSync/internal/provider" 8 "keepSync/internal/services" 9 10 "keepSync/cmd/keepsync/cmd/advanced" 11 "keepSync/cmd/keepsync/cmd/security" 12 "keepSync/cmd/keepsync/cmd/version" 13 14 "github.com/spf13/cobra" 15 ) 16 17 var ( 18 // Global flags 19 verbose bool 20 configFile string 21 22 // Commands 23 initCmd *cobra.Command 24 syncCmd *cobra.Command 25 26 // Provider factory 27 providerFactory *provider.Factory 28 29 // Provider factory adapter 30 providerFactoryAdapter services.ProviderFactoryInterface 31 32 // Logger 33 logger logging.Logger 34 ) 35 36 // rootCmd represents the base command when called without any subcommands 37 var rootCmd = &cobra.Command{ 38 Use: "keepsync", 39 Short: "KeepSync secure cloud synchronization tool", 40 Long: `KeepSync is a secure file synchronization tool that supports 41 multiple cloud providers and advanced security features including 42 TPM-based security, quantum-resistant encryption, and key revocation.`, 43 } 44 45 // Execute adds all child commands to the root command and sets flags appropriately. 46 // This is called by main.main(). It only needs to happen once to the rootCmd. 47 func Execute() error { 48 return rootCmd.Execute() 49 } 50 51 func init() { 52 // Create logger 53 logger = logging.GetLogger("keepsync") 54 55 // Create provider factory 56 providerFactory = provider.NewFactory(logger) 57 58 // Register S3 provider 59 provider.RegisterFactory("s3", providerFactory) 60 61 // Register WebDAV provider 62 provider.RegisterFactory("webdav", providerFactory) 63 64 // Register SFTP provider 65 provider.RegisterFactory("sftp", providerFactory) 66 67 // Create provider factory adapter 68 providerFactoryAdapter = adapter.NewProviderFactoryAdapter(providerFactory) 69 70 // Initialize commands 71 initCmd = InitializeInitCommand(logger, providerFactoryAdapter) 72 syncCmd = InitializeSyncCommand(logger, providerFactoryAdapter) 73 74 // Add global flags 75 rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output") 76 rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file (default is $HOME/.keepsync/config.json)") 77 78 // Add commands 79 rootCmd.AddCommand(initCmd) 80 rootCmd.AddCommand(syncCmd) 81 rootCmd.AddCommand(security.NewSecurityCommand()) 82 rootCmd.AddCommand(advanced.NewAdvancedCommand()) 83 rootCmd.AddCommand(version.NewVersionCommand()) 84 }