Class: Hiera::Backend::Eyaml::Subcommand
- Inherits:
-
Object
- Object
- Hiera::Backend::Eyaml::Subcommand
show all
- Defined in:
- lib/hiera/backend/eyaml/subcommand.rb
Constant Summary
collapse
- @@global_options =
[
{:name => :encrypt_method,
:description => "Override default encryption and decryption method (default is PKCS7)",
:short => 'n',
:default => "pkcs7"},
{:name => :version,
:description => "Show version information"},
{:name => :verbose,
:description => "Be more verbose",
:short => 'v'},
{:name => :trace,
:description => "Enable trace debug",
:short => 't'},
{:name => :quiet,
:description => "Be less verbose",
:short => 'q'},
{:name => :help,
:description => "Information on how to use this command",
:short => 'h'}
]
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.global_options ⇒ Object
Returns the value of attribute global_options.
12
13
14
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 12
def global_options
@global_options
end
|
.helptext ⇒ Object
Returns the value of attribute helptext.
12
13
14
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 12
def helptext
@helptext
end
|
.options ⇒ Object
Returns the value of attribute options.
12
13
14
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 12
def options
@options
end
|
Class Method Details
.all_options ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 50
def self.all_options
options = @@global_options.dup
options += self.options if self.options
options += Plugins.options
config_file = self.load_config_file
options.map!{ | opt|
key_name = "#{opt[:name]}"
if config_file.has_key? key_name
opt[:default] = config_file[key_name]
opt
else
opt
end
}
options
end
|
.attach_option(opt) ⇒ Object
68
69
70
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 68
def self.attach_option opt
self.suboptions += opt
end
|
.description ⇒ Object
135
136
137
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 135
def self.description
"no description"
end
|
.execute ⇒ Object
143
144
145
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 143
def self.execute
raise StandardError, "This command is not implemented yet (#{self.to_s.split('::').last})"
end
|
.find(commandname = "unknown_command") ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 72
def self.find commandname = "unknown_command"
begin
require "hiera/backend/eyaml/subcommands/#{commandname.downcase}"
rescue Exception => e
require "hiera/backend/eyaml/subcommands/unknown_command"
return Hiera::Backend::Eyaml::Subcommands::UnknownCommand
end
command_module = Module.const_get('Hiera').const_get('Backend').const_get('Eyaml').const_get('Subcommands')
command_class = Utils.find_closest_class :parent_class => command_module, :class_name => commandname
command_class || Hiera::Backend::Eyaml::Subcommands::UnknownCommand
end
|
.hidden? ⇒ Boolean
151
152
153
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 151
def self.hidden?
false
end
|
.load_config_file ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 36
def self.load_config_file
config = {}
[ "/etc/eyaml/config.yaml", "#{ENV['HOME']}/.eyaml/config.yaml", "#{ENV['EYAML_CONFIG']}" ].each do |config_file|
begin
yaml_contents = YAML.load_file(config_file)
Utils::info "Loaded config from #{config_file}"
config.merge! yaml_contents
rescue
raise StandardError, "Could not open config file \"#{config_file}\" for reading"
end if config_file and File.file? config_file
end
config
end
|
.parse ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 84
def self.parse
me = self
options = Trollop::options do
version "Hiera-eyaml version " + Hiera::Backend::Eyaml::VERSION.to_s
banner ["eyaml #{me.prettyname}: #{me.description}", me.helptext, "Options:"].compact.join("\n\n")
me.all_options.each do |available_option|
skeleton = {:description => "",
:short => :none}
skeleton.merge! available_option
opt skeleton[:name],
skeleton[:desc] || skeleton[:description], :short => skeleton[:short],
:default => skeleton[:default],
:type => skeleton[:type]
end
stop_on Eyaml.subcommands
end
if options[:verbose]
Hiera::Backend::Eyaml.verbosity_level += 1
end
if options[:trace]
Hiera::Backend::Eyaml.verbosity_level += 2
end
if options[:quiet]
Hiera::Backend::Eyaml.verbosity_level = 0
end
if options[:encrypt_method]
Hiera::Backend::Eyaml.default_encryption_scheme = options[:encrypt_method]
end
options
end
|
.prettyname ⇒ Object
147
148
149
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 147
def self.prettyname
Utils.snakecase self.to_s.split('::').last
end
|
.validate(args) ⇒ Object
131
132
133
|
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 131
def self.validate args
args
end
|