Class: DbAgile::Command
- Inherits:
-
Object
- Object
- DbAgile::Command
- Extended by:
- ClassMethods
- Includes:
- Robust, Environment::Delegator
- Defined in:
- lib/dbagile/command.rb,
lib/dbagile/command/api.rb,
lib/dbagile/command/dba.rb,
lib/dbagile/command/help.rb,
lib/dbagile/command/db/rm.rb,
lib/dbagile/command/db/add.rb,
lib/dbagile/command/db/use.rb,
lib/dbagile/command/robust.rb,
lib/dbagile/command/db/list.rb,
lib/dbagile/command/db/ping.rb,
lib/dbagile/command/db/stage.rb,
lib/dbagile/command/sql/drop.rb,
lib/dbagile/command/sql/send.rb,
lib/dbagile/command/sql/show.rb,
lib/dbagile/command/web/tools.rb,
lib/dbagile/command/bulk/export.rb,
lib/dbagile/command/bulk/import.rb,
lib/dbagile/command/repo/create.rb,
lib/dbagile/command/schema/diff.rb,
lib/dbagile/command/schema/dump.rb,
lib/dbagile/command/sql/heading.rb,
lib/dbagile/command/bulk/commons.rb,
lib/dbagile/command/schema/check.rb,
lib/dbagile/command/schema/merge.rb,
lib/dbagile/command/class_methods.rb,
lib/dbagile/command/schema/commons.rb,
lib/dbagile/command/schema/sql_script.rb
Direct Known Subclasses
Bulk::Export, Bulk::Import, Db::Add, Db::List, Db::Ping, Db::Rm, Db::Stage, Db::Use, Dba, Help, Repo::Create, SQL::Drop, SQL::Heading, SQL::Send, SQL::Show, Schema::Check, Schema::Diff, Schema::Dump, Schema::Merge, Schema::SqlScript, Web::Tools
Defined Under Namespace
Modules: Bulk, ClassMethods, Db, Repo, Robust, SQL, Schema, Web Classes: API, Dba, Help
Constant Summary collapse
- CATEGORIES =
Command categories
[:dba, :repo, :db, :sql, :schema, :bulk, :web]
- CATEGORY_NAMES =
Names of the categories
{ :dba => "Main commands:", :repo => "Repository management:", :db => "Database management:", :bulk => "Import/Export management:", :sql => "SQL:", :schema => "Database schema:", :web => "Database and the web:" }
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Command execution environment.
Instance Method Summary collapse
-
#add_options(opt) ⇒ Object
Contribute to options.
-
#category ⇒ Object
Returns commands category.
-
#check_command ⇒ Object
Checks the command.
-
#command_name ⇒ Object
Returns command name.
- #description ⇒ Object
-
#execute_command ⇒ Object
Executes the command.
-
#initialize(env) ⇒ Command
constructor
Creates an empty command instance.
-
#normalize_pending_arguments(arguments) ⇒ Object
Normalizes the pending arguments.
-
#options ⇒ Object
Parses commandline options provided as an array of Strings.
-
#run(requester_file, argv) ⇒ Object
Runs the command.
-
#set_default_options ⇒ Object
Sets the default options.
-
#show_help ⇒ Object
Shows the help.
-
#summary ⇒ Object
Returns command summary.
-
#unsecure_run(requester_file, argv) ⇒ Object
Runs the command without catching any error.
-
#usage ⇒ Object
(also: #banner)
Returns command summary.
Methods included from ClassMethods
build_command_options, build_me, command_for, 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
#initialize(env) ⇒ Command
Creates an empty command instance
33 34 35 36 |
# File 'lib/dbagile/command.rb', line 33 def initialize(env) @environment = env end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Command execution environment
30 31 32 |
# File 'lib/dbagile/command.rb', line 30 def environment @environment end |
Instance Method Details
#add_options(opt) ⇒ Object
Contribute to options
84 85 |
# File 'lib/dbagile/command.rb', line 84 def (opt) end |
#category ⇒ Object
Returns commands category
39 40 41 |
# File 'lib/dbagile/command.rb', line 39 def category self.class.category end |
#check_command ⇒ Object
Checks the command
125 126 |
# File 'lib/dbagile/command.rb', line 125 def check_command end |
#command_name ⇒ Object
Returns command name
44 45 46 |
# File 'lib/dbagile/command.rb', line 44 def command_name self.class.command_name end |
#description ⇒ Object
59 60 61 |
# File 'lib/dbagile/command.rb', line 59 def description self.class.description || "" end |
#execute_command ⇒ Object
Executes the command
129 130 |
# File 'lib/dbagile/command.rb', line 129 def execute_command end |
#normalize_pending_arguments(arguments) ⇒ Object
Normalizes the pending arguments
120 121 122 |
# File 'lib/dbagile/command.rb', line 120 def normalize_pending_arguments(arguments) bad_argument_list!(arguments) unless arguments.empty? end |
#options ⇒ Object
Parses commandline options provided as an array of Strings.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dbagile/command.rb', line 68 def @options ||= OptionParser.new do |opt| opt.program_name = File.basename $0 opt.version = DbAgile::VERSION opt.release = nil opt.summary_indent = ' ' * 2 opt. = self. (opt) end end |
#run(requester_file, argv) ⇒ Object
Runs the command
104 105 106 107 108 109 |
# File 'lib/dbagile/command.rb', line 104 def run(requester_file, argv) unsecure_run(requester_file, argv) rescue Exception => ex environment.on_error(self, ex) environment end |
#set_default_options ⇒ Object
Sets the default options
80 81 |
# File 'lib/dbagile/command.rb', line 80 def end |
#show_help ⇒ Object
Shows the help
92 93 94 95 96 97 |
# File 'lib/dbagile/command.rb', line 92 def show_help display display "" display short_help display "" end |
#summary ⇒ Object
Returns command summary
49 50 51 |
# File 'lib/dbagile/command.rb', line 49 def summary self.class.summary || "" end |
#unsecure_run(requester_file, argv) ⇒ Object
Runs the command without catching any error
112 113 114 115 116 117 |
# File 'lib/dbagile/command.rb', line 112 def unsecure_run(requester_file, argv) rest = .parse!(argv) normalize_pending_arguments(rest) check_command execute_command end |
#usage ⇒ Object Also known as:
Returns command summary
54 55 56 |
# File 'lib/dbagile/command.rb', line 54 def usage self.class.usage || "" end |