Class: GLI::Commands::RdocDocumentListener

Inherits:
Object
  • Object
show all
Defined in:
lib/gli/commands/rdoc_document_listener.rb

Instance Method Summary collapse

Constructor Details

#initialize(global_options, options, arguments, app) ⇒ RdocDocumentListener

Returns a new instance of RdocDocumentListener.



7
8
9
10
11
# File 'lib/gli/commands/rdoc_document_listener.rb', line 7

def initialize(global_options,options,arguments,app)
  @io = File.new("#{app.exe_name}.rdoc",'w')
  @nest = ''
  @arg_name_formatter = GLI::Commands::HelpModules::ArgNameFormatter.new
end

Instance Method Details

#beginningObject



13
14
# File 'lib/gli/commands/rdoc_document_listener.rb', line 13

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



83
84
85
86
87
88
89
# File 'lib/gli/commands/rdoc_document_listener.rb', line 83

def command(name,aliases,desc,long_desc,arg_name,arg_options)
  @io.puts "#{@nest}=== Command: <tt>#{([name] + aliases).join('|')} #{@arg_name_formatter.format(arg_name,arg_options)}</tt>"
  @io.puts String(desc).strip
  @io.puts 
  @io.puts String(long_desc).strip
  @nest = "#{@nest}="
end

#commandsObject



77
78
79
80
# File 'lib/gli/commands/rdoc_document_listener.rb', line 77

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



97
98
99
# File 'lib/gli/commands/rdoc_document_listener.rb', line 97

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



92
93
94
# File 'lib/gli/commands/rdoc_document_listener.rb', line 92

def end_command(name)
  @nest.gsub!(/=$/,'')
end

#end_commandsObject



101
102
103
# File 'lib/gli/commands/rdoc_document_listener.rb', line 101

def end_commands
  @nest.gsub!(/=$/,'')
end

#end_optionsObject



74
75
# File 'lib/gli/commands/rdoc_document_listener.rb', line 74

def end_options
end

#endingObject

Called when processing has completed



17
18
19
# File 'lib/gli/commands/rdoc_document_listener.rb', line 17

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



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gli/commands/rdoc_document_listener.rb', line 47

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
  @io.puts String(desc).strip
  @io.puts
  @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

#optionsObject



38
39
40
41
42
43
44
# File 'lib/gli/commands/rdoc_document_listener.rb', line 38

def options
  if @nest.size == 0
    @io.puts "=== Global Options"
  else
    @io.puts "#{@nest}=== Options"
  end
end

#program_desc(desc) ⇒ Object

Gives you the program description



22
23
24
25
# File 'lib/gli/commands/rdoc_document_listener.rb', line 22

def program_desc(desc)
  @io.puts "== #{@app.exe_name} - #{desc}"
  @io.puts
end

#program_long_desc(desc) ⇒ Object



27
28
29
30
# File 'lib/gli/commands/rdoc_document_listener.rb', line 27

def program_long_desc(desc)
  @io.puts desc
  @io.puts
end

#switch(name, aliases, desc, long_desc, negatable) ⇒ Object

Gives you a switch in the current context



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gli/commands/rdoc_document_listener.rb', line 61

def switch(name,aliases,desc,long_desc,negatable)
  if negatable
    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 String(desc).strip
  @io.puts
  @io.puts String(long_desc).strip
  @io.puts
end

#version(version) ⇒ Object

Gives you the program version



33
34
35
36
# File 'lib/gli/commands/rdoc_document_listener.rb', line 33

def version(version)
  @io.puts "v#{version}"
  @io.puts
end