Refactoring, fix bug

This commit is contained in:
2025-01-07 03:53:28 +03:00
parent e1670934a1
commit 56e826e580
2 changed files with 5 additions and 3 deletions

View File

@@ -14,6 +14,8 @@ const (
ModeMove Mode = "move" ModeMove Mode = "move"
) )
var supportedModes = []Mode{ModeHardlink, ModeSymlink, ModeMove, ModeCopy}
type Config struct { type Config struct {
SourceDir string SourceDir string
TargetDir string TargetDir string
@@ -34,8 +36,8 @@ func (c *Config) Validate() error {
return fmt.Errorf("target dir is required") return fmt.Errorf("target dir is required")
} }
if !slices.Contains([]Mode{ModeHardlink, ModeSymlink, ModeMove, ModeCopy}, c.Mode) { if !slices.Contains(supportedModes, c.Mode) {
return fmt.Errorf("invalid mode %s", c.Mode) return fmt.Errorf("invalid mode %s, supported modes: %s", c.Mode, supportedModes)
} }
if c.SkipFullSync && !c.Watch { if c.SkipFullSync && !c.Watch {

View File

@@ -38,7 +38,7 @@ func loadCfg() application.Config {
flag.StringVar(&cfg.SourceDir, "source", "", "Source directory") flag.StringVar(&cfg.SourceDir, "source", "", "Source directory")
flag.StringVar(&cfg.TargetDir, "target", "", "Target directory") flag.StringVar(&cfg.TargetDir, "target", "", "Target directory")
flag.BoolVar(&cfg.Overwrite, "overwrite", false, "Overwrite existing files") flag.BoolVar(&cfg.Overwrite, "overwrite", false, "Overwrite existing files")
flag.BoolVar(&cfg.Watch, "watch", true, "Watch for changes in the source directory") flag.BoolVar(&cfg.Watch, "watch", false, "Watch for changes in the source directory")
flag.BoolVar(&cfg.SkipFullSync, "skip-full-sync", false, "Skip full sync at startup") flag.BoolVar(&cfg.SkipFullSync, "skip-full-sync", false, "Skip full sync at startup")
var ( var (