Class: VPS::CLI::Upstream

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

Instance Method Summary collapse

Instance Method Details

#add(host_and_optional_upstream, path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vps/cli/upstream.rb', line 6

def add(host_and_optional_upstream, path)
  host, name = host_and_optional_upstream.split(":")
  config = VPS.read_config(host)
  path = File.expand_path(path)

  unless config[:upstreams].any?{|upstream| upstream[:name] == name}
    spec = derive_upstream(path)
    config[:upstreams].push(spec.merge({
      :name => name || File.basename(path),
      :path => path
    }))
    VPS.write_config(host, config)
  end
end

#list(host) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/vps/cli/upstream.rb', line 37

def list(host)
  config = VPS.read_config(host)

  upstreams = config[:upstreams].collect do |upstream|
    "* #{upstream[:name]} (#{upstream[:path].gsub(Dir.home, "~")})"
  end.sort

  puts upstreams
end

#remove(host_and_optional_upstream) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vps/cli/upstream.rb', line 22

def remove(host_and_optional_upstream)
  host, name = host_and_optional_upstream.split(":")
  config = VPS.read_config(host)

  unless name
    list = config[:upstreams].collect{|upstream| upstream[:name]}.sort
    name = list[Ask.list("Which upstream do you want to remove?", list)]
  end

  if config[:upstreams].reject!{|upstream| upstream[:name] == name}
    VPS.write_config(host, config)
  end
end