Skip to content

Commit

Permalink
Pass individual snowblock paths as arguments instead of flag values
Browse files Browse the repository at this point in the history
To simplify the CLI usage and removing the requirement to pass correctly
formatted (comma-separated) values to the `--snowblocks`/`-s` flag (1)
to process individual snowblocks the `bootstrap` command now accepts one
or more space-separated snowblock directory paths.

References:
  (1) https://github.com/arcticicestudio/snowsaw/blob/145a4c36caf960fc9a43b16c105df997e819a04d/cmd/snowsaw/bootstrap/bootstrap.go#L46

Epic: GH-33
Resolves GH-78
  • Loading branch information
arcticicestudio committed Jul 15, 2019
1 parent ed6226d commit 9366c4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions cmd/snowsaw/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,30 @@ func NewBootstrapCmd() *cobra.Command {
bootstrapCmd := &cobra.Command{
Use: "bootstrap",
Short: "Bootstraps all configured snowblocks",
Long: `Bootstraps all configured snowblocks
To process individual snowblocks a list of space-separated paths can be passed as arguments.
`,
Run: func(cmd *cobra.Command, args []string) {
o.prepare(cmd, args)
o.run(cmd, args)
},
}

bootstrapCmd.Flags().StringSliceVarP(
&o.SnowblockPaths, "snowblocks", "s", []string{}, "comma-separated paths to individual snowblock directories")

return bootstrapCmd
}

func (o *cmdOptions) prepare(cmd *cobra.Command, args []string) {
// Use explicit snowblocks if specified, otherwise find all snowblocks within the base directories.
if len(o.SnowblockPaths) > 0 {
if len(args) > 0 {
prt.Debugf("Using individual snowblocks instead of configured base directories(s): %s",
color.CyanString("%v", o.SnowblockPaths))
config.AppConfig.Snowblocks.Paths = o.SnowblockPaths
color.CyanString("%v", args))
config.AppConfig.Snowblocks.Paths = args
} else {
if err := o.readSnowblockDirectories(); err != nil {
prt.Errorf("Failed to read snowblocks from base directories: %v", err)
os.Exit(1)
}
o.SnowblockPaths = config.AppConfig.Snowblocks.Paths
}
o.SnowblockPaths = config.AppConfig.Snowblocks.Paths
}

func (o *cmdOptions) readSnowblockDirectories() error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/snowblock/snowblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (s *Snowblock) Validate(taskRunner map[string]api.TaskRunner) error {
// Try to read and encode the task objects when the directory contains a configuration file.
configFilePath := filepath.Join(s.Path, fmt.Sprintf("%s.%s", api.ConfigurationFileName, encoder.ExtensionsJson))
if configLoadErr := loadConfigFile(configFilePath, &s.TaskObjects); configLoadErr != nil {
prt.Debugf("Ignoring snowblock directory %s without valid configuration file: %s: %v",
color.CyanString(filepath.Base(s.Path)), color.BlueString(configFilePath), configLoadErr)
prt.Debugf("Ignoring snowblock directory %s: %v",
color.CyanString(filepath.Base(s.Path)), configLoadErr)
return nil
}

Expand Down

0 comments on commit 9366c4a

Please sign in to comment.