This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
env.rb
78 lines (64 loc) · 2.13 KB
/
env.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "cf/cli/app/base"
module CF::App
class Env < Base
VALID_ENV_VAR = /^[a-zA-Za-z_][[:alnum:]_]*$/
desc "Show all environment variables set for an app"
group :apps, :info, :hidden => true
input :app, :desc => "Application to inspect the environment of",
:argument => true, :from_given => by_name(:app)
def env
app = input[:app]
vars =
with_progress("Getting env for #{c(app.name, :name)}") do |s|
app.env
end
line unless quiet?
vars.each do |name, val|
line "#{c(name, :name)}: #{val}"
end
end
desc "Set an environment variable"
group :apps, :info, :hidden => true
input :app, :desc => "Application to set the variable for",
:argument => true, :from_given => by_name(:app)
input :name, :desc => "Variable name", :argument => true
input :value, :desc => "Variable value", :argument => :optional
input :restart, :desc => "Restart app after updating?", :default => true
def set_env
app = input[:app]
name = input[:name]
if value = input[:value]
name = input[:name]
elsif name["="]
name, value = name.split("=")
end
unless name =~ VALID_ENV_VAR
fail "Invalid variable name; must match #{VALID_ENV_VAR.inspect}"
end
with_progress("Updating #{c(app.name, :name)}") do
app.env[name] = value
app.update!
end
if app.started? && input[:restart]
invoke :restart, :app => app
end
end
desc "Remove an environment variable"
group :apps, :info, :hidden => true
input :app, :desc => "Application to set the variable for",
:argument => true, :from_given => by_name(:app)
input :name, :desc => "Variable name", :argument => true
input :restart, :desc => "Restart app after updating?", :default => true
def unset_env
app = input[:app]
name = input[:name]
with_progress("Updating #{c(app.name, :name)}") do
app.env.delete(name)
app.update!
end
if app.started? && input[:restart]
invoke :restart, :app => app
end
end
end
end