Class: SqlMigrate::CLI
- Inherits:
-
Object
- Object
- SqlMigrate::CLI
- Defined in:
- lib/sql_migrate/cli.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse(argv) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
15 16 17 |
# File 'lib/sql_migrate/cli.rb', line 15 def initialize @config = Config.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/sql_migrate/cli.rb', line 7 def config @config end |
Class Method Details
.run(argv = ARGV) ⇒ Object
9 10 11 12 13 |
# File 'lib/sql_migrate/cli.rb', line 9 def self.run(argv = ARGV) cli = new cli.parse(argv) cli.execute end |
Instance Method Details
#execute ⇒ Object
43 44 45 46 |
# File 'lib/sql_migrate/cli.rb', line 43 def execute migrator = Migrator.new(config) migrator.migrate end |
#parse(argv) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sql_migrate/cli.rb', line 19 def parse(argv) args = argv.dup = {} OptionParser.new do |opt| opt.version = VERSION opt. = "sql_migrate [options] MIGRATIONS_PATH" opt.on("-h HOST") { |v| [:host] = v } opt.on("-p PORT") { |v| [:port] = v } opt.on("-d DATABASE") { |v| [:database] = v } opt.on("-u USER") { |v| [:user] = v } opt.on("-p PASSWORD") { |v| [:password] = v } opt.on("-v", "--verbose") { |v| [:verbose] = v } opt.on("-n", "--dry-run") { |v| [:dryrun] = v } opt.on("-f CONFIG") { |v| [:config] = v } opt.parse!(args) end load_from_config(.delete(:config)) if .has_key?(:config) config.merge() config.migrations_path = args.first if args.size.positive? args end |