class LeapCli::MarkdownDocumentListener

Public Class Methods

new(global_options,options,arguments,app) click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 14
def initialize(global_options,options,arguments,app)
  @io = File.new(File.basename($0) + ".md",'w')
  @nest = ''
  @commands = [File.basename($0)]
  @arg_name_formatter = GLI::Commands::HelpModules::ArgNameFormatter.new
end

Public Instance Methods

beginning() click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 21
def beginning
end
command(name,aliases,desc,long_desc,arg_name,arg_options) click to toggle source

Gives you a command in the current context and creates a new context of this command

# File lib/leap_cli/markdown_document_listener.rb, line 99
def command(name,aliases,desc,long_desc,arg_name,arg_options)
  @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, arg_options, [])}"
  @io.puts
  @io.puts String(desc).strip
  @io.puts
  @io.puts String(long_desc).strip
  @nest = "#{@nest}#"
end
commands() click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 93
def commands
  #@io.puts "#{@nest}## Commands"
  #@nest = "#{@nest}#"
end
default_command(name) click to toggle source

Gives you the name of the current command in the current context

# File lib/leap_cli/markdown_document_listener.rb, line 118
def default_command(name)
  @io.puts "Default Command: #{name}" unless name.nil?
end
end_command(name) click to toggle source

Ends a command, and “pops” you back up one context

# File lib/leap_cli/markdown_document_listener.rb, line 112
def end_command(name)
  @nest.gsub!(/\#$/,'')
  @commands.pop
end
end_commands() click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 122
def end_commands
  @nest.gsub!(/\#$/,'')
end
end_options() click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 89
def end_options
  #@io.puts "</div>"
end
ending() click to toggle source

Called when processing has completed

# 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) click to toggle source

Gives you a flag in the current context

# File lib/leap_cli/markdown_document_listener.rb, line 62
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() click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 49
def options
  #@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) click to toggle source

Gives you the program description

# File lib/leap_cli/markdown_document_listener.rb, line 30
def program_desc(desc)
  @io.puts "@title = 'Command Line Reference'"
  @io.puts "@summary = 'A copy of leap --help'"

  #@io.puts "# #{File.basename($0)} - #{desc}"
  @io.puts
end
program_long_desc(desc) click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 38
def program_long_desc(desc)
  @io.puts desc
  @io.puts
end
switch(name,aliases,desc,long_desc,negetable) click to toggle source

Gives you a switch in the current context

# File lib/leap_cli/markdown_document_listener.rb, line 75
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) click to toggle source

Gives you the program version

# File lib/leap_cli/markdown_document_listener.rb, line 44
def version(version)
  #@io.puts "v#{version}"
  #@io.puts
end

Private Instance Methods

add_dashes(name) click to toggle source
# File lib/leap_cli/markdown_document_listener.rb, line 128
def add_dashes(name)
  name = "-#{name}"
  name = "-#{name}" if name.length > 2
  name
end