Class: RRSE::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/rrse/main.rb

Constant Summary collapse

DEFAULT_DIR =
Pathname(ENV["HOME"]) + ".rrse"
SUBCOMMANDS =
{
  "setup-config" => RRSE::Command::SetUpConfig,
  "update-db" => RRSE::Command::UpdateDB,
  "install-default-db" =>  RRSE::Command::InstallDefaultDB,
  "standalone-query" => RRSE::Command::StandaloneQuery,
  "pipe-query" => RRSE::Command::PipeQuery,
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



26
27
28
# File 'lib/rrse/main.rb', line 26

def initialize
  @rrse_dir = DEFAULT_DIR
end

Class Method Details

.show_helpObject



22
23
24
# File 'lib/rrse/main.rb', line 22

def self.show_help
  print(self.new.options.help)
end

Instance Method Details

#list_subcommandObject



56
57
58
59
60
# File 'lib/rrse/main.rb', line 56

def list_subcommand
  SUBCOMMANDS.map{|key, command_class|
    "  #{key.ljust(20)}#{command_class.short_description}"
  }.join("\n")
end

#optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rrse/main.rb', line 30

def options
  opts = OptionParser.new
  opts.program_name = "RRSE"
  opts.version = RRSE::VERSION
  opts.banner = <<EOS
Usage: rrse [global-options] subcommand ...

Subcommands:
#{list_subcommand}

Global Options:
EOS
  opts.on("-d DIR", "rrse directory (default: #{DEFAULT_DIR})") do|dir|
    @rrse_dir = Pathname(dir)
  end
  opts
end

#run(argv) ⇒ Object



48
49
50
51
52
53
# File 'lib/rrse/main.rb', line 48

def run(argv)
  self.options.order!(argv)
  subcommand = argv.shift

  SUBCOMMANDS.fetch(subcommand, RRSE::Command::Unknown).new(@rrse_dir).run(argv)
end