Class: Troy::Cli
- Inherits:
-
Thor
- Object
- Thor
- Troy::Cli
- Defined in:
- lib/troy/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(args = [], options = {}, config = {}) ⇒ Cli
constructor
A new instance of Cli.
- #new(path) ⇒ Object
- #server ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ Cli
Returns a new instance of Cli.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/troy/cli.rb', line 11 def initialize(args = [], = {}, config = {}) has_error = (config[:current_task] || config[:current_command]).name == "new" && args.empty? if has_error raise Error, "The site path is required. For details run: troy help new" end super end |
Class Method Details
.exit_on_failure? ⇒ Boolean
7 8 9 |
# File 'lib/troy/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#export ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/troy/cli.rb', line 27 def export runner = lambda do if [:assets] site.export_assets site.export_files end [:file]&.each do |file| site.export_pages(file) end site.export if ![:assets] && ![:file] end if [:benchmark] require "benchmark" elapsed = Benchmark.realtime(&runner) puts "=> Finished in #{elapsed.round(2)}s" else runner.call end end |
#new(path) ⇒ Object
51 52 53 54 55 |
# File 'lib/troy/cli.rb', line 51 def new(path) generator = Generator.new generator.destination_root = path generator.invoke_all end |
#server ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/troy/cli.rb', line 66 def server begin handler = Rackup::Handler.pick(%i[puma thin webrick]) rescue StandardError raise Error, "No Rack handler found. Install a Rack handler " \ "(e.g. puma, thing, webrick)" end handler.run Troy::Server.new(File.join(Dir.pwd, "public")), Port: [:port], Host: [:host] end |