Module: Spire::Commands::CLI

Defined in:
lib/spire/commands/cli.rb

Overview

This is the spire command

Constant Summary collapse

COMMANDS =
{
  "register" => Spire::Commands::Register,
  "console" => Spire::Commands::Console
}

Class Method Summary collapse

Class Method Details

.rcObject



28
29
30
# File 'lib/spire/commands/cli.rb', line 28

def self.rc
  @rc ||= (YAML.load_file(File.expand_path("~/.spirerc")) rescue {})
end

.run(subcommand, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spire/commands/cli.rb', line 15

def self.run(subcommand,*args)
  if command = COMMANDS[subcommand]
    begin
      command.run(args)
    rescue => e
      $stderr.puts "spire: #{e.message}"
      exit(-1)
    end
  else
    usage "#{subcommand} is not a supported command"
  end
end

.save_rcObject



32
33
34
# File 'lib/spire/commands/cli.rb', line 32

def self.save_rc
  File.open(File.expand_path("~/.spirerc"),"w") { |f| YAML.dump(rc,f) }
end

.urlObject



36
37
38
# File 'lib/spire/commands/cli.rb', line 36

def self.url
  rc["url"]||"https://api.spire.io"
end

.usage(message) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/spire/commands/cli.rb', line 40

def self.usage(message)
  $stderr.puts "spire: #{message}"
  $stderr.puts <<-eos
Usage: spire <subcommand> <options>

The spire command provides command line access to the spire.io API. 

Valid commands:

    register     Register a new account
    console      Open up an IRB session with an open spire session.
    
You can get more options for any command with --help or -h.
eos
  exit(-1)
end