diff --git a/cmd/config.go b/cmd/config.go index 4237066..aeabfa2 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -12,8 +12,9 @@ import ( ) var ( - path string - subPath string + path string + subPath string + autoUpdate string cmdConfig = &cobra.Command{ Use: "config", @@ -28,6 +29,7 @@ func init() { cmdConfig.Flags().StringVarP(&subPath, "subpath", "s", "", "sub directory map in this format subdirectoryName:.ext1,.ext2. e.g: video:.mp4,.mkv") cmdConfig.Flags().IntVarP(&concurrent, "concurrent", "c", 0, "number of concurrent process will be running, default: 5") cmdConfig.Flags().BoolVarP(&debug, "debug", "d", false, "display configuration") + cmdConfig.Flags().StringVarP(&autoUpdate, "auto-update", "a", "", "enable/disable auto-update. e.g: -a true, -a false") cmdDL.AddCommand(cmdConfig) } @@ -41,7 +43,14 @@ func setConfig(cmd *cobra.Command, args []string) { path = dir } + oldCfg := config.DefaultConfig() newCfg := config.Config{Directory: path, Concurrency: uint(concurrent)} + newCfg.AutoUpdate = oldCfg.AutoUpdate + if autoUpdate == "true" { + newCfg.AutoUpdate = true + } else if autoUpdate == "false" { + newCfg.AutoUpdate = false + } if subPath != "" { newCfg.SubDirMap = config.DefaultConfig().SubDirMap // assign old config diff --git a/cmd/dl.go b/cmd/dl.go index 2c21dc2..1d7f1c5 100644 --- a/cmd/dl.go +++ b/cmd/dl.go @@ -79,7 +79,7 @@ func initConfig() { func startDownload(cmd *cobra.Command, args []string) { cfg := config.DefaultConfig() - if cfg.AudoUpdate { + if cfg.AutoUpdate { err := update.SelfUpdate(context.Background(), BuildDate, Version) if err != nil { fmt.Println("Error: failed to update dl:", err) //this error can be skipped diff --git a/config/config.go b/config/config.go index 201d82f..4b2429d 100644 --- a/config/config.go +++ b/config/config.go @@ -21,7 +21,7 @@ var ( // Config represent configurations for the download manager type Config struct { - AudoUpdate bool `json:"auto_update"` + AutoUpdate bool `json:"auto_update"` Directory string `json:"directory"` Concurrency uint `json:"concurrency"` SubDirMap values.MapStrSliceString `json:"sub_dir_map"` @@ -65,7 +65,7 @@ func LoadDefaultConfig() error { ".odt", ".pdf", ".rtf", ".tex", ".txt", ".wpd", ".md"} CreateConfig(Config{ - AudoUpdate: true, + AutoUpdate: true, Concurrency: 5, Directory: "", SubDirMap: subDir, @@ -113,6 +113,8 @@ func SetConfig(c Config) error { oldCfg.Directory = c.Directory } + oldCfg.AutoUpdate = c.AutoUpdate + for k, extensions := range c.SubDirMap { for _, e := range extensions { oldCfg.SubDirMap.Add(k, e)