Class: Strobe::CLI

Inherits:
Thor
  • Object
show all
Includes:
Resources
Defined in:
lib/strobe/cli.rb

Direct Known Subclasses

Deploys, Main, Users

Defined Under Namespace

Modules: Preview Classes: DeployProgress, Deploys, Input, Main, Settings, Table, Ticker, Users

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.


103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/strobe/cli.rb', line 103

def initialize(*)
  super

  @resource = nil
  @input = Input.new

  # State
  @in_group = false
  @success  = false

  settings.connect!
end

Class Method Details

.__haxlias(name) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/strobe/cli.rb', line 83

def self.__haxlias(name)
  @haxliases ||= []

  return name if Class === name

  if @haxliases.include?(name.to_s)
    "__hax__#{name}"
  else
    name
  end
end

.action(name, *args, &blk) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/strobe/cli.rb', line 65

def self.action(name, *args, &blk)
  @haxliases ||= []
  @haxliases << name.to_s
  options = args.last if args.last.is_a?(Hash)
  usage = if options && options[:usage]
    options[:usage]
  elsif self == Users
    "users #{name}"
  elsif self == Deploys
    "deploys #{name}"
  else
    name
  end
  desc usage, *args
  define_method("__hax__#{name}", &blk)
  map name => "__hax__#{name}"
end

.application_path_optionObject


95
96
97
# File 'lib/strobe/cli.rb', line 95

def self.application_path_option
  method_option :path, :type => :string, :banner => "Path to your application"
end

.handle_argument_error(task, error) ⇒ Object

:nodoc:

Raises:

  • (InvocationError)

99
100
101
# File 'lib/strobe/cli.rb', line 99

def self.handle_argument_error(task, error) #:nodoc:
  raise InvocationError, "#{task.name.sub('__hax__','').inspect} was called incorrectly. Call as #{self.banner(task).inspect}."
end

.start(args) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
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
63
# File 'lib/strobe/cli.rb', line 23

def self.start(args)
  begin
    $__ARGV = args
    IdentityMap.wrap do
      super
    end
  rescue Strobe::UnauthenticatedError => e
    if Settings.global[:token]
      puts "[ERROR] Your token is invalid, please login to get a valid token"
      CLI::Main.start( [ "login" ] )
      retry
    else
      raise e
    end
  end
rescue NotifiableError => e
  if $__ARGV.include?('--backtrace')
    require 'pp'
    puts "=== ERROR DATA ==="
    pp e.data
    puts "\n"
    raise
  end
  STDERR.puts "[ERROR] #{e.message}"
  ExceptionNotifier.notify(e, :action => args.join(" "))
  abort
rescue StrobeError => e
  raise if $__ARGV.include?('--backtrace')
  STDERR.puts "[ERROR] #{e.message}"
  abort
rescue Interrupt
  abort  "\nQuitting..."
rescue SystemExit => e
  exit e.status
rescue Exception => e
  warn "Unfortunately, a fatal error has occurred. " +
    "Please report this error to Strobe Support at " +
    "http://support.strobeapp.com/home so that we can fix it. Thanks!\n\n" +
    "VERSION: #{Strobe.user_agent}"
  raise e
end