Class: Incline::CLI::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/incline/cli/usage.rb

Overview

Defines the ‘usage’ command for the CLI.

Instance Method Summary collapse

Constructor Details

#initializeUsage

Creates a new ‘usage’ command for the CLI.



11
12
13
# File 'lib/incline/cli/usage.rb', line 11

def initialize

end

Instance Method Details

#runObject

Shows usage information for the application.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/incline/cli/usage.rb', line 17

def run

  commands = Incline::CLI::valid_commands.sort{|a,b| a[0] <=> b[0]}

  msg = ANSI.ansi(:bold) { "Usage: #{$PROGRAM_NAME} command <arguments>" }
  msg += "\nValid Commands:\n"

  commands.each do |(name,klass,params)|
    comment = get_run_comment(klass)
    comment = "(No description)" if comment.to_s.strip == ''
    comment = '    ' + comment.gsub("\n", "\n    ")
    msg += "  #{name}"
    pend = ''
    params.each do |t,p|
      msg += ' '
      if t == :req
        msg += p.to_s
      elsif t == :opt
        msg += '[' + p.to_s
        pend += ']'
      else
        msg += '<...>'
      end
    end
    msg += "\n" + comment + "\n"
  end

  STDOUT.print msg
  msg
end