Class: Piedesaint::CLI

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

Overview

The CLI class encapsulates the behavior of Piedesaint when it is invoked as a command-line utility. This allows other programs to embed Piedesaint and preserve its command-line semantics.

Instance Method Summary collapse

Constructor Details

#initializeCLI



16
17
# File 'lib/piedesaint/cli.rb', line 16

def initialize
end

Instance Method Details

#asset_provider(parameters = []) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/piedesaint/cli.rb', line 61

def asset_provider ( parameters = [] )
  load_config
  asset_provider_helper_vagrantfile = parameters[0] || "chef_vagrant"
  asset_provider_config = parameters[1] || File.join("kitchen", "nodes", "vagrant.json")
  @config[:asset_provider_helper_vagrantfile] = asset_provider_helper_vagrantfile
  @config[:asset_provider_config] = asset_provider_config
  save_config @config
end

#executeObject



19
20
21
22
23
24
25
# File 'lib/piedesaint/cli.rb', line 19

def execute
  load_config
  cert( resolve_host(@config[:host]) ) if @config[:refresh_cert]
  refresh_asset_provider if @config[:refresh_asset_provider]
  piedesanto = Piedesaint.new @config
  piedesanto.start
end

#init(parameters = []) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/piedesaint/cli.rb', line 27

def init ( parameters = [] )
  if File.exist?(".piedesaint")
    abort "Configuration already exists at #{Dir.pwd}/.piedesaint"
  end

  config = { iface: "0.0.0.0",
              http_port: 8080,
              https_port: 9292,
              refresh_cert: true,
              host: "localhost",
              key: File.join(".", ".piedesaint", "ssl", "server.key" ),
              cert: File.join(".", ".piedesaint", "ssl", "server.crt" ),
              username: "user",
              password: "password",
              asset_provider_config: "",
              asset_provider_helper_vagrantfile: "",
              refresh_asset_provider: true,
              freshness: 3600,
              metastore: 'file:/tmp/rack/meta',
              entitystore: 'file:/tmp/rack/body',
              tar: true,
              folders: parameters }
  save_config config
  cert
  puts "Configuration created at #{Dir.pwd}/.piedesaint"
end

#set_host(host = []) ⇒ Object



54
55
56
57
58
59
# File 'lib/piedesaint/cli.rb', line 54

def set_host ( host = [] )
  load_config
  @config[:host] = host[0]
  save_config @config
  cert( resolve_host(@config[:host]) )
end