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
20 21 22 |
# File 'lib/enparallel/cli.rb', line 20 def self.basename File.basename($0) end |
.parse(argv, stdin) ⇒ Object
16 17 18 |
# File 'lib/enparallel/cli.rb', line 16 def self.parse(argv, stdin) new(Docopt::docopt(usage, argv: argv, version: VERSION), stdin) end |
.pick_default ⇒ Object
12 13 14 |
# File 'lib/enparallel/cli.rb', line 12 def self.pick_default 'sequential' end |
.usage ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/enparallel/cli.rb', line 24 def self.usage " \#{'Usage:'.bold}\n \#{basename} [options] [--] <command>...\n\n \#{'Description:'.bold}\n \#{basename} 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:'.bold}\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 Version.\n -h, --help Help.\n\n \#{'Types:'.bold}\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
60 61 62 |
# File 'lib/enparallel/cli.rb', line 60 def command Command.from_a(@opts['<command>']) end |
#inputs ⇒ Object
56 57 58 |
# File 'lib/enparallel/cli.rb', line 56 def inputs @inputs ||= @stdin.each_line.map(&:chomp) end |
#pick ⇒ Object
68 69 70 |
# File 'lib/enparallel/cli.rb', line 68 def pick @opts['--pick'] || pick_default end |
#workers ⇒ Object
64 65 66 |
# File 'lib/enparallel/cli.rb', line 64 def workers @opts['--workers'].to_i || workers_default end |