Class: RRSE::Main
- Inherits:
-
Object
- Object
- RRSE::Main
- 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
-
#initialize ⇒ Main
constructor
A new instance of Main.
- #list_subcommand ⇒ Object
- #options ⇒ Object
- #run(argv) ⇒ Object
Constructor Details
#initialize ⇒ Main
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_help ⇒ Object
22 23 24 |
# File 'lib/rrse/main.rb', line 22 def self.show_help print(self.new..help) end |
Instance Method Details
#list_subcommand ⇒ Object
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 |
#options ⇒ Object
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 opts = OptionParser.new opts.program_name = "RRSE" opts.version = RRSE::VERSION opts. = <<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..order!(argv) subcommand = argv.shift SUBCOMMANDS.fetch(subcommand, RRSE::Command::Unknown).new(@rrse_dir).run(argv) end |