Class: Enparallel::CLI
- Inherits:
-
Object
- Object
- Enparallel::CLI
- Defined in:
- lib/enparallel/cli.rb
Class Method Summary collapse
- .parse(argv, stdin) ⇒ Object
- .pick_default ⇒ Object
- .program_name ⇒ 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
3 4 5 6 |
# File 'lib/enparallel/cli.rb', line 3 def initialize(opts, stdin) @opts = opts @stdin = stdin end |
Class Method Details
.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 |
.program_name ⇒ Object
27 28 29 |
# File 'lib/enparallel/cli.rb', line 27 def self.program_name File.basename($PROGRAM_NAME) 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 |
# File 'lib/enparallel/cli.rb', line 31 def self.usage " Usage:\n \#{program_name} [options] [--] <command>...\n \#{program_name} --version\n\n Description:\n \#{program_name} operates by reading lines from standard input, and executing\n <command> once per entry, in parallel.\n\n The placeholder \"{}\", if present, is replaced with each line of input in turn.\n\n seq 1 10 | enparallel sleep {}\n\n To run a more complex command or to make use of shell functions or constructs\n (enparallel runs its argument as a program) use a call to \"bash -c\". Note that\n because of the \"-c\" you need to prefix the command with \"--\" to indicate the\n end of parameters to enparallel.\n\n seq 1 10 | enparallel -- bash -c \"sleep {} && echo Slept for {}\"\n\n Options:\n -w, --workers <n> Batch into a pool of <n> workers [default: \#{workers_default}]\n -p, --pick <type> Task-picking rule (see \"Types\") [default: \#{pick_default}]\n -v, --version Show version\n\n Types:\n sequential The order in which the tasks were queued\n random Random order\n EOF\nend\n" |
.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
67 68 69 |
# File 'lib/enparallel/cli.rb', line 67 def command Command.from_a(@opts['<command>']) end |
#inputs ⇒ Object
63 64 65 |
# File 'lib/enparallel/cli.rb', line 63 def inputs @inputs ||= @stdin.each_line.map(&:chomp) end |
#pick ⇒ Object
75 76 77 |
# File 'lib/enparallel/cli.rb', line 75 def pick @opts['--pick'] || pick_default end |
#workers ⇒ Object
71 72 73 |
# File 'lib/enparallel/cli.rb', line 71 def workers @opts['--workers'].to_i || workers_default end |