Skip to content

Commit

Permalink
Add auto-update enable/disable config
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevsaddam committed Nov 3, 2021
1 parent 1e4bf83 commit ca3f64d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

var (
path string
subPath string
path string
subPath string
autoUpdate string

cmdConfig = &cobra.Command{
Use: "config",
Expand All @@ -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)
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ca3f64d

Please sign in to comment.