class Rouge::CLI

Public Class Methods

class_from_arg(arg) click to toggle source
# File lib/rouge/cli.rb, line 98
def self.class_from_arg(arg)
  case arg
  when 'version', '--version', '-v'
    Version
  when 'help', nil
    Help
  when 'highlight', 'hi'
    Highlight
  when 'style'
    Style
  when 'list'
    List
  when 'guess'
    Guess
  end
end
doc() { |%|usage: rougify {global options} [command] [args...]|| ... } click to toggle source
# File lib/rouge/cli.rb, line 39
def self.doc
  return enum_for(:doc) unless block_given?

  yield %|usage: rougify {global options} [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 %|  guess            #{Guess.desc}|
  yield %|  version          #{Version.desc}|
  yield %||
  yield %|global options:|
  yield %[  --require|-r <fname>     require <fname> after loading rouge]
  yield %||
  yield %|See `rougify help <command>` for more info.|
end
error!(msg, status=1) click to toggle source
# File lib/rouge/cli.rb, line 90
def self.error!(msg, status=1)
  raise Error.new(msg, status)
end
new(options={}) click to toggle source
# File lib/rouge/cli.rb, line 87
def initialize(options={})
end
parse(argv=ARGV) click to toggle source
# File lib/rouge/cli.rb, line 66
def self.parse(argv=ARGV)
  argv = normalize_syntax(argv)

  while (head = argv.shift)
    case head
    when '-h', '--help', 'help', '-help'
      return Help.parse(argv)
    when '--require', '-r'
      require argv.shift
    else
      break
    end
  end

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

  argv.unshift(head) if head
  Highlight.parse(argv)
end

Private Class Methods

normalize_syntax(argv) click to toggle source
# File lib/rouge/cli.rb, line 481
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

Public Instance Methods

error!(*a) click to toggle source
# File lib/rouge/cli.rb, line 94
def error!(*a)
  self.class.error!(*a)
end