In Files

Parent

Class/Module Index [+]

Quicksearch

Rouge::CLI

Public Class Methods

class_from_arg(arg) click to toggle source
# File lib/rouge/cli.rb, line 86
def self.class_from_arg(arg)
  case arg
  when 'version', '--version'
    Version
  when 'help'
    Help
  when 'highlight', 'hi'
    Highlight
  when 'style'
    Style
  when 'list'
    List
  end
end
doc() click to toggle source
# 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 %|  version          #{Version.desc}|
  yield %||
  yield %|See `rougify help <command>` for more info.|
end

class Error < StandardError
  attr_reader :message, :status
  def initialize(message, status=1)
    @message = message
    @status = status
  end
end

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

def initialize(options={})
end

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

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

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

class Version < CLI
  def self.desc
    "print the rouge version number"
  end

  def self.parse(*); new; end

  def run
    puts Rouge.version
  end
end

class Help < CLI
  def self.desc
    "print help info"
  end

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

    yield %|usage: rougify help <command>|
    yield %||
    yield %|print help info for <command>.|
  end

  def self.parse(argv)
    opts = { :mode => CLI }
    until argv.empty?
      arg = argv.shift
      klass = class_from_arg(arg)
      if klass
        opts[:mode] = klass
        next
      end
    end
    new(opts)
  end

  def initialize(opts={})
    @mode = opts[:mode]
  end

  def run
    @mode.doc.each(&method(:puts))
  end
end
error!(msg, status=1) click to toggle source
# File lib/rouge/cli.rb, line 78
def self.error!(msg, status=1)
  raise Error.new(msg, status)
end
new(options={}) click to toggle source
# File lib/rouge/cli.rb, line 75
def initialize(options={})
end
parse(argv=ARGV) click to toggle source
# File lib/rouge/cli.rb, line 58
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

Public Instance Methods

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.