Module: Clitopic::Cli

Defined in:
lib/clitopic/cli.rb

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/clitopic/cli.rb', line 9

def run(args)
  args = args.dup
  $stdin.sync = true if $stdin.isatty
  $stdout.sync = true if $stdout.isatty
  command = args.shift.strip rescue "help"
  if !Clitopic.commands_dir.nil?
    Clitopic::Commands.load_commands(Clitopic.commands_dir)
  end
  Clitopic::Commands.run(command, args)
rescue Errno::EPIPE => e
  puts e.message #error(e.message)
  puts e.backtrace
rescue Interrupt => e
  `stty icanon echo`
  if Clitopic.debug
    Clitopic::Helpers.styled_error(e)
  else
    Clitopic::Helpers.error("Command cancelled.", false)
  end
rescue => error
  Clitopic::Helpers.styled_error(error)
  exit(1)
end