Class: Keystorage::CLI

Inherits:
Thor
  • Object
show all
Includes:
Keystorage
Defined in:
lib/keystorage/cli.rb

Constant Summary

Constants included from Keystorage

DEFAULT_FILE, DEFAULT_SECRET

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Keystorage

#render, #render_text

Class Attribute Details

.global_optionsObject (readonly)

Returns the value of attribute global_options.



31
32
33
# File 'lib/keystorage/cli.rb', line 31

def global_options
  @global_options
end

Class Method Details

.global_option(*params) ⇒ Object



33
34
35
36
37
# File 'lib/keystorage/cli.rb', line 33

def global_option *params
  @global_options ||= {}
  @global_options[params[0]] = params[1]
  class_option params[0],params[1]
end

.start(given_args = ARGV, config = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/keystorage/cli.rb', line 13

def start(given_args = ARGV, config = {})
  # parse global options: Thor is not support global-options.
  # Like: command global-options subcommand options
  new_global_options = []
  OptionParser.new do |opt|
    @global_options.each { |name,config|
      case config[:type]
      when :boolean then
        opt.on(config[:aliases],"--#{name.to_s}") { |v| new_global_options << "--#{name.to_s}"}
      when :string then
        opt.on(config[:aliases],"--#{name.to_s}=VALUE") { |v| new_global_options << "--#{name.to_s}=#{v}"}
      end
    }
    opt.parse!(given_args)
  end
  given_args+=new_global_options
  super(given_args,config)
end

Instance Method Details

#exec(*command) ⇒ Object



73
74
75
76
# File 'lib/keystorage/cli.rb', line 73

def exec *command
  #@todo: ask if new_secret == nil
  Manager.new(options).exec(command)
end

#get(group, key) ⇒ Object



56
57
58
# File 'lib/keystorage/cli.rb', line 56

def get(group,key)
  puts render(Manager.new(options).get(group,key))
end

#groupsObject



46
47
48
# File 'lib/keystorage/cli.rb', line 46

def groups
  puts render(Manager.new(options).groups)
end

#keys(group) ⇒ Object



51
52
53
# File 'lib/keystorage/cli.rb', line 51

def keys(group)
  puts render(Manager.new(options).keys(group))
end

#password(new_secret = nil) ⇒ Object



67
68
69
70
# File 'lib/keystorage/cli.rb', line 67

def password new_secret=nil
  #@todo: ask if new_secret == nil
  Manager.new(options).password(new_secret)
end

#set(group, key, value = nil) ⇒ Object



61
62
63
64
# File 'lib/keystorage/cli.rb', line 61

def set(group,key,value=nil)
  #@todo: ask if value == nil
  puts render Manager.new(options).set(group,key,value)
end

#versionObject



79
80
81
# File 'lib/keystorage/cli.rb', line 79

def version
  puts Version.current
end