Class: Rouge::CLI

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

Direct Known Subclasses

Help, Highlight, List, Style

Defined Under Namespace

Classes: Error, Help, Highlight, List, Style

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.


74
75
# File 'lib/rouge/cli.rb', line 74

def initialize(options={})
end

Class Method Details

.class_from_arg(arg) ⇒ Object


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rouge/cli.rb', line 81

def self.class_from_arg(arg)
  case arg
  when 'help'
    Help
  when 'highlight', 'hi'
    Highlight
  when 'style'
    Style
  when 'list'
    List
  end
end

.doc {|%|usage: rougify [command] [args...]|| ... } ⇒ Object

Yields:

  • (%|usage: rougify [command] [args...]|)

35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rouge/cli.rb', line 35

def self.doc
  return enum_for(:doc) unless block_given?

  yield %|usage: rougify [command] [args...]|
  yield %||
  yield %|where <command> is one of:|
  yield %|	highlight	#{Highlight.desc}|
  yield %|	help		#{Help.desc}|
  yield %|	style		#{Style.desc}|
  yield %|	list		#{List.desc}|
  yield %||
  yield %|See `rougify help <command>` for more info.|
end

.parse(argv = ARGV) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rouge/cli.rb', line 57

def self.parse(argv=ARGV)
  argv = normalize_syntax(argv)

  mode = argv.shift

  klass = class_from_arg(mode)
  return klass.parse(argv) if klass

  case mode
  when '-h', '--help', 'help', '-help'
    Help.parse(argv)
  else
    argv.unshift(mode) if mode
    Highlight.parse(argv)
  end
end

Instance Method Details

#error!(msg, status = 1) ⇒ Object

Raises:


77
78
79
# File 'lib/rouge/cli.rb', line 77

def error!(msg, status=1)
  raise Error.new(msg, status)
end