Module: AppSendr::Command

Extended by:
Helpers
Defined in:
lib/appsendr/command.rb,
lib/appsendr/commands/app.rb,
lib/appsendr/commands/auth.rb,
lib/appsendr/commands/base.rb,
lib/appsendr/commands/help.rb,
lib/appsendr/commands/build.rb,
lib/appsendr/commands/deploy.rb,
lib/appsendr/commands/testers.rb,
lib/appsendr/commands/version.rb,
lib/appsendr/commands/collaborators.rb

Defined Under Namespace

Classes: App, Auth, Base, Build, CommandFailed, Deploy, Help, InvalidCommand, Testers, Version

Class Method Summary collapse

Methods included from Helpers

credentials_file, credentials_setup?, display, error, has_project_droppr?, home_directory, in_project_dir?, project_appsendr, project_appsendr_app, read_app, read_app_id, require_in_project_and_no_droppr, require_project, require_project_dir, require_project_droppr, running_on_a_mac?, running_on_windows?

Class Method Details

.parse(command) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/appsendr/command.rb', line 45

def parse(command)
  parts = command.split(':')
  case parts.size
    when 1
      begin
        return eval("AppSendr::Command::#{command.capitalize}"), :index
      rescue NameError, NoMethodError
        return AppSendr::Command::App, command.to_sym
      end
    else
      begin
        const = AppSendr::Command
        command = parts.pop
        parts.each { |part| const = const.const_get(part.capitalize) }
        return const, command.to_sym
      rescue NameError
        raise InvalidCommand
      end
  end
end

.run(command, args, retries = 0) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appsendr/command.rb', line 16

def run(command, args, retries=0)
  begin
    run_internal 'auth:reauthorize', args.dup if (retries > 0 or !credentials_setup?)
    run_internal(command, args.dup)
  rescue InvalidCommand
    error "Unknown command. Run 'appsendr help' for usage information."
  rescue RestClient::Unauthorized
    if retries < 3
      STDERR.puts "Authentication failure"
      run(command, args, retries+1)
    else
      error "Authentication failure"
    end
  rescue RestClient::RequestFailed
      error "Something went wrong with the server."
  rescue CommandFailed => e
    error e.message
  rescue Interrupt => e
    error "\n[canceled]"
  end
end

.run_internal(command, args, appsendr = nil) ⇒ Object

Raises:



38
39
40
41
42
43
# File 'lib/appsendr/command.rb', line 38

def run_internal(command, args, appsendr=nil)
  klass, method = parse(command)
  runner = klass.new(args, appsendr)
  raise InvalidCommand unless runner.respond_to?(method)
  runner.send(method)
end