Module: NandoInterface
- Defined in:
- lib/nando/interface.rb
Class Method Summary collapse
- .build_command_message(command, description, required_indent) ⇒ Object
- .build_flag_message(flag, description, required_indent) ⇒ Object
- .get_user_function_list ⇒ Object
-
.get_user_input_boolean(message) ⇒ Object
if input is Y/y return true, else return false.
- .multi_line_gets(all_text = '') ⇒ Object
-
.print_help_message ⇒ Object
prints help message.
Class Method Details
.build_command_message(command, description, required_indent) ⇒ Object
51 52 53 54 55 |
# File 'lib/nando/interface.rb', line 51 def self. (command, description, required_indent) = "nando #{command}" indent = " " * (required_indent - .length) return "#{command_message.white.bold}#{indent} #{description}\n" end |
.build_flag_message(flag, description, required_indent) ⇒ Object
57 58 59 60 |
# File 'lib/nando/interface.rb', line 57 def self. (flag, description, required_indent) indent = " " * (required_indent - flag.length) return "#{flag.white.bold}#{indent} #{description}\n" end |
.get_user_function_list ⇒ Object
63 64 65 66 67 |
# File 'lib/nando/interface.rb', line 63 def self.get_user_function_list puts 'Enter the list of functions to add to the current migration: (Enter an empty line to exit)'.bold.magenta input = multi_line_gets return (input.split("\n").each { |line| line.strip! }.reject { |line| line == '' }) || [] end |
.get_user_input_boolean(message) ⇒ Object
if input is Y/y return true, else return false
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/nando/interface.rb', line 77 def self.get_user_input_boolean () puts "\n#{message} (Y/N)".magenta.bold # TODO: review error when not using $stdin (might need to use it above as well) input = $stdin.gets.chomp.downcase.strip if input == 'y' return true else return false end end |
.multi_line_gets(all_text = '') ⇒ Object
69 70 71 72 73 74 |
# File 'lib/nando/interface.rb', line 69 def self.multi_line_gets (all_text = '') until (text = gets) == "\n" all_text << text end return all_text.chomp end |
.print_help_message ⇒ Object
prints help message
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 46 47 48 49 |
# File 'lib/nando/interface.rb', line 4 def self. schema_mig_table = "schema_migrations" # left as a variable, might fill this value dynamically later = '' += "Usage: nando <command> [options]\n\n" # commands commands = [ ['up', "Executes all the migrations that are not yet on the #{schema_mig_table.white.bold} table"], ['down', "Rollbacks the last migration in the #{schema_mig_table.white.bold} table"], ['apply <version>', "Applies the migration with the specified version (even if it was already executed). Intended for development, not production"], ['new <migration name>', "Creates a new migration with the specified name. Use the #{"-t/--type".white.bold} flag to specify the type of migration: #{"[Migration|MigrationWithoutTransaction]".white.bold}"], ['parse <source> <destination>', "Parses all the #{"dbmate".white.bold} migrations in the source folder into #{"Nando".white.bold} migrations in the destination folder"], ['baseline', "Creates a baseline Nando migration with all the functions currently in the database"], ['update <path to migration>', "Updates the specified migration. Use #{"-f/--function".white.bold} to add one or more functions to the migration file"], ['diff <source> <target>', "Compares 2 schemas in the database and suggests SQL commands to fix any changes found"] ] largest_command = commands.max { |a,b| a[0].length <=> b[0].length } required_indent = "nando #{largest_command[0]}".length += "Commands:\n" for command in commands do += (command[0], command[1], required_indent) end # flags flags = [ ['-t/--type', 'Used to specify the migration type'], ['-f/--function', 'Used to specify which function files to add to a migration'], ['-d/--dry-run', 'Used to prevent the tool from applying migrations and only provide info'], ['-h/--help', 'Shows the help message'] ] largest_flag = flags.max { |a,b| a[0].length <=> b[0].length } required_indent = largest_flag[0].length += "\nFlags:\n" for flag in flags do += (flag[0], flag[1], required_indent) end += "Nando Version (#{Nando::VERSION})" puts end |