Class: MiGA::Cli::Action

Inherits:
MiGA
  • Object
show all
Defined in:
lib/miga/cli/action.rb

Overview

An action to be performed by the CLI. This is a generic class to be extended by MiGA::Cli::Action::* classes. Do not attempt creating directly with new, use instead the MiGA::Cli::Action.load interface.

Defined Under Namespace

Modules: Download, Wf Classes: About, Add, AddResult, Archive, Browse, ClassifyWf, Console, Daemon, Date, Db, DerepWf, Doctor, Edit, Env, Files, Find, Generic, Get, GtdbGet, IndexWf, Init, Lair, Ln, Ls, NcbiGet, New, NextStep, Option, PreprocWf, QualityWf, Rm, Run, SeqcodeGet, Stats, Summary, TaxDist, TaxIndex, TaxSet, TaxTest, Touch

Constant Summary

Constants included from MiGA

MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary collapse

Attributes included from MiGA::Common::Net

#remote_connection_uri

Class Method Summary collapse

Instance Method Summary collapse

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

#root_path, #script_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

#run_cmd, #run_cmd_opts

Constructor Details

#initialize(cli) ⇒ Action

Returns a new instance of Action.



22
23
24
# File 'lib/miga/cli/action.rb', line 22

def initialize(cli)
  @cli = cli
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



20
21
22
# File 'lib/miga/cli/action.rb', line 20

def cli
  @cli
end

Class Method Details

.load(task, cli) ⇒ Object



12
13
14
15
16
17
# File 'lib/miga/cli/action.rb', line 12

def load(task, cli)
  require "miga/cli/action/#{task}"
  camel = task.to_s.gsub(/(?:_|^)(\S)/, &:upcase).delete('_')
  klass = Object.const_get("MiGA::Cli::Action::#{camel}")
  klass.new(cli)
end

Instance Method Details

#completeObject

Complete the action



50
51
52
# File 'lib/miga/cli/action.rb', line 50

def complete
  cli.say 'Done'
end

#empty_actionObject

What to do when cli.argv is empty



63
64
65
# File 'lib/miga/cli/action.rb', line 63

def empty_action
  cli.argv << '-h'
end

#launchObject

Launch the sequence



28
29
30
31
32
33
34
# File 'lib/miga/cli/action.rb', line 28

def launch
  MiGA.DEBUG 'Cli::Action.launch'
  empty_action if cli.argv.empty?
  parse_cli
  perform
  complete
end

#nameObject

Name of the action, as referred to by the CLI



56
57
58
59
# File 'lib/miga/cli/action.rb', line 56

def name
  camel = self.class.to_s.gsub(/.*::/, '')
  camel.gsub(/(\S)([A-Z])/, '\1_\2').downcase
end

#parse_cliObject

Parse the CLI object



38
39
40
# File 'lib/miga/cli/action.rb', line 38

def parse_cli
  raise "Undefined interface for the command line of #{cli.task}"
end

#performObject

Perform the action



44
45
46
# File 'lib/miga/cli/action.rb', line 44

def perform
  raise "Undefined action for the command line of #{cli.task}"
end