Class: MiGA::Cli::Action::Option
- Inherits:
-
MiGA::Cli::Action
- Object
- MiGA
- MiGA::Cli::Action
- MiGA::Cli::Action::Option
- Defined in:
- lib/miga/cli/action/option.rb
Overview
CLI: ‘miga option`
Constant Summary
Constants included from MiGA
MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary
Attributes inherited from MiGA::Cli::Action
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, #known_hosts, #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
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 |
# File 'lib/miga/cli/action/option.rb', line 8 def parse_cli cli.parse do |opt| cli.opt_object(opt, %i[project dataset_opt]) opt.on( '-k', '--key STRING', 'Option name to get or set (by default, all options are printed)' ) { |v| cli[:key] = v } opt.on( '--value STRING', 'Value of the option to set (by default, option value is not changed)', 'Recognized tokens: nil, true, false' ) { |v| cli[:value] = v } opt.on( '--about', 'Print additional information about the values supported by this option' ) { |v| cli[:about] = v } opt.on( '--tab', 'Return a tab-delimited table' ) { |v| cli[:tabular] = v } opt.on( '-o', '--output PATH', 'Create output file instead of returning to STDOUT' ) { |v| cli[:output] = v } end end |
#perform ⇒ Object
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/miga/cli/action/option.rb', line 35 def perform unless cli[:value].nil? cli.ensure_par( { key: '-k' }, '%<name>s is mandatory when --value is set: provide %<flag>s' ) end obj = cli.load_project_or_dataset io = cli[:output].nil? ? $stdout : File.open(cli[:output], 'w') if cli[:key].nil? opts = obj. .map { |k, v| [k, v, obj.assert_has_option(k)[:desc]] } cli.table(%w[Key Value Definition], opts, io) elsif cli[:about] opt = obj.assert_has_option(cli[:key]) title = "#{cli[:key]}: #{opt[:desc]}" io.puts title io.puts '-' * title.length opt.each do |k, v| v = v[obj] if v.is_a? Proc io.puts "#{k.to_s.capitalize}: #{v}" unless k == :desc end else obj.set_option(cli[:key], cli[:value], true) unless cli[:value].nil? io.puts obj.option(cli[:key]) end io.close unless cli[:output].nil? end |