bin/nephos-generator in nephos-server-0.1.2 vs bin/nephos-generator in nephos-server-0.1.3
- old
+ new
@@ -43,21 +43,30 @@
File.write "Gemfile", GEMFILE
Dir.mkdir "controllers"
exec("bundle install")
end
-case ARGV[0]
-when "c", "controller"
- if not ARGV[1].to_s.empty?
- generate_controller("#{ARGV[1]}Controller", "src/#{ARGV[1]}.rb")
+require 'optparse'
+
+begin
+ OptionParser.new do |opts|
+ opts.banner = "Usage: nephos-generator [controller name] [appli [name]]"
+ end.parse!
+
+ case ARGV[0]
+ when "c", "controller"
+ if not ARGV[1].to_s.match(/[\w_\-\.]+/)
+ generate_controller("#{ARGV[1]}Controller", "src/#{ARGV[1]}.rb")
+ end
+ when "a", "appli", "application"
+ if not ARGV[1].to_s.empty?
+ create_application_dir(ARGV[1])
+ puts "Application #{ARGV[1]} created"
+ move_to_application_dir(ARGV[1])
+ end
+ initialize_application
+ puts "Application initialized"
end
-when "a", "appli", "application"
- if not ARGV[1].to_s.empty?
- create_application_dir(ARGV[1])
- puts "Application #{ARGV[1]} created"
- move_to_application_dir(ARGV[1])
- end
- initialize_application
- puts "Application initialized"
-else
- puts "help: generate c[ontroller] name"
+
+rescue => err
+ puts "Error: #{err.message}"
end