class Msewage::Importer::CLI
Public: Entry point for command line interface
Attributes
options[R]
Public Class Methods
run()
click to toggle source
Public: entry point for class
# File lib/msewage-importer/cli.rb, line 11 def run self.new.setup_and_run end
Public Instance Methods
setup_and_run()
click to toggle source
Public: setup and run
# File lib/msewage-importer/cli.rb, line 17 def setup_and_run setup run end
Private Instance Methods
cli_options()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 86 def cli_options @cli_options ||= GetoptLong.new(*options_possible.map{ |o| o.first(3) }) end
options_possible()
click to toggle source
Private: Command line options
# File lib/msewage-importer/cli.rb, line 41 def options_possible [ ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT, 'Override the configuration file'], ['--help', '-h', GetoptLong::NO_ARGUMENT, 'Show this text'], ['--password', '-p', GetoptLong::REQUIRED_ARGUMENT, 'mSewage.org password'], ['--source', '-s', GetoptLong::REQUIRED_ARGUMENT, 'Source file with data to import'], ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT, 'Type of defecation site sources to import'], ['--types', '-T', GetoptLong::NO_ARGUMENT, 'Show type of defecation sites available'], ['--username', '-u', GetoptLong::REQUIRED_ARGUMENT, 'mSewage.org user name'], ['--verbose', '-v', GetoptLong::NO_ARGUMENT, 'Be extremely verbose'], ['--version', '-V', GetoptLong::NO_ARGUMENT, 'Show version info'], ] end
process_command_line_options()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 56 def process_command_line_options @options = {} cli_options.each do |opt, arg| case opt when '--help' show_help_and_exit when '--config' options[:config_file_path] = arg when '--verbose' options[:verbose] = true when '--version' show_version_info_and_exit when '--types' show_types_and_exit when '--type' options[:type] = arg when '--username' options[:msewage] ||= {} options[:msewage][:username] = arg when '--password' options[:msewage] ||= {} options[:msewage][:password] = arg when '--source' options[:source] = arg end end end
run()
click to toggle source
Private: do some more!
# File lib/msewage-importer/cli.rb, line 36 def run Importer.new(options).import end
setup()
click to toggle source
Private: set up program name and process command line options
# File lib/msewage-importer/cli.rb, line 27 def setup process_command_line_options rescue GetoptLong::MissingArgument, GetoptLong::InvalidOption, GetoptLong::AmbiguousOption puts puts "Run #{program_name} --help to see the available options" exit end
show_help_and_exit()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 118 def show_help_and_exit STDOUT.puts help_info exit end
show_types_and_exit()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 91 def show_types_and_exit puts " " << SourceTypes.types_supported * "\n " exit end
show_version_info_and_exit()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 97 def show_version_info_and_exit puts version_info exit end
version()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 113 def version VERSION end
version_info()
click to toggle source
Private:
# File lib/msewage-importer/cli.rb, line 103 def version_info <<-EOV #{program_name}, version #{version} (c) Juan C. Muller, 2012 http://github.com/jcmuller/msewage-importer EOV end