Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
cmd/plg: create "scan" command to set targets
Browse files Browse the repository at this point in the history
While testing Pilgo as a user, I found it very bad UX-wise to have
target options reset whenever I needed to rescan a directory.

This commit splits "config" into two commands, "config" itself and
"scan". Each command now uses a mode when setting a configuration, so
"config" preserves all targets from a given configuration but still
overwrites all other properties, while "scan" only resets targets, not
other properties.
  • Loading branch information
gbrlsnchs committed May 1, 2020
1 parent 7d4a307 commit 73f6141
Show file tree
Hide file tree
Showing 17 changed files with 1,254 additions and 890 deletions.
30 changes: 1 addition & 29 deletions cmd/plg/config.go
Expand Up @@ -16,8 +16,6 @@ type configCmd struct {
link string
useHome boolptr
flatten bool
scanDir bool
read readMode
tags cliutil.CommaSepOptionList
}

Expand All @@ -30,28 +28,18 @@ func (cmd *configCmd) register(getcfg func() appConfig) func(cli.Program) error
if err != nil {
return err
}
var targets []string
if cmd.scanDir {
files, err := fs.ReadDir(cmd.file)
if err != nil {
return err
}
cmd.read.exclude.Set(conf)
targets = cmd.read.resolve(files)
}
var c config.Config
if err := yaml.Unmarshal(b, &c); err != nil {
return err
}
cc := &config.Config{
Targets: targets,
BaseDir: cmd.baseDir,
Link: cmd.link,
Flatten: cmd.flatten,
UseHome: cmd.useHome.addr,
Tags: cmd.tags,
}
c.Set(cmd.file, cc)
c.Set(cmd.file, cc, config.ModeConfig)
if b, err = marshalYAML(c); err != nil {
return err
}
Expand All @@ -63,22 +51,6 @@ func (cmd *configCmd) register(getcfg func() appConfig) func(cli.Program) error
}
}

type strptr struct {
addr *string
}

func (sp *strptr) Set(value string) error {
sp.addr = &value
return nil
}

func (sp strptr) String() string {
if sp.addr == nil {
return ""
}
return *sp.addr
}

type boolptr struct {
addr *bool
}
Expand Down

0 comments on commit 73f6141

Please sign in to comment.