class Enparallel::CLI
Public Class Methods
basename()
click to toggle source
# File lib/enparallel/cli.rb, line 20 def self.basename File.basename($0) end
new(opts, stdin)
click to toggle source
# File lib/enparallel/cli.rb, line 3 def initialize(opts, stdin) @opts = opts @stdin = stdin end
parse(argv, stdin)
click to toggle source
# File lib/enparallel/cli.rb, line 16 def self.parse(argv, stdin) new(Docopt::docopt(usage, argv: argv, version: VERSION), stdin) end
pick_default()
click to toggle source
# File lib/enparallel/cli.rb, line 12 def self.pick_default 'sequential' end
usage()
click to toggle source
# File lib/enparallel/cli.rb, line 24 def self.usage <<~EOF #{'Usage:'.bold} #{basename} [options] [--] <command>... #{'Description:'.bold} #{basename} operates by reading lines from standard input, and executing <command> once per entry, in parallel. The placeholder "{}", if present, is replaced with each line of input in turn. seq 1 10 | enparallel sleep {} To run a more complex command or to make use of shell functions or constructs (enparallel runs its argument as a program) use a call to "bash -c". Note that because of the "-c" you need to prefix the command with "--" to indicate the end of parameters to enparallel. seq 1 10 | enparallel -- bash -c "sleep {} && echo Slept for {}" #{'Options:'.bold} -w, --workers <n> Batch into a pool of <n> workers [default: #{workers_default}]. -p, --pick <type> Task-picking rule (see "Types") [default: #{pick_default}]. -v, --version Version. -h, --help Help. #{'Types:'.bold} sequential The order in which the tasks were queued. random Random order. EOF end
workers_default()
click to toggle source
# File lib/enparallel/cli.rb, line 8 def self.workers_default Util.processor_count end
Public Instance Methods
command()
click to toggle source
# File lib/enparallel/cli.rb, line 60 def command Command.from_a(@opts['<command>']) end
inputs()
click to toggle source
# File lib/enparallel/cli.rb, line 56 def inputs @inputs ||= @stdin.each_line.map(&:chomp) end
pick()
click to toggle source
# File lib/enparallel/cli.rb, line 68 def pick @opts['--pick'] || pick_default end
workers()
click to toggle source
# File lib/enparallel/cli.rb, line 64 def workers @opts['--workers'].to_i || workers_default end