Class: PgOptionsParser
- Inherits:
-
Object
- Object
- PgOptionsParser
- Defined in:
- lib/so2pg.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Parses the command-line arguments into a Hash object.
Class Method Details
.parse(args) ⇒ Object
Parses the command-line arguments into a Hash object. Note that the members of the Hash have the same name as the ActiveRecord parameters (e.g., :host, :database, etc.). This Hash will actually be passed to ActiveRecord for consumption.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/so2pg.rb', line 123 def self.parse(args) = {} opts = OptionParser.new do |opts| opts. = "Imports a StackOverflow data dump into a PostgreSQL database.\nUsage: so2pg [options]\n EOB\n\n opts.on(\"-H\", \"--host HOST\", \"The database host\") do |host|\n options[:host] = host\n end\n\n opts.on(\"-d\", \"--database DBNAME\", \"The name of the database (REQUIRED)\") do |dbname|\n options[:database] = dbname\n end\n\n opts.on(\"-D\", \"--directory DIRECTORY\", \"The data directory path (REQUIRED)\") do |dir|\n options[:dir] = dir\n end\n\n opts.on(\"-u\", \"--user USER\", \"The user name\") do |user|\n options[:username] = user\n end\n\n opts.on(\"-p\", \"--password PASSWORD\", \"The user's password\") do |password|\n options[:password] = password\n end\n\n opts.on(\"-P\", \"--port PORT_NUMBER\", \"The port number\") do |port|\n options[:port] = port\n end\n\n opts.on(\"-O\", \"--include-optionals\", \"Includes optional tables\") do\n options[:optionals] = true\n end\n\n opts.on(\"-R\", \"--include-relationships\", \"Includes table relationships\") do\n options[:relationships] = true\n end\n\n opts.on(\"-h\", \"--help\", \"Show this help screen\") do |help|\n options[:help] = true\n end\n\n end\n\n opts.parse!(args)\n if(options[:help] or !options.has_key? :dir or !options.has_key? :database)\n puts opts.help\n nil\n else\n options\n end\nend\n" |