Class: Keg::CLI

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

Constant Summary collapse

DEFAULT_FORMAT =
'json'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
# File 'lib/keg/cli.rb', line 9

def initialize(*args)
  super
  @database = Core.new(ENV["HOME"])
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


7
# File 'lib/keg/cli.rb', line 7

def self.exit_on_failure?; true end

Instance Method Details

#currentObject



38
39
40
41
42
43
44
# File 'lib/keg/cli.rb', line 38

def current
  begin
    puts @database.current
  rescue => e
    raise Thor::InvocationError.new(e.message)
  end
end

#show(filename) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/keg/cli.rb', line 26

def show(filename)
  begin
    content = @database.select(filename)
    formatter = Formatter.create(options[:format])
  rescue => e
    raise Thor::InvocationError.new(e)
  end

  puts formatter.format(content)
end

#show_allObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/keg/cli.rb', line 48

def show_all
  begin
    contents = @database.select_all
    formatter = Formatter.create(options[:format])
  rescue => e
    raise Thor::InvocationError.new(e)
  end

  contents.each do |content|
    puts formatter.format(content)
  end
end

#switch(name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/keg/cli.rb', line 15

def switch(name)
  begin
    @database.switch name
  rescue => e
    raise Thor::InvocationError.new(e)
  end
  puts "Switch dataBase `#{name}`."
end