Class: OptparseLite::AppSpec
- Inherits:
-
Object
- Object
- OptparseLite::AppSpec
show all
- Includes:
- Lingual
- Defined in:
- lib/optparse-lite.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Lingual
#methodize, #oxford_comma
Constructor Details
#initialize(mod) ⇒ AppSpec
Returns a new instance of AppSpec.
38
39
40
41
42
43
44
45
46
|
# File 'lib/optparse-lite.rb', line 38
def initialize mod
@app_description = Description.new
@base_commands = nil
@commands = []
@names = {}
@mod = mod
@order = []
@desc = @opts = @spec = @subcommands = @usage = nil
end
|
Instance Attribute Details
#app_description ⇒ Object
Returns the value of attribute app_description.
47
48
49
|
# File 'lib/optparse-lite.rb', line 47
def app_description
@app_description
end
|
#invocation_name ⇒ Object
82
83
84
|
# File 'lib/optparse-lite.rb', line 82
def invocation_name
@invocation_name ||= File.basename($PROGRAM_NAME)
end
|
Instance Method Details
#base_commands ⇒ Object
48
49
50
51
52
53
|
# File 'lib/optparse-lite.rb', line 48
def base_commands
@base_commands ||=
(@order & @mod.public_instance_methods(false)).map do |meth|
get_command(meth)
end
end
|
#cmd_desc(desc) ⇒ Object
54
55
56
57
|
# File 'lib/optparse-lite.rb', line 54
def cmd_desc desc
@desc ||= []
@desc.push desc
end
|
#desc(mixed) ⇒ Object
58
59
60
|
# File 'lib/optparse-lite.rb', line 58
def desc mixed
@app_description.push mixed
end
|
#find_all_local(local_name) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/optparse-lite.rb', line 70
def find_all_local local_name
meth = methodize(local_name)
re = /^#{Regexp.escape(meth)}/
command_method_names.grep(re).map do |n|
if n == meth
return [get_command(n)]
else
get_command(n)
end
end
end
|
#get_command(meth) ⇒ Object
this is private except for getting subcommand command objects!
62
63
64
65
66
67
68
69
|
# File 'lib/optparse-lite.rb', line 62
def get_command meth
@names[meth] ? @commands[@names[meth]] : begin
@names[meth] = @commands.length
cmd = Command.new(self, meth)
@commands.push cmd
cmd
end
end
|
#method_added_notify(meth) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/optparse-lite.rb', line 85
def method_added_notify meth
meth = meth.to_s
@order.push meth
if @desc || @opts || @usage || @subcommands
@names[meth] = @commands.length
@commands.push Command.new(self, meth, @desc, @opts, @usage,
@subcommands)
@desc = @opts = @usage = @subcommands = nil
end
end
|
#opts(mixed = nil, &block) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/optparse-lite.rb', line 95
def opts mixed=nil, &block
@desc ||= []
@opts ||= []
fail("can't take block and arg") if mixed && block
if block
mixed = parser_from_block(&block)
else
fail("opts must be OptsLike") unless mixed.kind_of?(OptsLike)
end
@opts.push @desc.size
@desc.push mixed
end
|
#parser_from_block(&block) ⇒ Object
107
108
109
|
# File 'lib/optparse-lite.rb', line 107
def parser_from_block &block
OptParser.new(&block)
end
|
#subcommands(*a) ⇒ Object
110
111
112
113
|
# File 'lib/optparse-lite.rb', line 110
def subcommands *a
@subcommands ||= []
@subcommands.concat a
end
|
#unbound_method(method_name) ⇒ Object
114
115
116
|
# File 'lib/optparse-lite.rb', line 114
def unbound_method method_name
@mod.instance_method method_name
end
|
#usage(usage) ⇒ Object
117
118
119
120
|
# File 'lib/optparse-lite.rb', line 117
def usage usage
@usage ||= []
@usage.push usage
end
|