lib/flare_up/cli.rb in flare-up-0.9 vs lib/flare_up/cli.rb in flare-up-0.10

- old
+ new

@@ -17,10 +17,11 @@ begin CLI.env_validator(boot_options, :aws_access_key, 'AWS_ACCESS_KEY_ID') CLI.env_validator(boot_options, :aws_secret_key, 'AWS_SECRET_ACCESS_KEY') CLI.env_validator(boot_options, :redshift_username, 'REDSHIFT_USERNAME') CLI.env_validator(boot_options, :redshift_password, 'REDSHIFT_PASSWORD') + CLI.env_validator(boot_options, :redshift_port, 'REDSHIFT_PORT', 5439) rescue ArgumentError => e Emitter.error(e.message) CLI.bailout(1) end @@ -35,10 +36,11 @@ } all_shared_options = [ [:redshift_username, { :type => :string, :desc => "Required unless ENV['REDSHIFT_USERNAME'] is set." }], [:redshift_password, { :type => :string, :desc => "Required unless ENV['REDSHIFT_PASSWORD'] is set." }], + [:redshift_port, { :type => :numeric, :desc => "Optional (defaults to 5439)" }], [:colorize_output, { :type => :boolean, :desc => 'Should Flare-up colorize its output?', :default => true }] ] copy_options = [ [:aws_access_key, { :type => :string, :desc => "Required unless ENV['AWS_ACCESS_KEY_ID'] is set." }], [:aws_secret_key, { :type => :string, :desc => "Required unless ENV['AWS_SECRET_ACCESS_KEY'] is set." }], @@ -87,26 +89,37 @@ #{long_desc_footer} LONGDESC all_shared_options.each { |shared_options| method_option *shared_options } alias_method :drop_table, :no_datasource_command + ### truncate command + + desc 'truncate REDSHIFT_ENDPOINT DATABASE TABLE', 'TRUNCATE DATABASE.TABLE in REDSHIFT_ENDPOINT' + long_desc <<-LONGDESC +`flare-up truncate` executes the Redshift TRUNCATE command, deleting all rows the table named TABLE\x5 +in DATABASE_NAME at REDSHIFT_ENDPOINT. +#{long_desc_footer} + LONGDESC + all_shared_options.each { |shared_options| method_option *shared_options } + alias_method :truncate, :no_datasource_command + # transforms the symbol method names to the corresponding class under # the FlareUp::Command namespace def self.command_formatter(sym) name = sym.to_s.split('_').map(&:capitalize).join # Ruby 1.9.3 cannot handle const_get for nested Classes (Ruby 2.0 can). "FlareUp::Command::#{name}".split("::").reduce(Object) { |a, e| a.const_get e } end - def self.env_validator(options, option_name, env_variable_name) - options[option_name] ||= ENVWrap.get(env_variable_name) + def self.env_validator(options, option_name, env_variable_name, default_value=nil) + options[option_name] ||= (ENVWrap.get(env_variable_name) || default_value) return if options[option_name] raise ArgumentError, "One of either the --#{option_name} option or the ENV['#{env_variable_name}'] must be set" end def self.bailout(exit_code) exit(exit_code) end end -end \ No newline at end of file +end