bin/spire in spire-0.3.0 vs bin/spire in spire-0.3.2
- old
+ new
@@ -2,18 +2,22 @@
require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
- opts.banner = "Usage: spire create app"
+ opts.banner = "Usage: spire -c app"
opts.on('-h', '--help', 'Displays this usage screen') do
puts optparse
exit
end
+
+ opts.on('-g', '--generate controller', 'Generates a new view controller') do |params|
+ options[:generate] = params
+ end
- opts.on('-c', '-create DIR', 'Creates a new app/project with given name.') do |params|
+ opts.on('-c', '--create project', 'Creates a new app/project with given name.') do |params|
options[:create] = params
end
end
@@ -22,12 +26,33 @@
rescue OptionParser::InvalidOption
puts optparse
exit 1
end
+if options[:generate]
+
+ if File.directory? 'app/controllers'
+ controller_value = options[:generate].capitalize
+ puts "Generating..."
+ controller = File.new("app/controllers/#{controller_value}Controller.rb", "w+")
+ if controller
+ controller.write("class #{controller_value} < Spire::MainController \n\t def index \n\t \t render :text => 'Hello, new controller!' \n\t end \nend
+ ")
+ controller.close
+ puts "Created controller file: #{controller_value}Controller in app/controllers/"
+ else
+ puts "No file made, file could not be created for writing."
+ end
+ else
+ puts "No app folder found to create a controller."
+ end
+end
+
if options[:create]
unless Dir.exists?(options[:create])
system("git clone git://github.com/snicol/spire-base-app.git #{options[:create]}")
end
-else
- puts "No arguments given!"
+end
+
+unless options[:create] or options[:generate]
+ puts "No arguments given. See `spire -h' for documentation."
end
\ No newline at end of file