diff --git a/cmd/cp.go b/cmd/cp.go index 1b47c24..0ada74f 100644 --- a/cmd/cp.go +++ b/cmd/cp.go @@ -19,6 +19,7 @@ func NewCpCommand() *cobra.Command { } cmd.Flags().BoolP("with-metadata", "m", false, "Include file metadata in hash calculation") + cmd.Flags().BoolP("verbose", "v", false, "Verbose output") return cmd } @@ -26,6 +27,7 @@ func NewCpCommand() *cobra.Command { func cpCommand(cmd *cobra.Command, args []string) { source, dest, storagePath := args[0], args[1], args[2] withMetadata, _ := cmd.Flags().GetBool("with-metadata") + verbose, _ := cmd.Flags().GetBool("verbose") // Create storage storageOpts := storage.StorageOptions{ @@ -45,7 +47,7 @@ func cpCommand(cmd *cobra.Command, args []string) { // Run the processor log.Printf("Copying %s to %s..", source, dest) - d := dabadee.NewDaBaDee(processor) + d := dabadee.NewDaBaDee(processor, verbose) if err := d.Run(); err != nil { log.Fatalf("Error during copy and link: %v", err) } diff --git a/cmd/dedup.go b/cmd/dedup.go index f7d2558..91b3f27 100644 --- a/cmd/dedup.go +++ b/cmd/dedup.go @@ -20,6 +20,7 @@ func NewDedupCommand() *cobra.Command { } cmd.Flags().BoolP("with-metadata", "m", false, "Include file metadata in hash calculation") + cmd.Flags().BoolP("verbose", "v", false, "Verbose output") return cmd } @@ -27,6 +28,7 @@ func NewDedupCommand() *cobra.Command { func dedupCommand(cmd *cobra.Command, args []string) { source, storagePath, workersStr := args[0], args[1], args[2] withMetadata, _ := cmd.Flags().GetBool("with-metadata") + verbose, _ := cmd.Flags().GetBool("verbose") workers, err := strconv.Atoi(workersStr) if err != nil { log.Fatalf("Invalid number of workers: %v", err) @@ -50,7 +52,7 @@ func dedupCommand(cmd *cobra.Command, args []string) { // Run the processor log.Printf("Deduplicating %s..", source) - d := dabadee.NewDaBaDee(processor) + d := dabadee.NewDaBaDee(processor, verbose) if err := d.Run(); err != nil { log.Fatalf("Error during deduplication: %v", err) } diff --git a/pkg/dabadee/dabadee.go b/pkg/dabadee/dabadee.go index 10105a1..cc9f235 100644 --- a/pkg/dabadee/dabadee.go +++ b/pkg/dabadee/dabadee.go @@ -4,14 +4,18 @@ import "github.com/mirkobrombin/dabadee/pkg/processor" type DaBaDee struct { Processor processor.Processor + Verbose bool } // NewDaBaDee creates a new DaBaDee orchestrator with the given processor -func NewDaBaDee(p processor.Processor) *DaBaDee { - return &DaBaDee{Processor: p} +func NewDaBaDee(p processor.Processor, verbose bool) *DaBaDee { + return &DaBaDee{ + Processor: p, + Verbose: verbose, + } } // Run starts the given processor func (d *DaBaDee) Run() error { - return d.Processor.Process() + return d.Processor.Process(d.Verbose) } diff --git a/pkg/processor/cp.go b/pkg/processor/cp.go index ac95509..29115d5 100644 --- a/pkg/processor/cp.go +++ b/pkg/processor/cp.go @@ -37,7 +37,7 @@ func NewCpProcessor(sourceFile, destFile string, storage *storage.Storage, hashG } // Process processes the file and creates a link at the destination -func (p *CpProcessor) Process() (err error) { +func (p *CpProcessor) Process(verbose bool) (err error) { // Compute file hash var finalHash string diff --git a/pkg/processor/dedup.go b/pkg/processor/dedup.go index c7caa5a..e39334e 100644 --- a/pkg/processor/dedup.go +++ b/pkg/processor/dedup.go @@ -79,7 +79,7 @@ func finishProcessing(hash string) { } // Process processes the files in the source directory -func (p *DedupProcessor) Process() error { +func (p *DedupProcessor) Process(verbose bool) error { jobs := make(chan string, p.Workers) var wg sync.WaitGroup @@ -91,7 +91,9 @@ func (p *DedupProcessor) Process() error { for path := range jobs { err := p.processFile(path) if err != nil { - log.Printf("Error processing file %s: %v", path, err) + if verbose { + log.Printf("Error processing file %s: %v", path, err) + } } } }() diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index f60c88e..166b374 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -3,5 +3,5 @@ package processor // Processor defines the core processing logic, implement this to add new // functionalities that can be orchestrated by DaBaDee type Processor interface { - Process() error + Process(verbose bool) error } diff --git a/tests/cp_test.go b/tests/cp_test.go index 7482a63..1443839 100644 --- a/tests/cp_test.go +++ b/tests/cp_test.go @@ -49,7 +49,7 @@ func TestCpCommand(t *testing.T) { h, ) - d := dabadee.NewDaBaDee(cpProcessor) + d := dabadee.NewDaBaDee(cpProcessor, true) // Run the command err = d.Run() diff --git a/tests/dedup_test.go b/tests/dedup_test.go index 2794d5a..572da08 100644 --- a/tests/dedup_test.go +++ b/tests/dedup_test.go @@ -53,7 +53,7 @@ func TestDedupCommand(t *testing.T) { processor := processor.NewDedupProcessor(testPath, s, h, 1) - d := dabadee.NewDaBaDee(processor) + d := dabadee.NewDaBaDee(processor, true) // Run the deduplication err = d.Run()