Class: MiGA::Cli::Action::Cmd
- Inherits:
-
MiGA::Cli::Action
- Object
- MiGA
- MiGA::Cli::Action
- MiGA::Cli::Action::Cmd
- Defined in:
- lib/miga/cli/action/cmd.rb
Constant Summary
Constants included from MiGA
MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary
Attributes inherited from MiGA::Cli::Action
Attributes included from MiGA::Common::Net
Instance Method Summary collapse
Methods inherited from MiGA::Cli::Action
#complete, #empty_action, #initialize, #launch, load, #name
Methods inherited from MiGA
CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say
Methods included from MiGA::Common::Path
Methods included from MiGA::Common::Format
#clean_fasta_file, #seqs_length, #tabulate
Methods included from MiGA::Common::Net
#download_file_ftp, #http_request, #known_hosts, #main_server, #net_method, #normalize_encoding, #remote_connection
Methods included from MiGA::Common::SystemCall
Constructor Details
This class inherits a constructor from MiGA::Cli::Action
Instance Method Details
#parse_cli ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/miga/cli/action/cmd.rb', line 7 def parse_cli cli.expect_files = true cli.files_label = 'CMD' cli.defaults = { raise: false, return: :status, source: :miga_env, stdout: nil, stderr: nil, dry: false, show_cmd: false, err2out: false } cli.parse do |opt| opt.separator 'To separate command flags from MiGA flags, use --:' opt.separator 'miga cmd --verbose -- rbm.rb --version' opt.separator '' opt.separator 'To run the command as is (no escaping), use single-quotes:' opt.separator 'miga cmd \'echo $MIGA\'' opt.separator '' opt.on( '-o', '--stdout FILE', 'Save STDOUT to this file instead of displaying it' ) { |v| cli[:stdout] = v } opt.on( '-e', '--stderr FILE', 'Save STDERR to this file instead of displaying it' ) { |v| cli[:stderr] = v } opt.on( '--err2out', 'Combine STDERR and STDOUT into one single channel (STDOUT)' ) { |v| cli[:err2out] = v } opt.on( '--show-cmd', 'Show exact command being launched before running it' ) { |v| cli[:show_cmd] = v } opt.on( '--dry', 'Prepare the command but stop short of executing it', 'Useful in combination with --show-cmd; it always exits with code 1' ) { |v| cli[:dry] = v } end end |
#perform ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/miga/cli/action/cmd.rb', line 46 def perform cli.files cli.say 'Running command:' cmd = cli.files.size == 1 ? cli.files[0] : cli.files cli.say cmd status = MiGA::MiGA.run_cmd(cmd, cli.to_h) cli.say 'Exit status: %s' % status unless status&.success? exit(status.nil? ? 1 : status.exitstatus) end end |