Class: Gtmtech::Crypto::Subcommand
- Inherits:
-
Object
- Object
- Gtmtech::Crypto::Subcommand
show all
- Defined in:
- lib/gtmtech/crypto/subcommand.rb
Constant Summary
collapse
- @@global_options =
[
{:name => :version,
:description => "Show version information"},
{: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.
13
14
15
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 13
def global_options
@global_options
end
|
.helptext ⇒ Object
Returns the value of attribute helptext.
13
14
15
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 13
def helptext
@helptext
end
|
.options ⇒ Object
Returns the value of attribute options.
13
14
15
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 13
def options
@options
end
|
Class Method Details
.all_options ⇒ Object
24
25
26
27
28
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 24
def self.all_options
options = @@global_options.dup
options += self.options if self.options
{ :options => options }
end
|
.description ⇒ Object
83
84
85
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 83
def self.description
"no description"
end
|
.error(message) ⇒ Object
103
104
105
106
107
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 103
def self.error message
puts "Error:"
puts message
exit 1
end
|
.execute ⇒ Object
91
92
93
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 91
def self.execute
raise StandardError, "This command is not implemented yet (#{self.to_s.split('::').last})"
end
|
.find(commandname = "unknown_command") ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 30
def self.find commandname = "unknown_command"
begin
require "gtmtech/crypto/subcommands/#{commandname.downcase}"
rescue Exception => e
require "gtmtech/crypto/subcommands/unknown_command"
return Gtmtech::Crypto::Subcommands::UnknownCommand
end
command_module = Module.const_get('Gtmtech').const_get('Crypto').const_get('Subcommands')
command_class = Utils.find_closest_class :parent_class => command_module, :class_name => commandname
if command_class
command_class
else
require "gtmtech/crypto/subcommands/unknown_command"
Gtmtech::Crypto::Subcommands::UnknownCommand
end
end
|
.hidden? ⇒ Boolean
99
100
101
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 99
def self.hidden?
false
end
|
.parse ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 47
def self.parse
me = self
all = self.all_options
@@options = Trollop::options do
version "gtmtech-crypto version " + Gtmtech::Crypto::VERSION.to_s
banner "#{me.usage}\n\n"
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
end
end
|
.prettyname ⇒ Object
95
96
97
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 95
def self.prettyname
Utils.snakecase self.to_s.split('::').last
end
|
.usage ⇒ Object
79
80
81
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 79
def self.usage
"Usage: \ncrypto #{self.prettyname} [global-options] [options]\nDescription: #{self.description}"
end
|
.validate(args) ⇒ Object
75
76
77
|
# File 'lib/gtmtech/crypto/subcommand.rb', line 75
def self.validate args
args
end
|