Class: LeapCli::MarkdownDocumentListener
- Defined in:
- lib/leap_cli/markdown_document_listener.rb
Instance Method Summary collapse
- #beginning ⇒ Object
-
#command(name, aliases, desc, long_desc, arg_name, arg_options) ⇒ 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, app) ⇒ MarkdownDocumentListener
constructor
A new instance of MarkdownDocumentListener.
- #options ⇒ Object
-
#program_desc(desc) ⇒ Object
Gives you the program description.
- #program_long_desc(desc) ⇒ Object
-
#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, app) ⇒ MarkdownDocumentListener
Returns a new instance of MarkdownDocumentListener.
14 15 16 17 18 19 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 14 def initialize(,,arguments,app) @io = File.new(File.basename($0) + ".md",'w') @nest = '' @commands = [File.basename($0)] @arg_name_formatter = GLI::Commands::HelpModules::ArgNameFormatter.new end |
Instance Method Details
#beginning ⇒ Object
21 22 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 21 def beginning end |
#command(name, aliases, desc, long_desc, arg_name, arg_options) ⇒ Object
Gives you a command in the current context and creates a new context of this command
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 97 def command(name,aliases,desc,long_desc,arg_name,) @commands.push(name) #@io.puts "#{@nest}## Command: <tt>#{([name] + aliases).join('|')} #{@arg_name_formatter.format(arg_name,arg_options)}</tt>" @io.puts @io.puts "#{@nest}# #{@commands.join ' '} #{@arg_name_formatter.format(arg_name,)}" @io.puts @io.puts String(desc).strip @io.puts @io.puts String(long_desc).strip @nest = "#{@nest}#" end |
#commands ⇒ Object
91 92 93 94 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 91 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
116 117 118 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 116 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
110 111 112 113 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 110 def end_command(name) @nest.gsub!(/\#$/,'') @commands.pop end |
#end_commands ⇒ Object
120 121 122 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 120 def end_commands @nest.gsub!(/\#$/,'') end |
#end_options ⇒ Object
87 88 89 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 87 def #@io.puts "</div>" end |
#ending ⇒ Object
Called when processing has completed
25 26 27 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 25 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
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 60 def flag(name,aliases,desc,long_desc,default_value,arg_name,must_match,type) invocations = ([name] + Array(aliases)).map { |_| add_dashes(_) }.join('|') usage = "#{invocations} #{arg_name || 'arg'}" #@io.puts "#{@nest}## #{usage}" @io.puts "* `#{usage}` " @io.puts String(desc).strip + " " @io.puts String(long_desc).strip + " " if long_desc @io.puts "Default Value: #{default_value || 'None'} " @io.puts "Must Match: #{must_match.to_s} " unless must_match.nil? @io.puts end |
#options ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 47 def #@io.puts "<div class='options'>" @io.puts if @nest.size == 0 @io.puts "# Global Options" else #@io.puts "#{@nest}# Options" @io.puts "**Options**" end @io.puts end |
#program_desc(desc) ⇒ Object
Gives you the program description
30 31 32 33 34 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 30 def program_desc(desc) @io.puts "@title = 'Command Line Reference'" #@io.puts "# #{File.basename($0)} - #{desc}" @io.puts end |
#program_long_desc(desc) ⇒ Object
36 37 38 39 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 36 def program_long_desc(desc) @io.puts desc @io.puts end |
#switch(name, aliases, desc, long_desc, negetable) ⇒ Object
Gives you a switch in the current context
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 73 def switch(name,aliases,desc,long_desc,negetable) if negetable name = "[no-]#{name}" if name.to_s.length > 1 aliases = aliases.map { |_| _.to_s.length > 1 ? "[no-]#{_}" : _ } end invocations = ([name] + aliases).map { |_| add_dashes(_) }.join('|') #@io.puts "#{@nest}## #{invocations}" @io.puts "* `#{invocations}` " @io.puts String(desc).strip + " " #@io.puts #@io.puts String(long_desc).strip @io.puts end |
#version(version) ⇒ Object
Gives you the program version
42 43 44 45 |
# File 'lib/leap_cli/markdown_document_listener.rb', line 42 def version(version) #@io.puts "v#{version}" #@io.puts end |