lib/backticks/runner.rb in backticks-0.3.1 vs lib/backticks/runner.rb in backticks-0.4.0
- old
+ new
@@ -31,16 +31,28 @@
# @return [#parameters] the CLI-translation object used by this runner
attr_reader :cli
# Create an instance of Runner.
# @param [#parameters] cli object used to convert Ruby method parameters into command-line parameters
- def initialize(buffered:false, cli:Backticks::CLI::Getopt, interactive:false)
- @buffered = buffered
- @cli = cli
- @interactive = interactive
+ def initialize(options={})
+ options = {
+ :buffered => false,
+ :cli => Backticks::CLI::Getopt,
+ :interactive => false,
+ }.merge(options)
+
+ @buffered = options[:buffered]
+ @cli = options[:cli]
+ @interactive = options[:interactive]
end
+ # @deprecated
+ def command(*sugar)
+ warn 'Backticks::Runner#command is deprecated; please call #run instead'
+ run(*sugar)
+ end
+
# Run a command whose parameters are expressed using some Rubyish sugar.
# This method accepts an arbitrary number of positional parameters; each
# parameter can be a Hash, an array, or a simple Object. Arrays and simple
# objects are appended to argv as words of the command; Hashes are
# translated to command-line options and then appended to argv.
@@ -48,18 +60,26 @@
# Hashes are processed by @cli, defaulting to Backticks::CLI::Getopt and
# easily overridden by passing the `cli` option to #initialize.
#
# @see Backticks::CLI::Getopt for option-Hash format information
#
- # @param [Array] args list of command words and options
+ # @param [Array] sugar list of command words and options
#
# @return [Command] the running command
#
# @example Run docker-compose with complex parameters
- # command('docker-compose', {file: 'joe.yml'}, 'up', {d:true}, 'mysvc')
- def command(*args)
- argv = @cli.parameters(*args)
+ # run('docker-compose', {file: 'joe.yml'}, 'up', {d:true}, 'mysvc')
+ def run(*sugar)
+ run_without_sugar(@cli.parameters(*sugar))
+ end
+ # Run a command whose argv is specified in the same manner as Kernel#exec,
+ # with no Rubyish sugar.
+ #
+ # @param [Array] argv command to run; argv[0] is program name and the
+ # remaining elements are parameters and flags
+ # @return [Command] the running command
+ def run_without_sugar(argv)
if self.buffered
run_buffered(argv)
else
run_unbuffered(argv)
end