Class: DbAgile::Command

Inherits:
Object
  • Object
show all
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

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

Instance Method Summary collapse

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
  set_default_options
end

Instance Attribute Details

#environmentObject (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 add_options(opt)
end

#categoryObject

Returns commands category



39
40
41
# File 'lib/dbagile/command.rb', line 39

def category
  self.class.category
end

#check_commandObject

Checks the command



125
126
# File 'lib/dbagile/command.rb', line 125

def check_command
end

#command_nameObject

Returns command name



44
45
46
# File 'lib/dbagile/command.rb', line 44

def command_name
  self.class.command_name
end

#descriptionObject



59
60
61
# File 'lib/dbagile/command.rb', line 59

def description
  self.class.description || ""
end

#execute_commandObject

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

#optionsObject

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
  @options ||= OptionParser.new do |opt|
    opt.program_name = File.basename $0
    opt.version = DbAgile::VERSION
    opt.release = nil
    opt.summary_indent = ' ' * 2
    opt.banner = self.banner
    add_options(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_optionsObject

Sets the default options



80
81
# File 'lib/dbagile/command.rb', line 80

def set_default_options
end

#show_helpObject

Shows the help



92
93
94
95
96
97
# File 'lib/dbagile/command.rb', line 92

def show_help
  display banner
  display ""
  display short_help
  display ""
end

#summaryObject

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 = options.parse!(argv)
  normalize_pending_arguments(rest)
  check_command
  execute_command
end

#usageObject Also known as:

Returns command summary



54
55
56
# File 'lib/dbagile/command.rb', line 54

def usage
  self.class.usage || ""
end