Class: Troy::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/troy/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
16
17
# File 'lib/troy/cli.rb', line 11

def initialize(args = [], options = {}, config = {})
  if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
    raise Error, "The site path is required. For details run: troy help new"
  end

  super
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/troy/cli.rb', line 7

def self.exit_on_failure?
  true
end

Instance Method Details

#exportObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/troy/cli.rb', line 23

def export
  runner = lambda do
    if options[:assets]
      site.export_assets
      site.export_files
    end

    options[:file]&.each do |file|
      site.export_pages(file)
    end

    site.export if !options[:assets] && !options[:file]
  end

  if options[:benchmark]
    require "benchmark"
    elapsed = Benchmark.realtime(&runner)
    puts "=> Finished in #{elapsed.round(2)}s"
  else
    runner.call
  end
end

#new(path) ⇒ Object



47
48
49
50
51
# File 'lib/troy/cli.rb', line 47

def new(path)
  generator = Generator.new
  generator.destination_root = path
  generator.invoke_all
end

#serverObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/troy/cli.rb', line 62

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]
end

#versionObject



55
56
57
# File 'lib/troy/cli.rb', line 55

def version
  say "Troy #{Troy::VERSION}"
end