Class: Rouge::CLI

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

Direct Known Subclasses

Help, Highlight, List, Style, Version

Defined Under Namespace

Classes: Error, Help, Highlight, List, Style, Version

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.


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

def initialize(options={})
end

Class Method Details

.class_from_arg(arg) ⇒ Object


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rouge/cli.rb', line 88

def self.class_from_arg(arg)
  case arg
  when 'version', '--version', '-v'
    Version
  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...]|)

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

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 %|	version		#{Version.desc}|
  yield %||
  yield %|See `rougify help <command>` for more info.|
end

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

Raises:


80
81
82
# File 'lib/rouge/cli.rb', line 80

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

.normalize_syntax(argv) ⇒ Object


379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/rouge/cli.rb', line 379

def self.normalize_syntax(argv)
  out = []
  argv.each do |arg|
    case arg
    when /^(--\w+)=(.*)$/
      out << $1 << $2
    when /^(-\w)(.+)$/
      out << $1 << $2
    else
      out << arg
    end
  end

  out
end

.parse(argv = ARGV) ⇒ Object


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

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', nil
    Help.parse(argv)
  else
    argv.unshift(mode) if mode
    Highlight.parse(argv)
  end
end

Instance Method Details

#error!(*a) ⇒ Object


84
85
86
# File 'lib/rouge/cli.rb', line 84

def error!(*a)
  self.class.error!(*a)
end