Class: DbAgile::Command::Dba
- Inherits:
-
DbAgile::Command
- Object
- DbAgile::Command
- DbAgile::Command::Dba
- Defined in:
- lib/dbagile/command/dba.rb
Overview
Agile SQL databases and tools for database administrators
Usage: dba [–help] [–version]
dba help <subcommand>
dba [--repository=DIR] [--use=DB] [--no-interactive] <subcommand> [OPTIONS] [ARGS]
DbAgile aims at supporting database administrators and developers of database oriented application. Read more about it on blambeau.github.com/dbagile.
Constant Summary
Constants inherited from DbAgile::Command
Instance Attribute Summary collapse
-
#stop_after_options ⇒ Object
Continue after my options.
Attributes inherited from DbAgile::Command
Attributes included from ClassMethods
#description, #summary, #usage
Instance Method Summary collapse
-
#add_options(opt) ⇒ Object
Contribute to options.
-
#commands_by_categ ⇒ Object
Returns commands by category.
-
#invoke_subcommand(requester_file, argv) ⇒ Object
Invokes the subcommand.
-
#show_commands_help(category) ⇒ Object
Show command help for a specific category.
-
#show_long_help ⇒ Object
Shows the long help.
-
#show_short_help ⇒ Object
(also: #show_help)
Shows the short help.
-
#unsecure_run(requester_file, argv) ⇒ Object
Runs the command.
Methods inherited from DbAgile::Command
#category, #check_command, #command_name, #description, #execute_command, #initialize, #normalize_pending_arguments, #options, #run, #set_default_options, #summary, #usage
Methods included from ClassMethods
#build_command_options, #build_me, #category, #command_for, #command_name, #command_name_of, #each_subclass, #inherited, #ruby_method_for, #subclasses
Methods included from Robust
#ambigous_argument_list!, #assumption_error!, #bad_argument_list!, #has_command!, #is_in!, #valid_argument_list!, #valid_read_file!
Methods included from DbAgile::Core::IO::Robustness
#has_database!, #valid_database_name!, #valid_database_uri!, #valid_schema_files!
Constructor Details
This class inherits a constructor from DbAgile::Command
Instance Attribute Details
#stop_after_options ⇒ Object
Continue after my options
17 18 19 |
# File 'lib/dbagile/command/dba.rb', line 17 def @stop_after_options end |
Instance Method Details
#add_options(opt) ⇒ Object
Contribute to options
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dbagile/command/dba.rb', line 20 def (opt) opt.separator nil opt.separator "Options:" opt.on("--repository=DIR", "Use a specific repository (current is #{environment.friendly_repository_path})") do |value| environment.repository_path = value end opt.on("--use=DB", "Use a specific database") do |value| environment.repository.current_db_name = value.to_sym end opt.on("--[no-]interactive", "[Dis-]allow interactive mode") do |value| environment.interactive = value end opt.on("--[no-]backtrace", "Print a backtrace when an error occurs") do |value| environment.show_backtrace = value end opt.on_tail("--help", "Show list of available subcommands") do show_long_help self. = true end opt.on_tail("--version", "Show version") do flush("dba" << " " << DbAgile::VERSION << " (c) 2010, Bernard Lambeau") self. = true end end |
#commands_by_categ ⇒ Object
Returns commands by category
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dbagile/command/dba.rb', line 48 def commands_by_categ return @commands_by_categ if @commands_by_categ @commands_by_categ = Hash.new{|h,k| h[k] = []} Command.subclasses.each do |subclass| next if subclass == Dba name = Command::command_name_of(subclass) command = Command::command_for(name, environment) category = command.category raise "Unknown command category #{category}" unless DbAgile::Command::CATEGORIES.include?(category) @commands_by_categ[category] << command end @commands_by_categ end |
#invoke_subcommand(requester_file, argv) ⇒ Object
Invokes the subcommand
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dbagile/command/dba.rb', line 106 def invoke_subcommand(requester_file, argv) # Command execution if argv.size >= 1 DbAgile::Core::Repository::Builder.new(environment).ensure_repository{ command = has_command!(argv.shift, environment) command.run(requester_file, argv) } else show_long_help end end |
#show_commands_help(category) ⇒ Object
Show command help for a specific category
63 64 65 66 67 |
# File 'lib/dbagile/command/dba.rb', line 63 def show_commands_help(category) commands_by_categ[category].each do |command| flush(.summary_indent + command.command_name.ljust(30) + command.summary.to_s) end end |
#show_long_help ⇒ Object
Shows the long help
78 79 80 81 82 83 84 85 |
# File 'lib/dbagile/command/dba.rb', line 78 def show_long_help show_short_help DbAgile::Command::CATEGORIES.each{|categ| flush DbAgile::Command::CATEGORY_NAMES[categ] show_commands_help(categ) flush "\n" } end |
#show_short_help ⇒ Object Also known as: show_help
Shows the short help
70 71 72 73 74 |
# File 'lib/dbagile/command/dba.rb', line 70 def show_short_help flush flush .summarize flush "\n" end |
#unsecure_run(requester_file, argv) ⇒ Object
Runs the command
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dbagile/command/dba.rb', line 88 def unsecure_run(requester_file, argv) # My own options my_args = [] while argv.first =~ /^--/ my_args << argv.shift end .parse!(my_args) # Invoke sub command unless invoke_subcommand(requester_file, argv) end rescue Exception => ex environment.on_error(self, ex) environment end |