Module: Magellan::Cli::Script

Defined in:
lib/magellan/cli/script.rb

Constant Summary collapse

SETTINGS =
[:io, :prompt, :program_name]

Class Method Summary collapse

Class Method Details

.cli(args, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/magellan/cli/script.rb', line 19

def cli(args, options = {})
  args = Shellwords.split(args) if args.is_a?(String)
  args << "-V" if ARGV.include?("-V")
  $PROGRAM_NAME, backup = program_name, $PROGRAM_NAME
  self.io.puts "#{prompt}#{$PROGRAM_NAME} #{args.join(' ')}"
  begin
    Magellan::Cli::Command.start(args) do |e|
      exit(1) unless e.message =~ options[:allow]
    end
  ensure
    $PROGRAM_NAME = backup
  end
end