diff --git a/features/execute.feature b/features/execute.feature index d8271585..ba04ce0e 100644 --- a/features/execute.feature +++ b/features/execute.feature @@ -5,11 +5,32 @@ Feature: execute Given a basic setup with a puppet module "puppet-test" from "awesome" Then the file "modules/awesome/puppet-test/metadata.json" should not exist When I successfully run `msync exec --verbose /bin/true` - Then the output should contain "Cloning from 'file://" + Then the stdout should contain "Cloning from 'file://" And the file "modules/awesome/puppet-test/metadata.json" should exist @no-clobber Scenario: No clones before running command when sourcecode have already been cloned Then the file "modules/awesome/puppet-test/metadata.json" should exist When I successfully run `msync exec --verbose /bin/true` - Then the output should not contain "Cloning from 'file://" + Then the stdout should not contain "Cloning from 'file://" + + Scenario: When command run fails, abort expect --no-fail-fast + + @wip + Scenario: Show fail-fast default value in help + When I successfully run `msync help exec` + Then the stdout should contain: + """ + [--fail-fast], [--no-fail-fast] # Abort the run after a command execution failure + # Default: true + """ + + @wip + Scenario: Override fail-fast default value using config file + Given the global option "fail_fast" sets to "false" + When I successfully run `msync help exec` + Then the stdout should contain: + """ + [--fail-fast], [--no-fail-fast] # Abort the run after a command execution failure + """ + # NOTE: It seems there is a Thor bug here: default value is missing in help when sets to 'false' diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 5c130faa..f740ce76 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -190,6 +190,7 @@ def self.clone(cli_options) def self.execute(cli_options) @options = config_defaults.merge(cli_options) + errors = {} managed_modules.each do |puppet_module| $stdout.puts "#{puppet_module.given_name}:" @@ -206,13 +207,24 @@ def self.execute(cli_options) FileUtils.chdir(puppet_module.working_directory) do result = system command_env, *command_args, unsetenv_others: true unless result - raise Thor::Error, - "Error during script execution ('#{@options[:command_args].join ' '}': #{$CHILD_STATUS})" + message = "Command execution failed ('#{@options[:command_args].join ' '}': #{$CHILD_STATUS})" + raise Thor::Error, message if @options[:fail_fast] + + errors.merge( + puppet_module.given_name => message + ) + $stderr.puts message end end $stdout.puts '' end + + errors.each do |name, message| + puts "#{name}: #{message}" + end + + exit 1 unless errors.empty? end def self.reset(cli_options) diff --git a/lib/modulesync/cli.rb b/lib/modulesync/cli.rb index 3ba5c090..fbf21a9a 100644 --- a/lib/modulesync/cli.rb +++ b/lib/modulesync/cli.rb @@ -38,7 +38,7 @@ class Base < Thor class_option :project_root, :aliases => '-c', :desc => 'Path used by git to clone modules into.', - :default => CLI.defaults[:project_root] || 'modules' + :default => CLI.defaults[:project_root] class_option :git_base, :desc => 'Specify the base part of a git URL to pull from', :default => CLI.defaults[:git_base] || 'git@github.com:' @@ -148,7 +148,29 @@ def update ModuleSync.update(config) end - desc 'execute COMMAND', 'Execute the command in each managed modules' + no_commands do + def merge_options(command, cli_options, **more_options) + options = CLI.defaults + puts "DEFAULTS" + pp options + # options.merge!(options[command.to_sym]) unless options[command.to_sym].nil? + # puts "DEFAULTS + COMMAND-DEFAULT" + # pp options + options.merge! Util.symbolize_keys cli_options + puts "DEFAULTS + COMMAND-DEFAULT + CLI" + pp options + options.merge! more_options + puts "DEFAULTS + COMMAND-DEFAULT + CLI + MORE OPTIONS" + pp options + options.merge! command: command # TODO Remove this + puts "DEFAULTS + COMMAND-DEFAULT + CLI + MORE OPTIONS + COMMAND NAME" + pp options + + Util.symbolize_keys options + end + end + + desc 'execute [OPTIONS] -- COMMAND..', 'Execute the command in each managed modules' option :configs, :aliases => '-c', :desc => 'The local directory or remote repository to define the list of managed modules,' \ @@ -159,14 +181,13 @@ def update :aliases => '-b', :desc => 'Branch name to make the changes in.', :default => CLI.defaults[:branch] - + option :fail_fast, + :type => :boolean, + :desc => 'Abort the run after a command execution failure', + :default => CLI.defaults[:fail_fast].nil? ? true : CLI.defaults[:fail_fast] def execute(*command_args) - config = { - :command => 'execute', - :command_args => command_args, - }.merge(options) - config = Util.symbolize_keys(config) - ModuleSync.execute(config) + #raise unless ARGV.include? '--' + ModuleSync.execute merge_options('execute', options, command_args: command_args) end desc 'reset', 'Reset all repositories'