Module: Linguist::Command

Extended by:
Helpers
Defined in:
lib/linguist_ruby/command.rb,
lib/linguist_ruby/commands/auth.rb,
lib/linguist_ruby/commands/base.rb,
lib/linguist_ruby/commands/help.rb,
lib/linguist_ruby/commands/project.rb,
lib/linguist_ruby/commands/version.rb,
lib/linguist_ruby/commands/collaborator.rb,
lib/linguist_ruby/commands/translations.rb

Defined Under Namespace

Classes: Auth, Base, BaseWithApp, Collaborator, CommandFailed, Help, InvalidCommand, Project, Translations, Version

Class Method Summary collapse

Methods included from Helpers

ask, confirm, confirm_command, deprecate, display, error, format_date, git, has_git?, home_directory, redisplay, retry_on_exception, run_command, running_on_a_mac?, running_on_windows?, shell

Class Method Details

.parse(command) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/linguist_ruby/command.rb', line 49

def parse(command)
  parts = command.split(':')
  case parts.size
    when 1
      begin
        return eval("Linguist::Command::#{command.capitalize}"), :index
      rescue NameError, NoMethodError
        return Linguist::Command::Project, command.to_sym
      end
    else
      begin
        const = Linguist::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



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

def run(command, args, retries=0)
  begin
    run_internal 'auth:reauthorize', args.dup if retries > 0
    run_internal(command, args.dup)
  rescue InvalidCommand
    error "Unknown command. Run 'linguist 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::ResourceNotFound => e
#          error extract_not_found(e.http_body)
#        rescue RestClient::RequestFailed => e
#          error extract_error(e.http_body) unless e.http_code == 402
#          retry if run_internal('account:confirm_billing', args.dup)
#        rescue RestClient::RequestTimeout
#          error "API request timed out. Please try again, or contact [email protected] if this issue persists."
  rescue CommandFailed => e
    error e.message
  rescue Interrupt => e
    error "\n[canceled]"
  end
end

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

Raises:



42
43
44
45
46
47
# File 'lib/linguist_ruby/command.rb', line 42

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