Module: Command

Defined in:
lib/command.rb,
lib/command/env.rb,
lib/command/types.rb,
lib/command/option.rb,
lib/command/parser.rb,
lib/command/result.rb,
lib/command/version.rb,
lib/command/argument.rb,
lib/command/definition.rb,
lib/command/nofileerror.rb,
lib/command/decoratinghash.rb,
lib/command/nodirectoryerror.rb,
lib/command/filenotfounderror.rb,
lib/command/directorynotfounderror.rb

Defined Under Namespace

Modules: VERSION Classes: Argument, DecoratingHash, Definition, DirectoryNotFoundError, Env, FileNotFoundError, NoDirectoryError, NoFileError, Option, Parser, Result

Constant Summary collapse

Types =
{
  :Virtual   => nil,
  :Boolean   => proc { |v| v =~ /\A(?:true|y(?:es)?)\z/i },
  :String    => proc { |v| v },
  :Integer   => proc { |v| Integer(v) },
  :Octal     => proc { |v| Intever("0#{v}") },
  :Hex       => proc { |v| Integer("0x#{v}") },
  :Float     => proc { |v| Float(v) },
  :File      => proc { |v|
    raise FileNotFoundError, "No such file or directory - #{v}" unless File.exist?(v)
    raise NoFileError, "Not a file - #{v}" unless File.file?(v)
    v
  },
  :Directory => proc { |v|
    raise DirectoryNotFoundError, "No such file or directory - #{v}" unless File.exist?(v)
    raise NoDirectoryError, "Not a directory - #{v}" unless File.directory?(v)
    v
  },
  :Path => proc { |v|
    require 'pathname'
    Pathname.new(v)
  }
}

Class Method Summary collapse

Class Method Details

.define(*args, &block) ⇒ Object



26
27
28
29
# File 'lib/command.rb', line 26

def self.define(*args, &block)
  @main = Definition.new(*args, &block)
  @main
end

.with(argv, &block) ⇒ Object



31
32
33
34
35
# File 'lib/command.rb', line 31

def self.with(argv, &block)
  parser = Parser.new($command, argv)
  parser.instance_eval(&block)
  parser
end