Class: Enparallel::CLI
- Inherits:
-
Object
- Object
- Enparallel::CLI
- Defined in:
- lib/enparallel/cli.rb
Class Method Summary collapse
- .basename ⇒ Object
- .parse(argv, stdin) ⇒ Object
- .pick_default ⇒ Object
- .usage ⇒ Object
- .workers_default ⇒ Object
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(opts, stdin) ⇒ CLI
constructor
A new instance of CLI.
- #inputs ⇒ Object
- #pick ⇒ Object
- #workers ⇒ Object
Constructor Details
#initialize(opts, stdin) ⇒ CLI
Returns a new instance of CLI.
3 4 5 6 |
# File 'lib/enparallel/cli.rb', line 3 def initialize(opts, stdin) @opts = opts @stdin = stdin end |
Class Method Details
.basename ⇒ Object
27 28 29 |
# File 'lib/enparallel/cli.rb', line 27 def self.basename File.basename($0) end |
.parse(argv, stdin) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/enparallel/cli.rb', line 16 def self.parse(argv, stdin) opts = Docopt::docopt(usage, argv: argv) if opts['--version'] puts VERSION exit end new(opts, stdin) end |
.pick_default ⇒ Object
12 13 14 |
# File 'lib/enparallel/cli.rb', line 12 def self.pick_default 'sequential' end |
.usage ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/enparallel/cli.rb', line 31 def self.usage <<~EOF Usage: #{basename} [options] [--] <command>... #{basename} ( --version | --help ) Description: #{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: -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: sequential The order in which the tasks were queued. random Random order. EOF end |
.workers_default ⇒ Object
8 9 10 |
# File 'lib/enparallel/cli.rb', line 8 def self.workers_default Util.processor_count end |
Instance Method Details
#command ⇒ Object
68 69 70 |
# File 'lib/enparallel/cli.rb', line 68 def command Command.from_a(@opts['<command>']) end |
#inputs ⇒ Object
64 65 66 |
# File 'lib/enparallel/cli.rb', line 64 def inputs @inputs ||= @stdin.each_line.map(&:chomp) end |
#pick ⇒ Object
76 77 78 |
# File 'lib/enparallel/cli.rb', line 76 def pick @opts['--pick'] || pick_default end |
#workers ⇒ Object
72 73 74 |
# File 'lib/enparallel/cli.rb', line 72 def workers @opts['--workers'].to_i || workers_default end |