lib/troy/cli.rb in troy-0.0.35 vs lib/troy/cli.rb in troy-0.0.36

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Troy class Cli < Thor check_unknown_options! def self.exit_on_failure? @@ -23,19 +25,15 @@ if options[:assets] site.export_assets site.export_files end - if options[:file] - options[:file].each do |file| - site.export_pages(file) - end + options[:file]&.each do |file| + site.export_pages(file) end - if !options[:assets] && !options[:file] - site.export - end + site.export if !options[:assets] && !options[:file] end if options[:benchmark] require "benchmark" elapsed = Benchmark.realtime(&runner) @@ -51,30 +49,31 @@ generator.destination_root = path generator.invoke_all end desc "version", "Display Troy version" - map %w(-v --version) => :version + map %w[-v --version] => :version def version say "Troy #{Troy::VERSION}" end desc "server", "Start a server" - option :port, :type => :numeric, :default => 9292, :aliases => "-p" - option :host, :type => :string, :default => "0.0.0.0", :aliases => "-b" + option :port, type: :numeric, default: 9292, aliases: "-p" + option :host, type: :string, default: "0.0.0.0", aliases: "-b" def server begin handler = Rack::Handler::Thin Thin::Logging.level = Logger::DEBUG rescue Exception handler = Rack::Handler::WEBrick end - handler.run Troy::Server.new(File.join(Dir.pwd, "public")), :Port => options[:port], :Host => options[:host] + handler.run Troy::Server.new(File.join(Dir.pwd, "public")), Port: options[:port], Host: options[:host] end - private - def site - @site ||= Troy::Site.new(Dir.pwd, options) + no_commands do + def site + @site ||= Troy::Site.new(Dir.pwd, options) + end end end end