class MiGA::Cli::Action

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 ::load interface.

Attributes

cli[RW]

Public Class Methods

load(task, cli) click to toggle source
# File lib/miga/cli/action.rb, line 13
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
new(cli) click to toggle source
# File lib/miga/cli/action.rb, line 23
def initialize(cli)
  @cli = cli
end

Public Instance Methods

complete() click to toggle source

Complete the action

# File lib/miga/cli/action.rb, line 50
def complete
  cli.say 'Done'
end
empty_action() click to toggle source

What to do when cli.argv is empty

# File lib/miga/cli/action.rb, line 63
def empty_action
  cli.argv << '-h'
end
launch() click to toggle source

Launch the sequence

# File lib/miga/cli/action.rb, line 29
def launch
  empty_action if cli.argv.empty?
  parse_cli
  perform
  complete
end
name() click to toggle source

Name of the action, as referred to by the CLI

# 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_cli() click to toggle source

Parse the CLI object

# File lib/miga/cli/action.rb, line 38
def parse_cli
  raise "Undefined interface for the command line of #{cli.task}"
end
perform() click to toggle source

Perform the action

# File lib/miga/cli/action.rb, line 44
def perform
  raise "Undefined action for the command line of #{cli.task}"
end