Class: GLI::Commands::RdocDocumentListener
- Inherits:
-
Object
- Object
- GLI::Commands::RdocDocumentListener
- Defined in:
- lib/gli/commands/rdoc_document_listener.rb
Instance Method Summary collapse
- #beginning ⇒ Object
-
#command(name, aliases, desc, long_desc, arg_name) ⇒ Object
Gives you a command in the current context and creates a new context of this command.
- #commands ⇒ Object
-
#default_command(name) ⇒ Object
Gives you the name of the current command in the current context.
-
#end_command(name) ⇒ Object
Ends a command, and “pops” you back up one context.
- #end_commands ⇒ Object
- #end_options ⇒ Object
-
#ending ⇒ Object
Called when processing has completed.
-
#flag(name, aliases, desc, long_desc, default_value, arg_name, must_match, type) ⇒ Object
Gives you a flag in the current context.
-
#initialize(global_options, options, arguments) ⇒ RdocDocumentListener
constructor
A new instance of RdocDocumentListener.
- #options ⇒ Object
-
#program_desc(desc) ⇒ Object
Gives you the program description.
-
#switch(name, aliases, desc, long_desc, negetable) ⇒ Object
Gives you a switch in the current context.
-
#version(version) ⇒ Object
Gives you the program version.
Constructor Details
#initialize(global_options, options, arguments) ⇒ RdocDocumentListener
Returns a new instance of RdocDocumentListener.
6 7 8 9 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 6 def initialize(,,arguments) @io = File.new(File.basename($0) + ".rdoc",'w') @nest = '' end |
Instance Method Details
#beginning ⇒ Object
11 12 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 11 def beginning end |
#command(name, aliases, desc, long_desc, arg_name) ⇒ Object
Gives you a command in the current context and creates a new context of this command
77 78 79 80 81 82 83 84 85 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 77 def command(name,aliases,desc,long_desc,arg_name) @io.puts "#{@nest}=== #{name} #{arg_name}" @io.puts String(desc).strip @io.puts @io.puts "[Aliases] #{aliases.join(',')}\n" unless aliases.empty? @io.puts @io.puts String(long_desc).strip @nest = "#{@nest}=" end |
#commands ⇒ Object
71 72 73 74 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 71 def commands @io.puts "#{@nest}=== Commands" @nest = "#{@nest}=" end |
#default_command(name) ⇒ Object
Gives you the name of the current command in the current context
93 94 95 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 93 def default_command(name) @io.puts "[Default Command] #{name}" unless name.nil? end |
#end_command(name) ⇒ Object
Ends a command, and “pops” you back up one context
88 89 90 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 88 def end_command(name) @nest.gsub!(/=$/,'') end |
#end_commands ⇒ Object
97 98 99 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 97 def end_commands @nest.gsub!(/=$/,'') end |
#end_options ⇒ Object
68 69 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 68 def end |
#ending ⇒ Object
Called when processing has completed
15 16 17 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 15 def ending @io.close end |
#flag(name, aliases, desc, long_desc, default_value, arg_name, must_match, type) ⇒ Object
Gives you a flag in the current context
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 40 def flag(name,aliases,desc,long_desc,default_value,arg_name,must_match,type) usage = "#{add_dashes(name)} #{arg_name || 'arg'}" @io.puts "#{@nest}=== #{usage}" @io.puts @io.puts String(desc).strip @io.puts @io.puts "[Aliases] #{aliases.map { |_| add_dashes(_) }.join(',')}" unless aliases.empty? @io.puts "[Default Value] #{default_value || 'None'}" @io.puts "[Must Match] #{must_match.to_s}" unless must_match.nil? @io.puts String(long_desc).strip @io.puts end |
#options ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 31 def if @nest.size == 0 @io.puts "=== Global Options" else @io.puts "#{@nest}=== Options" end end |
#program_desc(desc) ⇒ Object
Gives you the program description
20 21 22 23 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 20 def program_desc(desc) @io.puts "== #{File.basename($0)} - #{desc}" @io.puts end |
#switch(name, aliases, desc, long_desc, negetable) ⇒ Object
Gives you a switch in the current context
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 54 def switch(name,aliases,desc,long_desc,negetable) if negetable name = "[no-]#{name}" if name.length > 1 aliases = aliases.map { |_| _.length > 1 ? "[no-]#{_}" : _ } end @io.puts "#{@nest}=== #{add_dashes(name)}" @io.puts String(desc).strip @io.puts @io.puts "[Aliases] #{aliases.map { |_| add_dashes(_) }.join(',')}\n" unless aliases.empty? @io.puts @io.puts String(long_desc).strip @io.puts end |
#version(version) ⇒ Object
Gives you the program version
26 27 28 29 |
# File 'lib/gli/commands/rdoc_document_listener.rb', line 26 def version(version) @io.puts "v#{version}" @io.puts end |