lib/prez/start.rb in prez-0.0.6 vs lib/prez/start.rb in prez-0.1.0
- old
+ new
@@ -1,30 +1,28 @@
require "launchy"
-require "prez/builder"
-require "prez/error"
require "thor/actions"
require "thor/group"
require "webrick"
module Prez
class Start < Thor::Group
include Thor::Actions
include Prez::Builder
- argument :name, type: :string
+ argument :name, type: :string, required: false, default: nil
class_option :server, type: :boolean, desc: "Keep the server up for dynamic refreshes"
def check_file!
- if File.exists? name
- @filename = name
- elsif File.exists? "#{name}.prez"
- @filename = "#{name}.prez"
+ if File.exists? prez_name
+ @filename = prez_name
+ elsif File.exists? "#{prez_name}.prez"
+ @filename = "#{prez_name}.prez"
else
- raise Prez::Error.new("Missing prez file '#{name}'")
+ raise Prez::Error.new("Missing prez file '#{prez_name}'")
end
if filename =~ /\.html$/
- raise Prez::Error.new("Prez file cannot be an html file: '#{name}'")
+ raise Prez::Error.new("Prez file cannot be an html file: '#{prez_name}'")
end
end
def generate_html
return if options[:server]
@@ -66,9 +64,25 @@
end
end
end
private
+
+ def prez_name
+ @prez_name = name || only_existing_prez
+ end
+
+ def only_existing_prez
+ results = Dir.glob "*.prez"
+
+ if results.empty?
+ raise Prez::Error.new("No .prez files found!")
+ elsif results.size > 1
+ raise Prez::Error.new("More than one .prez file found!\nPlease specify which one you want to start.")
+ end
+
+ results.first
+ end
def stop_server
say "Shutting down server..."
@server.shutdown
end