From 9366c4a9c6d59dd0fccad12fbc413842ea751fa6 Mon Sep 17 00:00:00 2001 From: Arctic Ice Studio Date: Mon, 15 Jul 2019 14:15:57 +0200 Subject: [PATCH] Pass individual snowblock paths as arguments instead of flag values 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 --- cmd/snowsaw/bootstrap/bootstrap.go | 15 +++++++-------- pkg/snowblock/snowblock.go | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/snowsaw/bootstrap/bootstrap.go b/cmd/snowsaw/bootstrap/bootstrap.go index faf137d..366865e 100644 --- a/cmd/snowsaw/bootstrap/bootstrap.go +++ b/cmd/snowsaw/bootstrap/bootstrap.go @@ -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 { diff --git a/pkg/snowblock/snowblock.go b/pkg/snowblock/snowblock.go index 97a6b04..95378ba 100644 --- a/pkg/snowblock/snowblock.go +++ b/pkg/snowblock/snowblock.go @@ -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 }