cf_script 0.0.1.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +84 -0
- data/Rakefile +33 -0
- data/cf_script.gemspec +34 -0
- data/lib/cf_script/callbacks.rb +43 -0
- data/lib/cf_script/command/base.rb +57 -0
- data/lib/cf_script/command/cf/apps/app.rb +19 -0
- data/lib/cf_script/command/cf/apps/apps.rb +44 -0
- data/lib/cf_script/command/cf/apps/env.rb +20 -0
- data/lib/cf_script/command/cf/apps/push.rb +47 -0
- data/lib/cf_script/command/cf/apps/restage.rb +19 -0
- data/lib/cf_script/command/cf/apps/restart.rb +19 -0
- data/lib/cf_script/command/cf/apps/set_env.rb +18 -0
- data/lib/cf_script/command/cf/apps/start.rb +19 -0
- data/lib/cf_script/command/cf/apps/stop.rb +19 -0
- data/lib/cf_script/command/cf/apps/unset_env.rb +18 -0
- data/lib/cf_script/command/cf/apps.rb +55 -0
- data/lib/cf_script/command/cf/general/api.rb +36 -0
- data/lib/cf_script/command/cf/general/auth.rb +28 -0
- data/lib/cf_script/command/cf/general/login.rb +42 -0
- data/lib/cf_script/command/cf/general/logout.rb +15 -0
- data/lib/cf_script/command/cf/general/target.rb +64 -0
- data/lib/cf_script/command/cf/general.rb +15 -0
- data/lib/cf_script/command/cf/routes/check_route.rb +17 -0
- data/lib/cf_script/command/cf/routes/create_route.rb +19 -0
- data/lib/cf_script/command/cf/routes/delete_route.rb +19 -0
- data/lib/cf_script/command/cf/routes/map_route.rb +30 -0
- data/lib/cf_script/command/cf/routes/routes.rb +40 -0
- data/lib/cf_script/command/cf/routes/unmap_route.rb +30 -0
- data/lib/cf_script/command/cf/routes.rb +17 -0
- data/lib/cf_script/command/cf/spaces/space.rb +36 -0
- data/lib/cf_script/command/cf/spaces/spaces.rb +23 -0
- data/lib/cf_script/command/cf/spaces.rb +9 -0
- data/lib/cf_script/command/error.rb +5 -0
- data/lib/cf_script/command/line.rb +105 -0
- data/lib/cf_script/command/registry.rb +50 -0
- data/lib/cf_script/command/runner.rb +97 -0
- data/lib/cf_script/command.rb +44 -0
- data/lib/cf_script/config.rb +60 -0
- data/lib/cf_script/executor/non_blocking.rb +107 -0
- data/lib/cf_script/executor/recorder.rb +16 -0
- data/lib/cf_script/executor/simple.rb +17 -0
- data/lib/cf_script/executor.rb +5 -0
- data/lib/cf_script/manifest.rb +38 -0
- data/lib/cf_script/object/api_endpoint.rb +10 -0
- data/lib/cf_script/object/app_info.rb +69 -0
- data/lib/cf_script/object/app_list.rb +24 -0
- data/lib/cf_script/object/app_spec.rb +55 -0
- data/lib/cf_script/object/attribute.rb +18 -0
- data/lib/cf_script/object/attribute_list.rb +40 -0
- data/lib/cf_script/object/instance_status.rb +29 -0
- data/lib/cf_script/object/route_info.rb +14 -0
- data/lib/cf_script/object/space.rb +17 -0
- data/lib/cf_script/object/target.rb +23 -0
- data/lib/cf_script/object.rb +24 -0
- data/lib/cf_script/output/buffer.rb +74 -0
- data/lib/cf_script/output/parser/attributes.rb +44 -0
- data/lib/cf_script/output/parser/section.rb +15 -0
- data/lib/cf_script/output/parser/table.rb +46 -0
- data/lib/cf_script/output/parser.rb +15 -0
- data/lib/cf_script/output/tests.rb +51 -0
- data/lib/cf_script/output/utils.rb +13 -0
- data/lib/cf_script/output.rb +62 -0
- data/lib/cf_script/scope/app/env.rb +15 -0
- data/lib/cf_script/scope/app/routes.rb +21 -0
- data/lib/cf_script/scope/app/state.rb +33 -0
- data/lib/cf_script/scope/app/utils.rb +32 -0
- data/lib/cf_script/scope/app.rb +94 -0
- data/lib/cf_script/scope/proxy.rb +36 -0
- data/lib/cf_script/scope/script.rb +59 -0
- data/lib/cf_script/scope/space.rb +9 -0
- data/lib/cf_script/scope/target.rb +90 -0
- data/lib/cf_script/scope.rb +68 -0
- data/lib/cf_script/ui.rb +261 -0
- data/lib/cf_script/utils.rb +19 -0
- data/lib/cf_script/version.rb +3 -0
- data/lib/cf_script.rb +105 -0
- data/test/fixtures/commands/apps/app/good.yml +18 -0
- data/test/fixtures/commands/apps/app/not_found.yml +8 -0
- data/test/fixtures/commands/apps/app/running.yml +19 -0
- data/test/fixtures/commands/apps/apps/good.yml +14 -0
- data/test/fixtures/commands/apps/apps/no_apps.yml +10 -0
- data/test/fixtures/commands/apps/env/empty.yml +37 -0
- data/test/fixtures/commands/apps/env/good.yml +41 -0
- data/test/fixtures/commands/apps/push/good.yml +60 -0
- data/test/fixtures/commands/apps/restage/good.yml +48 -0
- data/test/fixtures/commands/apps/restage/not_found.yml +8 -0
- data/test/fixtures/commands/apps/restart/good.yml +35 -0
- data/test/fixtures/commands/apps/restart/not_found.yml +8 -0
- data/test/fixtures/commands/apps/set_env/empty.yml +5 -0
- data/test/fixtures/commands/apps/set_env/good.yml +9 -0
- data/test/fixtures/commands/apps/set_env/not_found.yml +8 -0
- data/test/fixtures/commands/apps/start/good.yml +32 -0
- data/test/fixtures/commands/apps/start/not_found.yml +8 -0
- data/test/fixtures/commands/apps/start/with_container.yml +98 -0
- data/test/fixtures/commands/apps/stop/good.yml +8 -0
- data/test/fixtures/commands/apps/stop/not_found.yml +8 -0
- data/test/fixtures/commands/apps/unset_env/empty.yml +5 -0
- data/test/fixtures/commands/apps/unset_env/good.yml +9 -0
- data/test/fixtures/commands/apps/unset_env/not_found.yml +8 -0
- data/test/fixtures/commands/common/fail.yml +5 -0
- data/test/fixtures/commands/common/no_endpoint.yml +11 -0
- data/test/fixtures/commands/common/no_login.yml +8 -0
- data/test/fixtures/commands/general/api/bad_argument.yml +9 -0
- data/test/fixtures/commands/general/api/bad_endpoint.yml +9 -0
- data/test/fixtures/commands/general/api/good.yml +7 -0
- data/test/fixtures/commands/general/api/not_set.yml +7 -0
- data/test/fixtures/commands/general/api/set.yml +7 -0
- data/test/fixtures/commands/general/auth/empty.yml +5 -0
- data/test/fixtures/commands/general/auth/good.yml +10 -0
- data/test/fixtures/commands/general/auth/rejected.yml +10 -0
- data/test/fixtures/commands/general/login/good.yml +8 -0
- data/test/fixtures/commands/general/login/rejected.yml +23 -0
- data/test/fixtures/commands/general/logout/good.yml +8 -0
- data/test/fixtures/commands/general/target/empty.yml +5 -0
- data/test/fixtures/commands/general/target/good.yml +11 -0
- data/test/fixtures/commands/general/target/no_space.yml +10 -0
- data/test/fixtures/commands/general/target/not_found.yml +9 -0
- data/test/fixtures/commands/general/target/production.yml +11 -0
- data/test/fixtures/commands/general/target/staging.yml +11 -0
- data/test/fixtures/commands/general/target/staging_org.yml +11 -0
- data/test/fixtures/commands/general/target/test.yml +11 -0
- data/test/fixtures/commands/routes/check_route/good.yml +9 -0
- data/test/fixtures/commands/routes/check_route/no_domain.yml +9 -0
- data/test/fixtures/commands/routes/check_route/no_route.yml +9 -0
- data/test/fixtures/commands/routes/create_route/exists.yml +9 -0
- data/test/fixtures/commands/routes/create_route/good.yml +8 -0
- data/test/fixtures/commands/routes/delete_route/good.yml +8 -0
- data/test/fixtures/commands/routes/delete_route/not_exist.yml +8 -0
- data/test/fixtures/commands/routes/map_route/good.yml +10 -0
- data/test/fixtures/commands/routes/map_route/host_taken.yml +10 -0
- data/test/fixtures/commands/routes/map_route/invalid.yml +9 -0
- data/test/fixtures/commands/routes/map_route/no_app.yml +8 -0
- data/test/fixtures/commands/routes/map_route/no_domain.yml +9 -0
- data/test/fixtures/commands/routes/routes/good.yml +14 -0
- data/test/fixtures/commands/routes/unmap_route/good.yml +8 -0
- data/test/fixtures/commands/routes/unmap_route/no_app.yml +8 -0
- data/test/fixtures/commands/routes/unmap_route/no_domain.yml +9 -0
- data/test/fixtures/commands/spaces/space/empty.yml +5 -0
- data/test/fixtures/commands/spaces/space/good.yml +16 -0
- data/test/fixtures/commands/spaces/space/staging.yml +16 -0
- data/test/fixtures/commands/spaces/spaces/empty.yml +5 -0
- data/test/fixtures/commands/spaces/spaces/good.yml +12 -0
- data/test/lib/cf_script/command/base_test.rb +21 -0
- data/test/lib/cf_script/command/cf/apps/app_test.rb +56 -0
- data/test/lib/cf_script/command/cf/apps/apps_test.rb +81 -0
- data/test/lib/cf_script/command/cf/apps/env_test.rb +55 -0
- data/test/lib/cf_script/command/cf/apps/push_test.rb +46 -0
- data/test/lib/cf_script/command/cf/apps/restage_test.rb +47 -0
- data/test/lib/cf_script/command/cf/apps/restart_test.rb +47 -0
- data/test/lib/cf_script/command/cf/apps/set_env_test.rb +38 -0
- data/test/lib/cf_script/command/cf/apps/start_test.rb +55 -0
- data/test/lib/cf_script/command/cf/apps/stop_test.rb +35 -0
- data/test/lib/cf_script/command/cf/apps/unset_env_test.rb +38 -0
- data/test/lib/cf_script/command/cf/general/api_test.rb +55 -0
- data/test/lib/cf_script/command/cf/general/auth_test.rb +76 -0
- data/test/lib/cf_script/command/cf/general/login_test.rb +80 -0
- data/test/lib/cf_script/command/cf/general/logout_test.rb +34 -0
- data/test/lib/cf_script/command/cf/general/target_test.rb +110 -0
- data/test/lib/cf_script/command/cf/routes/check_route_test.rb +31 -0
- data/test/lib/cf_script/command/cf/routes/create_route_test.rb +19 -0
- data/test/lib/cf_script/command/cf/routes/delete_route_test.rb +19 -0
- data/test/lib/cf_script/command/cf/routes/map_route_test.rb +56 -0
- data/test/lib/cf_script/command/cf/routes/routes_test.rb +24 -0
- data/test/lib/cf_script/command/cf/routes/unmap_route_test.rb +36 -0
- data/test/lib/cf_script/command/cf/spaces/space_test.rb +55 -0
- data/test/lib/cf_script/command/cf/spaces/spaces_test.rb +47 -0
- data/test/lib/cf_script/command/line_test.rb +59 -0
- data/test/lib/cf_script/object/api_endpoint_test.rb +19 -0
- data/test/lib/cf_script/object/app_info_test.rb +127 -0
- data/test/lib/cf_script/object/app_list_test.rb +51 -0
- data/test/lib/cf_script/object/attribute_list_test.rb +42 -0
- data/test/lib/cf_script/object/attribute_test.rb +29 -0
- data/test/lib/cf_script/object/instance_status_test.rb +37 -0
- data/test/lib/cf_script/object/space_test.rb +31 -0
- data/test/lib/cf_script/object/target_test.rb +41 -0
- data/test/lib/cf_script/output/buffer_test.rb +73 -0
- data/test/lib/cf_script/output/parser/attributes_test.rb +102 -0
- data/test/lib/cf_script/output/parser/section_test.rb +60 -0
- data/test/lib/cf_script/output/parser/table_test.rb +108 -0
- data/test/lib/cf_script/output/tests_test.rb +91 -0
- data/test/lib/cf_script/output_test.rb +134 -0
- data/test/lib/cf_script/scope/app/state_test.rb +61 -0
- data/test/lib/cf_script/scope/app_test.rb +101 -0
- data/test/lib/cf_script/scope/script_test.rb +88 -0
- data/test/lib/cf_script/scope/space_test.rb +27 -0
- data/test/lib/cf_script/scope/target_test.rb +158 -0
- data/test/lib/cf_script/scope_test.rb +41 -0
- data/test/lib/cf_script/utils_test.rb +20 -0
- data/test/lib/cf_script_test.rb +73 -0
- data/test/support/assertions.rb +14 -0
- data/test/support/helpers/config_context.rb +19 -0
- data/test/support/helpers/fixture_executor.rb +79 -0
- data/test/support/helpers/mock_execution.rb +58 -0
- data/test/support/helpers/object_helpers.rb +29 -0
- data/test/support/helpers/output_sink.rb +25 -0
- data/test/support/helpers.rb +3 -0
- data/test/support/shared_examples/command_object.rb +38 -0
- data/test/support/shared_examples.rb +30 -0
- data/test/test_helper.rb +34 -0
- metadata +321 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module CfScript::Scope
|
|
2
|
+
module Execution
|
|
3
|
+
module_function
|
|
4
|
+
|
|
5
|
+
def exec_in(inner, *args, &block)
|
|
6
|
+
outer = eval('self', block.binding)
|
|
7
|
+
outer = CfScript::Scope::Root.new if outer.class == Object
|
|
8
|
+
|
|
9
|
+
inner_proxy = CfScript::Scope::Proxy.new(inner, outer)
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
outer.instance_variables.each do |var|
|
|
13
|
+
val = outer.instance_variable_get(var)
|
|
14
|
+
inner_proxy.instance_variable_set(var, val)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
inner_proxy.instance_exec(*args, &block)
|
|
18
|
+
ensure
|
|
19
|
+
outer.instance_variables.each do |var|
|
|
20
|
+
val = inner_proxy.instance_variable_get(var)
|
|
21
|
+
outer.instance_variable_set(var, val)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Base
|
|
28
|
+
include Execution
|
|
29
|
+
include CfScript::UI
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
enter_scope
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def finalize
|
|
36
|
+
exit_scope
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def spec_for(name)
|
|
40
|
+
CfScript.spec_for(name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def method_missing(m, *args, &block)
|
|
44
|
+
CfScript::Command.run(m, *args, &block)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def scope_name
|
|
50
|
+
self.class.name.split('::').last.downcase
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def enter_scope
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def exit_scope
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class Root < Base
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
require 'cf_script/scope/proxy'
|
|
65
|
+
require 'cf_script/scope/target'
|
|
66
|
+
require 'cf_script/scope/script'
|
|
67
|
+
require 'cf_script/scope/space'
|
|
68
|
+
require 'cf_script/scope/app'
|
data/lib/cf_script/ui.rb
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'colorize'
|
|
4
|
+
|
|
5
|
+
module CfScript::UI
|
|
6
|
+
TAGS = {
|
|
7
|
+
error: ['{', '}'],
|
|
8
|
+
trace: ['<', '>'],
|
|
9
|
+
debug: ['(', ')'],
|
|
10
|
+
other: ['[', ']'],
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
COLORS = {
|
|
14
|
+
success: { color: :green },
|
|
15
|
+
error: { color: :red },
|
|
16
|
+
alert: { color: :yellow },
|
|
17
|
+
info: { color: :cyan },
|
|
18
|
+
|
|
19
|
+
inactive: { color: :light_red },
|
|
20
|
+
active: { color: :light_green },
|
|
21
|
+
|
|
22
|
+
progress: { color: :blue },
|
|
23
|
+
step: { color: :light_blue },
|
|
24
|
+
|
|
25
|
+
title: { color: :magenta },
|
|
26
|
+
detail: { color: :light_magenta },
|
|
27
|
+
|
|
28
|
+
trace: { color: :light_black },
|
|
29
|
+
debug: { color: :white },
|
|
30
|
+
|
|
31
|
+
# NOTE: default != no color
|
|
32
|
+
default: { color: :default },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
EMOJI = {
|
|
36
|
+
success: "\xE2\x9C\x85",
|
|
37
|
+
error: "\xE2\x9D\x8C",
|
|
38
|
+
alert: "\xE2\x9A\xA1",
|
|
39
|
+
info: "\xE2\x9D\x95",
|
|
40
|
+
|
|
41
|
+
trace: "\xE2\x86\xAA",
|
|
42
|
+
debug: "\xE2\x9A\xAA",
|
|
43
|
+
|
|
44
|
+
default: "\xE2\x9E\x96",
|
|
45
|
+
|
|
46
|
+
bisque: "🍲",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module_function
|
|
50
|
+
|
|
51
|
+
def puts_out(text)
|
|
52
|
+
CfScript.stdout.puts text
|
|
53
|
+
nil # Make it explicit
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def print_out(text)
|
|
57
|
+
CfScript.stdout.print text
|
|
58
|
+
nil # Make it explicit
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def puts_err(text)
|
|
62
|
+
CfScript.stderr.puts text
|
|
63
|
+
nil # Make it explicit
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def print_err(text)
|
|
67
|
+
CfScript.stderr.print text
|
|
68
|
+
nil # Make it explicit
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def with_color_of(type = :default)
|
|
72
|
+
COLORS[CfScript.config.ui.color ? type : :default]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def ui_style(text, type = :default)
|
|
76
|
+
text.colorize with_color_of(type)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def emoji(type)
|
|
80
|
+
"#{(EMOJI.key?(type) ? EMOJI[type] : EMOJI[:default])} "
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def emoji_for(type)
|
|
84
|
+
emoji(type) if CfScript.config.ui.emoji
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def tag_style(type = :default)
|
|
88
|
+
type
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def tag_color(type = :default)
|
|
92
|
+
type
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def tag_char(type, which)
|
|
96
|
+
(TAGS.key?(type) ? TAGS[type] : TAGS[:other]).send(which)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def tag_open(type = :default)
|
|
100
|
+
tag_char(tag_style(type), :first)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def tag_close(type = :default)
|
|
104
|
+
tag_char(tag_style(type), :last)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def tag_format(tag, type = :default)
|
|
108
|
+
if tag and CfScript.config.ui.tags
|
|
109
|
+
list = []
|
|
110
|
+
|
|
111
|
+
list << tag_open(type)
|
|
112
|
+
list << tag
|
|
113
|
+
list << tag_close(type)
|
|
114
|
+
|
|
115
|
+
list.join.colorize with_color_of(tag_color(type))
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def ui_format(type, tag, message, tag_type = nil)
|
|
120
|
+
list = []
|
|
121
|
+
|
|
122
|
+
list << emoji_for(type)
|
|
123
|
+
list << tag_format(tag, tag_type ? tag_type : type)
|
|
124
|
+
list << message.colorize(with_color_of(type))
|
|
125
|
+
|
|
126
|
+
list.compact.reject(&:empty?).join(' ')
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def call_type(callee)
|
|
130
|
+
callee.to_s =~ /\Aui_(.+)\z/ ? $1.to_sym : callee
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def success(tag, message)
|
|
134
|
+
puts_out ui_format(call_type(__callee__), tag, message)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def error(tag, message)
|
|
138
|
+
puts_err ui_format(call_type(__callee__), tag, message)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def alert(tag, message)
|
|
142
|
+
puts_out ui_format(call_type(__callee__), tag, message)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def info(tag, message)
|
|
146
|
+
puts_out ui_format(call_type(__callee__), tag, message)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def progress(tag, message)
|
|
150
|
+
puts_out ui_format(call_type(__callee__), tag, message)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def step(tag, message)
|
|
154
|
+
puts_out ui_format(call_type(__callee__), tag, message)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def title(tag, message, indent = 0)
|
|
158
|
+
puts_out ui_format(call_type(__callee__), tag, "#{' ' * indent}#{message}")
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def detail(tag, message, indent = 1)
|
|
162
|
+
puts_out ui_format(call_type(__callee__), tag, "#{' ' * indent}#{message}")
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def trace(tag, message, use_print = false)
|
|
166
|
+
if CfScript.config.runtime.trace
|
|
167
|
+
text = ui_format(call_type(__callee__), tag, message)
|
|
168
|
+
use_print ? print_out(text) : puts_out(text)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def debug(tag, message)
|
|
173
|
+
puts_err ui_format(call_type(__callee__), tag, message.inspect)
|
|
174
|
+
#binding.pry; __pry__.???
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# For overriding to use a default tag
|
|
178
|
+
alias :ui_tag_format :tag_format
|
|
179
|
+
alias :ui_success :success
|
|
180
|
+
alias :ui_error :error
|
|
181
|
+
alias :ui_alert :alert
|
|
182
|
+
alias :ui_info :info
|
|
183
|
+
alias :ui_progress :progress
|
|
184
|
+
alias :ui_step :step
|
|
185
|
+
alias :ui_title :title
|
|
186
|
+
alias :ui_detail :detail
|
|
187
|
+
alias :ui_trace :trace
|
|
188
|
+
alias :ui_debug :debug
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
module CfScript::UI::NilTag
|
|
192
|
+
def success(message)
|
|
193
|
+
ui_success nil, message
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def error(message)
|
|
197
|
+
ui_error nil, message
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def alert(message)
|
|
201
|
+
ui_alert nil, message
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def info(message)
|
|
205
|
+
ui_info nil, message
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def progress(message)
|
|
209
|
+
ui_progress nil, message
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def step(message)
|
|
213
|
+
ui_step nil, message
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def title(message, indent = 0)
|
|
217
|
+
ui_title nil, message, indent
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def detail(message, indent = 1)
|
|
221
|
+
ui_detail nil, message, indent
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
module CfScript::UI::NameTag
|
|
226
|
+
def name_tag
|
|
227
|
+
name
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def success(message)
|
|
231
|
+
ui_success name_tag, message
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def error(message)
|
|
235
|
+
ui_error name_tag, message
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def alert(message)
|
|
239
|
+
ui_alert name_tag, message
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def info(message)
|
|
243
|
+
ui_info name_tag, message
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def progress(message)
|
|
247
|
+
ui_progress name_tag, message
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def step(message)
|
|
251
|
+
ui_step name_tag, message
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def title(message, indent = 0)
|
|
255
|
+
ui_title name_tag, message, indent
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def detail(message, indent = 1)
|
|
259
|
+
ui_detail name_tag, message, indent
|
|
260
|
+
end
|
|
261
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module CfScript::Utils
|
|
2
|
+
module_function
|
|
3
|
+
|
|
4
|
+
def symbolize(name)
|
|
5
|
+
return name if name.is_a?(Symbol)
|
|
6
|
+
|
|
7
|
+
name.downcase.gsub(/[ .-]/, '_').to_sym
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def symbolize_keys(hash)
|
|
11
|
+
out = {}
|
|
12
|
+
|
|
13
|
+
hash.each do |key, value|
|
|
14
|
+
out[symbolize(key)] = value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
out
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/cf_script.rb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require_relative './cf_script/version'
|
|
2
|
+
require_relative './cf_script/config'
|
|
3
|
+
require_relative './cf_script/callbacks'
|
|
4
|
+
require_relative './cf_script/utils'
|
|
5
|
+
require_relative './cf_script/ui'
|
|
6
|
+
require_relative './cf_script/output'
|
|
7
|
+
require_relative './cf_script/executor'
|
|
8
|
+
require_relative './cf_script/scope'
|
|
9
|
+
require_relative './cf_script/command'
|
|
10
|
+
require_relative './cf_script/object'
|
|
11
|
+
require_relative './cf_script/manifest'
|
|
12
|
+
|
|
13
|
+
module CfScript
|
|
14
|
+
class << self
|
|
15
|
+
attr_accessor :configuration
|
|
16
|
+
|
|
17
|
+
attr_accessor :definitions
|
|
18
|
+
|
|
19
|
+
attr_accessor :cf_call_count
|
|
20
|
+
attr_accessor :cf_call_stack
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#extend CfScript::Context
|
|
24
|
+
extend CfScript::Scope::Execution
|
|
25
|
+
extend CfScript::UI
|
|
26
|
+
|
|
27
|
+
module_function
|
|
28
|
+
|
|
29
|
+
def config
|
|
30
|
+
@configuration ||= Config.new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def configure
|
|
34
|
+
block_given? ? yield(config) : config
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def stdout
|
|
38
|
+
config.io.stdout
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def stderr
|
|
42
|
+
config.io.stderr
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def manifest(path = nil)
|
|
46
|
+
@manifest ||= CfScript::Manifest.new(path)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def define(app_name, &block)
|
|
50
|
+
@definitions ||= {}
|
|
51
|
+
@definitions[app_name] = AppSpec.new(name: app_name).tap do |spec|
|
|
52
|
+
spec.instance_exec(&block)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def spec_for(app_name)
|
|
57
|
+
@definitions ||= {}
|
|
58
|
+
@definitions[app_name]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def cf(options = {}, &block)
|
|
62
|
+
@cf_call_count ||= 0
|
|
63
|
+
@cf_call_stack ||= []
|
|
64
|
+
|
|
65
|
+
if @cf_call_count == 0
|
|
66
|
+
info :cf, CfScript::Command::Runner.cf_id
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@cf_call_count += 1
|
|
70
|
+
@cf_call_stack.push CfScript::Scope::Script.new(options)
|
|
71
|
+
@cf_call_stack.last.run(&block)
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
print_error(e)
|
|
74
|
+
ensure
|
|
75
|
+
@cf_call_stack.last.finalize if @cf_call_stack.last
|
|
76
|
+
@cf_call_stack.pop
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def stack_level
|
|
80
|
+
@cf_call_stack.length - 1
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def print_error(e)
|
|
84
|
+
error "cf:#{stack_level}", e.message
|
|
85
|
+
e.backtrace.each do |line|
|
|
86
|
+
error "cf:#{stack_level}", line
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
if stdout.is_a?(StringIO)
|
|
90
|
+
STDOUT.puts "cf:#{stack_level} #{e.message}"
|
|
91
|
+
e.backtrace.each do |line|
|
|
92
|
+
STDOUT.puts "cf:#{stack_level} #{line}"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class << self
|
|
98
|
+
private :stack_level
|
|
99
|
+
private :print_error
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def cf(options = {}, &block)
|
|
104
|
+
CfScript.cf(options, &block)
|
|
105
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Showing health and status for app email-worker in org ACME / space staging as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
requested state: stopped
|
|
7
|
+
instances: 0/1
|
|
8
|
+
usage: 32M x 1 instances
|
|
9
|
+
urls:
|
|
10
|
+
last uploaded: Fri Dec 25 00:00:00 UTC 2015
|
|
11
|
+
stack: cflinuxfs2
|
|
12
|
+
buildpack: https://github.com/cloudfoundry/binary-buildpack.git
|
|
13
|
+
|
|
14
|
+
There are no running instances of this app.
|
|
15
|
+
|
|
16
|
+
stderr: ''
|
|
17
|
+
status:
|
|
18
|
+
exitstatus: 0
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Showing health and status for app email-worker in org ACME / space staging as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
requested state: started
|
|
7
|
+
instances: 1/1
|
|
8
|
+
usage: 32M x 1 instances
|
|
9
|
+
urls:
|
|
10
|
+
last uploaded: Tue Dec 15 22:22:28 UTC 2015
|
|
11
|
+
stack: cflinuxfs2
|
|
12
|
+
buildpack: https://github.com/cloudfoundry/binary-buildpack.git
|
|
13
|
+
|
|
14
|
+
state since cpu memory disk details
|
|
15
|
+
#0 running 2015-12-22 08:49:38 AM 0.0% 2M of 32M 27.8M of 1G
|
|
16
|
+
|
|
17
|
+
stderr: ''
|
|
18
|
+
status:
|
|
19
|
+
exitstatus: 0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Getting apps in org ACME / space test as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
name requested state instances memory disk urls
|
|
7
|
+
org-one-api stopped 0/1 256M 1G example.com, example.net
|
|
8
|
+
org-one-worker started 1/3 1G 2G
|
|
9
|
+
org-two-api stopped 0/2 256M 3G example.io, example.org
|
|
10
|
+
org-two-worker started 1/1 2G 4G
|
|
11
|
+
|
|
12
|
+
stderr: ''
|
|
13
|
+
status:
|
|
14
|
+
exitstatus: 0
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Getting env variables for app email-worker in org ACME / space staging as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
System-Provided:
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
{
|
|
10
|
+
"VCAP_APPLICATION": {
|
|
11
|
+
"application_id": "00000000-0000-0000-0000-000000000000",
|
|
12
|
+
"application_name": "email-worker",
|
|
13
|
+
"application_uris": [],
|
|
14
|
+
"application_version": "00000000-0000-0000-0000-000000000000",
|
|
15
|
+
"limits": {
|
|
16
|
+
"disk": 1024,
|
|
17
|
+
"fds": 16384,
|
|
18
|
+
"mem": 4
|
|
19
|
+
},
|
|
20
|
+
"name": "email-worker",
|
|
21
|
+
"space_id": "00000000-0000-0000-0000-000000000000",
|
|
22
|
+
"space_name": "staging",
|
|
23
|
+
"uris": [],
|
|
24
|
+
"users": null,
|
|
25
|
+
"version": "00000000-0000-0000-0000-000000000000"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
No user-defined env variables have been set
|
|
30
|
+
|
|
31
|
+
No running env variables have been set
|
|
32
|
+
|
|
33
|
+
No staging env variables have been set
|
|
34
|
+
|
|
35
|
+
stderr: ''
|
|
36
|
+
status:
|
|
37
|
+
exitstatus: 0
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Getting env variables for app email-worker in org ACME / space development as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
System-Provided:
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
{
|
|
10
|
+
"VCAP_APPLICATION": {
|
|
11
|
+
"application_id": "00000000-0000-0000-0000-000000000000",
|
|
12
|
+
"application_name": "email-worker",
|
|
13
|
+
"application_uris": [],
|
|
14
|
+
"application_version": "00000000-0000-0000-0000-000000000000",
|
|
15
|
+
"limits": {
|
|
16
|
+
"disk": 1024,
|
|
17
|
+
"fds": 16384,
|
|
18
|
+
"mem": 8
|
|
19
|
+
},
|
|
20
|
+
"name": "email-worker",
|
|
21
|
+
"space_id": "00000000-0000-0000-0000-000000000000",
|
|
22
|
+
"space_name": "development",
|
|
23
|
+
"uris": [],
|
|
24
|
+
"users": null,
|
|
25
|
+
"version": "00000000-0000-0000-0000-000000000000"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
User-Provided:
|
|
30
|
+
SERVER_HOSTNAME: host.example.com
|
|
31
|
+
SERVER_HOSTPORT: 1234
|
|
32
|
+
SERVER_PASSWORD: word
|
|
33
|
+
SERVER_USERNAME: name
|
|
34
|
+
|
|
35
|
+
No running env variables have been set
|
|
36
|
+
|
|
37
|
+
No staging env variables have been set
|
|
38
|
+
|
|
39
|
+
stderr: ''
|
|
40
|
+
status:
|
|
41
|
+
exitstatus: 0
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
stdout: |
|
|
3
|
+
Updating app development-worker in org ACME / space development as user@example.com...
|
|
4
|
+
OK
|
|
5
|
+
|
|
6
|
+
App development-worker is a worker, skipping route creation
|
|
7
|
+
Uploading development-worker...
|
|
8
|
+
Uploading app files from: /path/to/app
|
|
9
|
+
Uploading 12M, 345 files
|
|
10
|
+
Done uploading
|
|
11
|
+
OK
|
|
12
|
+
|
|
13
|
+
Stopping app development-worker in org ACME / space development as user@example.com...
|
|
14
|
+
OK
|
|
15
|
+
|
|
16
|
+
Starting app development-worker in org ACME / space development as user@example.com...
|
|
17
|
+
Creating container
|
|
18
|
+
Successfully created container
|
|
19
|
+
Downloading app package...
|
|
20
|
+
Downloaded app package (411B)
|
|
21
|
+
Downloading buildpacks (https://github.com/cloudfoundry/binary-buildpack.git), build artifacts cache...
|
|
22
|
+
Downloading build artifacts cache...
|
|
23
|
+
Downloaded build artifacts cache (108B)
|
|
24
|
+
Downloaded buildpacks
|
|
25
|
+
Staging...
|
|
26
|
+
Exit status 0
|
|
27
|
+
Staging complete
|
|
28
|
+
Uploading droplet, build artifacts cache...
|
|
29
|
+
Uploading droplet...
|
|
30
|
+
Uploading build artifacts cache...
|
|
31
|
+
Uploaded build artifacts cache (108B)
|
|
32
|
+
Uploaded droplet (401B)
|
|
33
|
+
Uploading complete
|
|
34
|
+
|
|
35
|
+
1 of 1 instances running
|
|
36
|
+
|
|
37
|
+
App started
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
OK
|
|
41
|
+
|
|
42
|
+
App development-worker was started using this command `./worker`
|
|
43
|
+
|
|
44
|
+
Showing health and status for app development-worker in org ACME / space development as user@example.com...
|
|
45
|
+
OK
|
|
46
|
+
|
|
47
|
+
requested state: started
|
|
48
|
+
instances: 1/1
|
|
49
|
+
usage: 8M x 1 instances
|
|
50
|
+
urls:
|
|
51
|
+
last uploaded: Wed Dec 23 03:07:26 UTC 2015
|
|
52
|
+
stack: cflinuxfs2
|
|
53
|
+
buildpack: https://github.com/cloudfoundry/binary-buildpack.git
|
|
54
|
+
|
|
55
|
+
state since cpu memory disk details
|
|
56
|
+
\#0 running 2015-12-23 05:07:42 AM 0.0% 2.2M of 8M 27.8M of 1G
|
|
57
|
+
|
|
58
|
+
stderr: ''
|
|
59
|
+
status:
|
|
60
|
+
exitstatus: 0
|