Class: Whaler::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/whaler/cli.rb

Constant Summary collapse

EX_USAGE =
64
EX_DATAERR =
65
EX_NOINPUT =
66
GIT_URI =
"[email protected]"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



38
39
40
# File 'lib/whaler/cli.rb', line 38

def initialize(args)
  @args = args
end

Class Method Details

.app(opts) ⇒ Object



16
17
18
# File 'lib/whaler/cli.rb', line 16

def self.app(opts)
  opts[:app] || detect_app
end

.app_opts(command) ⇒ Object



12
13
14
# File 'lib/whaler/cli.rb', line 12

def self.app_opts(command)
  command.on "a=", "app=", "Application"
end

.detect_appObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/whaler/cli.rb', line 20

def self.detect_app
  apps = Git.open(".").remotes.map do |remote|
    if m = remote.url.match(/#{GIT_URI}:(.+)\.git/)
      m[1]
    end
  end.uniq

  if apps.size == 0
    $stderr.puts "No app found. Please run whaler from the app folder or use the --app option"
    exit EX_NOINPUT
  elsif apps.size > 1
    $stderr.puts "Multiple apps found (#{apps.join(", ")}). Please specify one with the --app option"
    exit EX_DATAERR
  end

  apps.first
end

Instance Method Details

#runObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/whaler/cli.rb', line 42

def run
  Slop.parse(args, help: true, strict: true) do
    context = self
    Command.commands.each do |block|
      self.instance_eval(&block)
    end

    run do |opts, args|
      $stderr.puts opts.help
      exit EX_USAGE
    end
  end
end