cf_script 0.0.1.beta.1 → 0.0.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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +18 -0
  3. data/README.md +182 -34
  4. data/Rakefile +0 -13
  5. data/lib/cf_script/command/base.rb +1 -1
  6. data/lib/cf_script/command/cf/apps/app.rb +1 -1
  7. data/lib/cf_script/command/cf/apps/apps.rb +5 -3
  8. data/lib/cf_script/command/cf/apps/delete.rb +25 -0
  9. data/lib/cf_script/command/cf/apps/env.rb +4 -2
  10. data/lib/cf_script/command/cf/apps/push.rb +7 -2
  11. data/lib/cf_script/command/cf/apps/rename.rb +20 -0
  12. data/lib/cf_script/command/cf/apps/restage.rb +1 -1
  13. data/lib/cf_script/command/cf/apps/restart.rb +1 -1
  14. data/lib/cf_script/command/cf/apps/set_env.rb +1 -1
  15. data/lib/cf_script/command/cf/apps/start.rb +1 -1
  16. data/lib/cf_script/command/cf/apps/stop.rb +3 -2
  17. data/lib/cf_script/command/cf/apps/unset_env.rb +1 -1
  18. data/lib/cf_script/command/cf/apps.rb +5 -1
  19. data/lib/cf_script/command/cf/general/api.rb +1 -1
  20. data/lib/cf_script/command/cf/general/auth.rb +1 -1
  21. data/lib/cf_script/command/cf/general/login.rb +1 -1
  22. data/lib/cf_script/command/cf/general/logout.rb +1 -1
  23. data/lib/cf_script/command/cf/general/target.rb +1 -1
  24. data/lib/cf_script/command/cf/routes/check_route.rb +1 -1
  25. data/lib/cf_script/command/cf/routes/create_route.rb +1 -1
  26. data/lib/cf_script/command/cf/routes/delete_route.rb +5 -2
  27. data/lib/cf_script/command/cf/routes/map_route.rb +1 -1
  28. data/lib/cf_script/command/cf/routes/routes.rb +1 -1
  29. data/lib/cf_script/command/cf/routes/unmap_route.rb +1 -1
  30. data/lib/cf_script/command/cf/spaces/space.rb +1 -1
  31. data/lib/cf_script/command/cf/spaces/spaces.rb +1 -1
  32. data/lib/cf_script/command/runner.rb +1 -15
  33. data/lib/cf_script/config.rb +3 -1
  34. data/lib/cf_script/executor/recorder.rb +3 -1
  35. data/lib/cf_script/executor/simple.rb +22 -9
  36. data/lib/cf_script/executor.rb +0 -1
  37. data/lib/cf_script/object/api_endpoint.rb +1 -1
  38. data/lib/cf_script/object/app_info.rb +1 -1
  39. data/lib/cf_script/object/app_list.rb +21 -5
  40. data/lib/cf_script/object/attribute.rb +1 -1
  41. data/lib/cf_script/object/attribute_list.rb +1 -1
  42. data/lib/cf_script/object/instance_status.rb +1 -1
  43. data/lib/cf_script/object/route_info.rb +1 -1
  44. data/lib/cf_script/object/space.rb +1 -1
  45. data/lib/cf_script/object/target.rb +1 -1
  46. data/lib/cf_script/object.rb +0 -11
  47. data/lib/cf_script/output/buffer.rb +1 -1
  48. data/lib/cf_script/scope/app/routes.rb +1 -1
  49. data/lib/cf_script/scope/app.rb +0 -26
  50. data/lib/cf_script/scope/target.rb +7 -1
  51. data/lib/cf_script/ui.rb +2 -6
  52. data/lib/cf_script/version.rb +1 -1
  53. data/lib/cf_script.rb +0 -2
  54. data/test/fixtures/commands/apps/delete/good.yml +8 -0
  55. data/test/fixtures/commands/apps/delete/not_exist.yml +9 -0
  56. data/test/fixtures/commands/apps/env/{empty.yml → empty_vars.yml} +0 -0
  57. data/test/fixtures/commands/apps/rename/good.yml +8 -0
  58. data/test/fixtures/commands/apps/rename/not_found.yml +8 -0
  59. data/test/fixtures/commands/{apps/set_env → common}/empty.yml +0 -0
  60. data/test/lib/cf_script/command/cf/apps/app_test.rb +8 -0
  61. data/test/lib/cf_script/command/cf/apps/apps_test.rb +12 -3
  62. data/test/lib/cf_script/command/cf/apps/delete_test.rb +51 -0
  63. data/test/lib/cf_script/command/cf/apps/env_test.rb +12 -2
  64. data/test/lib/cf_script/command/cf/apps/push_test.rb +14 -0
  65. data/test/lib/cf_script/command/cf/apps/rename_test.rb +35 -0
  66. data/test/lib/cf_script/command/cf/apps/restage_test.rb +8 -0
  67. data/test/lib/cf_script/command/cf/apps/restart_test.rb +8 -0
  68. data/test/lib/cf_script/command/cf/apps/start_test.rb +8 -0
  69. data/test/lib/cf_script/command/cf/apps/stop_test.rb +2 -2
  70. data/test/lib/cf_script/command/cf/general/login_test.rb +9 -10
  71. data/test/lib/cf_script/command/cf/routes/create_route_test.rb +12 -0
  72. data/test/lib/cf_script/command/cf/routes/delete_route_test.rb +18 -0
  73. data/test/lib/cf_script/command/cf/routes/map_route_test.rb +12 -0
  74. data/test/lib/cf_script/command/cf/routes/routes_test.rb +8 -0
  75. data/test/lib/cf_script/command/cf/routes/unmap_route_test.rb +12 -0
  76. data/test/lib/cf_script/object/app_info_test.rb +4 -4
  77. data/test/lib/cf_script/object/app_list_test.rb +68 -2
  78. data/test/lib/cf_script/output/buffer_test.rb +9 -9
  79. data/test/lib/cf_script/output/parser/section_test.rb +4 -2
  80. data/test/lib/cf_script/output/tests_test.rb +24 -24
  81. data/test/lib/cf_script/output_test.rb +23 -18
  82. data/test/lib/cf_script/scope/app/env_test.rb +58 -0
  83. data/test/lib/cf_script/scope/app/routes_test.rb +56 -0
  84. data/test/lib/cf_script/scope/app/state_test.rb +30 -0
  85. data/test/lib/cf_script/scope/script_test.rb +3 -2
  86. data/test/lib/cf_script/scope/target_test.rb +38 -23
  87. data/test/lib/cf_script/scope_test.rb +10 -6
  88. data/test/lib/cf_script/ui_test.rb +133 -0
  89. data/test/lib/cf_script_test.rb +14 -8
  90. data/test/support/assertions.rb +25 -0
  91. data/test/support/helpers/fixture_executor.rb +1 -1
  92. data/test/support/helpers/mock_execution.rb +29 -7
  93. metadata +23 -14
  94. data/lib/cf_script/callbacks.rb +0 -43
  95. data/lib/cf_script/executor/non_blocking.rb +0 -107
  96. data/lib/cf_script/object/app_spec.rb +0 -55
  97. data/test/fixtures/commands/apps/unset_env/empty.yml +0 -5
  98. data/test/fixtures/commands/general/auth/empty.yml +0 -5
  99. data/test/fixtures/commands/general/target/empty.yml +0 -5
  100. data/test/fixtures/commands/spaces/space/empty.yml +0 -5
  101. data/test/fixtures/commands/spaces/spaces/empty.yml +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 760492ef86eb59b8e5fdcb8275227fc8e8e884e4
4
- data.tar.gz: 3d347022f374182c81c52cfaa69b24986a620406
3
+ metadata.gz: 3b3fcbadbf41b6e1480c5762c3f7552b438b4a15
4
+ data.tar.gz: 5674005bd8d20ad77fecadf0b0480226e955bbee
5
5
  SHA512:
6
- metadata.gz: 1d430f863f77eebe4188a6891fb2e609abdc0e2e1a168920e23ac0f6ee50feee970ef3c9d16b7052011597977131a0c8c671b01df7e5d9a5f94036bbca9ae01a
7
- data.tar.gz: 42a1de9c7fbd5d2cdee6affafa8c53862112057aaad50d0daaba59df433e7298b393ae0fd06b87e5c0f6ec301e417d96d8c02d6b5b5f4805f7cd797cd0f72bb1
6
+ metadata.gz: d7ea902b29a98636d2bd71e7dad70b58aa35cdfd133f461ff93121c54afa2592fe2dc70a3d82f1fd1b858cbdfa11449ca7fd40d076fa9cdc4df29d22c9fda156
7
+ data.tar.gz: b82c13b445f07e7b92c9882404c9185d9931e25fb0c375eb0838d0cc62519a78f45db737b0c6b72e7376c92e974e919731875477f4c9c746901c16c7ed843076
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ branches:
4
+ only:
5
+ - master
6
+
7
+ before_script:
8
+ - wget http://go-cli.s3-website-us-east-1.amazonaws.com/releases/latest/cf-linux-amd64.tgz -O /tmp/cf-linux-amd64.tgz
9
+ - tar -xvf /tmp/cf-linux-amd64.tgz
10
+ - export PATH=$PATH:$PWD/
11
+
12
+ rvm:
13
+ - '2.0.0'
14
+ - '2.1.8'
15
+ - '2.2.4'
16
+ - '2.3.0'
17
+
18
+ script: 'bundle exec rake test'
data/README.md CHANGED
@@ -1,23 +1,38 @@
1
1
  # CfScript
2
+ [![Gem Version](https://img.shields.io/gem/v/cf_script.svg)](https://rubygems.org/gems/cf_script) [![Build Status](https://secure.travis-ci.org/ammar/cf_script.png?branch=master)](http://travis-ci.org/ammar/cf_script)
2
3
 
3
- CfScript is a DSL for scripting and automating the Cloud Foundry CLI.
4
+ CfScript is a DSL for scripting the Cloud Foundry CLI, with a focus
5
+ on application deployment and management. _[See Supported Commands](#supported-commands)_
4
6
 
5
7
  ```ruby
8
+ # example.rb
6
9
  require 'cf_script'
7
10
 
8
- cf space: 'staging' do
11
+ cf space: :development do
9
12
  workers = apps ending_with: 'worker'
10
13
 
11
14
  workers.each do |worker|
12
15
  app worker do
16
+ show :state, :memory, :instances
17
+
18
+ stop if started?
19
+
20
+ progress 'Setting ENV variable...'
13
21
  set_env 'SOME_NAME', 'SOME_VALUE'
14
22
 
15
- restart if started?
23
+ progress "Restaging #{name} in #{current_space}..."
24
+ restage
16
25
  end
17
26
  end
18
27
  end
19
28
  ```
20
29
 
30
+ To see the cf commands that get executed, run with TRACE=1.
31
+ ```
32
+ TRACE=1 ruby example.rb
33
+ ```
34
+
35
+ ---
21
36
  ## Requirements
22
37
 
23
38
  * `ruby` >= 2.0
@@ -28,48 +43,161 @@ end
28
43
 
29
44
  Install the gem with:
30
45
 
31
- `gem install cf_script --pre`
46
+ ```gem install cf_script --pre```
32
47
 
33
48
  Or, add it to your project's `Gemfile`:
34
49
 
35
- ```gem 'cf_script', '0.1.0.pre'```
50
+ ```gem 'cf_script', '0.0.1.beta.1'```
36
51
 
37
52
  ---
53
+ ## Execution Scopes
54
+
55
+ There are three execution scopes/blocks; `cf`, `space`, and `app`:
56
+
57
+ ### The `cf` Block Scope
58
+ The `cf` scope is the top-level scope, it includes evertything between the
59
+ `do/end` following a call to `cf`. The scope saves the current target on
60
+ entry and restores it on exit.
61
+
62
+ ```ruby
63
+ # cf target => staging
64
+
65
+ cf space: :development do
66
+ # cf target => development
67
+ end
68
+
69
+ # cf target => staging
70
+ ```
71
+
72
+ The `cf` block accepts the following options:
73
+
74
+ - `api`: Sets the API endpoint _(optional)_
75
+ - `org`: Sets the target organization _(optional)_
76
+ - `username`/`password`: Credentials to use for logging in. _(optional)_
77
+ - `space`: Sets the target space _(optional)_
78
+
79
+ _**Note**: To save the current target the `cf` block will execute `cf target`
80
+ on entry, and if it changed within the block, it wil execute `cf target SPACE`
81
+ on exit to restore it._
38
82
 
83
+
84
+ ### The `space` Block Scope
85
+ The `space` scope is a sub-scope and can only appear within a `cf` block. It
86
+ also saves the current target on entry and restores, if changed, it on exit.
87
+
88
+ ```ruby
89
+ # before cf block, target => staging
90
+
91
+ cf space: :development do
92
+ # inside cf block, target => development
93
+
94
+ space :production do
95
+ # inside space block, target => production
96
+ end
97
+
98
+ # still inside cf block, target => development
99
+ end
100
+
101
+ # after cf block, target => staging
102
+ ```
103
+
104
+ ### The `app` Block Scope
105
+ The `app` scope can appear within a `cf` or `space` blocks. Within the block
106
+ the selected app is the target of commands, this means that commands that take
107
+ an application name as their first argument can be called without it.
108
+
109
+ ```ruby
110
+ cf do
111
+ app :api do
112
+ env.each do |name, value|
113
+ unset_env name
114
+ end
115
+
116
+ started? ? restart : start
117
+ end
118
+ end
119
+ ```
120
+
121
+ The `app` method accepts a string or an AppInfo object as a name argument.
122
+
123
+ ## Command Methods
124
+
125
+ ### The `apps` Method
126
+ The `apps` method mirrors the `cf apps` command. When called without a block,
127
+ it returns an AppList object that acts as an array of AppInfo objects, each
128
+ of which contains the information in each row output by `cf apps`.
129
+
130
+ ```ruby
131
+ cf do
132
+ # Get the list of AppInfo objects
133
+ space_apps = apps
134
+
135
+ # Iterate over the AppInfo objects
136
+ apps.each do |app_info|
137
+ # ...
138
+ end
139
+ end
140
+ ```
141
+
142
+ When the `apps` method is called with a block, it excutes the block within the
143
+ context of each app.
144
+
145
+ ```ruby
146
+ cf do
147
+ apps do
148
+ started? ? restart : start
149
+ end
150
+ end
151
+ ```
152
+
153
+ This is equivalent to:
154
+
155
+ ```ruby
156
+ cf do
157
+ apps.each do |app_info|
158
+ app app_info do
159
+ started? ? restart : start
160
+ end
161
+ end
162
+ end
163
+ ```
164
+
165
+ ---
39
166
  ## Supported Commands
40
167
 
41
168
  | Commands | CLI command | ⋯ |
42
- | ------------------------------------- | ------------------------------------------------------- |:--------:|
43
- | **General** | | ⋱ |
44
- |   _**api**_ | `cf api URL` | ✓ |
45
- |   _**auth**_ | `cf auth USER PASSWORD` | ✓ |
46
- |   _**login**_ | `cf login -u USER -p PASSWORD [OPTIONS]` | ✓ |
47
- |   _**logout**_ | `cf logout` | ✓ |
48
- |   _**target**_ | `cf target [-s SPACE -o ORG]` | ✓ |
49
- | **Applications** | | ⋱ |
50
- |   _**app**_ | `cf app APP_NAME` | ✓ |
51
- |   _**apps**_ | `cf apps` | ✓ |
52
- |   _**start**_ | `cf start APP_NAME` | ✓ |
53
- |   _**stop**_ | `cf stop APP_NAME` | ✓ |
54
- |   _**restart**_ | `cf restart APP_NAME` | ✓ |
55
- |   _**push**_ | `cf push [OPTIONS]` | ✓ |
56
- |   _**restage**_ | `cf restage APP_NAME` | ✓ |
57
- |   _**env**_ | `cf env APP_NAME` | ✓ |
58
- |   _**set-env**_ | `cf set-env APP_NAME VAR_NAME VAR_VALUE` | ✓ |
59
- |   _**unset-env**_ | `cf unset-env APP_NAME VAR_NAME` | ✓ |
60
- | **Routes** | | ⋱ |
61
- |   _**routes**_ | `cf routes` | ✓ |
62
- |   _**check-route**_ | `cf check-route HOST DOMAIN` | ✓ |
63
- |   _**create-route**_ | `cf create-route SPACE DOMAIN [-n HOSTNAME]` | ✓ |
64
- |   _**map-route**_ | `cf map-route APP_NAME DOMAIN [-n HOSTNAME]` | ✓ |
65
- |   _**unmap-route**_ | `cf unmap-route APP_NAME DOMAIN [-n HOSTNAME]` | ✓ |
66
- |   _**delete-route**_ | `cf delete-route DOMAIN [-n HOSTNAME] [-f]` | ✓ |
67
- | **Spaces** | | ⋱ |
68
- |   _**space**_ | `cf space SPACE` | ✓ |
69
- |   _**spaces**_ | `cf spaces` | ✓ |
169
+ |:--------------------------------------|:--------------------------------------------------------|:--------:|
170
+ | _**General**_ | | |
171
+ |   api | `cf api URL` | ✓ |
172
+ |   auth | `cf auth USER PASSWORD` | ✓ |
173
+ |   login | `cf login -u USER -p PASSWORD [OPTIONS]` | ✓ |
174
+ |   logout | `cf logout` | ✓ |
175
+ |   target | `cf target [-s SPACE -o ORG]` | ✓ |
176
+ | _**Applications**_ | | |
177
+ |   apps | `cf apps` | ✓ |
178
+ |   app | `cf app APP_NAME` | ✓ |
179
+ |   start | `cf start APP_NAME` | ✓ |
180
+ |   stop | `cf stop APP_NAME` | ✓ |
181
+ |   restart | `cf restart APP_NAME` | ✓ |
182
+ |   push | `cf push APP_NAME [OPTIONS]` | ✓ |
183
+ |   restage | `cf restage APP_NAME` | ✓ |
184
+ |   rename | `cf rename APP_NAME NEW_APP_NAME` | ✓ |
185
+ |   delete | `cf delete APP_NAME [-f -r]` | ✓ |
186
+ |   env | `cf env APP_NAME` | ✓ |
187
+ |   set-env | `cf set-env APP_NAME VAR_NAME VAR_VALUE` | ✓ |
188
+ |   unset-env | `cf unset-env APP_NAME VAR_NAME` | ✓ |
189
+ | _**Routes**_ | | |
190
+ |   routes | `cf routes` | ✓ |
191
+ |   check-route | `cf check-route HOST DOMAIN` | ✓ |
192
+ |   create-route | `cf create-route SPACE DOMAIN [-n HOSTNAME]` | ✓ |
193
+ |   map-route | `cf map-route APP_NAME DOMAIN [-n HOSTNAME]` | ✓ |
194
+ |   unmap-route | `cf unmap-route APP_NAME DOMAIN [-n HOSTNAME]` | ✓ |
195
+ |   delete-route | `cf delete-route DOMAIN [-n HOSTNAME] [-f]` | ✓ |
196
+ | _**Spaces**_ | | |
197
+ |   spaces | `cf spaces` | ✓ |
198
+ |   space | `cf space SPACE` | ✓ |
70
199
 
71
200
  ---
72
-
73
201
  ## Building
74
202
  The project uses the standard rubygems package tasks, so:
75
203
 
@@ -82,3 +210,23 @@ To install the gem from the cloned project, run:
82
210
  ```
83
211
  rake install
84
212
  ```
213
+
214
+ ---
215
+ ## Known Problems/Limitations
216
+
217
+ * Obviously everything depends on the output of `cf`, so if that changes
218
+ things will break. This is not unique to cf_script, but it is something
219
+ worth noting. The centralized parsing of `cf`'s output should reduce
220
+ the impact of change on scripts, but there is no guarantee.
221
+
222
+ * The fixtures were collected manually and they might become a pain to
223
+ manage. Will investigate creating a tool/script that automates their
224
+ collection from `cf`.
225
+
226
+ * I18N, n'existe pas, mais, it's not impossible. If implemented, it should
227
+ be based on the latest [translation files from the `cf` repository](https://github.com/cloudfoundry/cli/tree/master/cf/i18n/resources),
228
+ and the process of pulling the files automated. In the meantime, might
229
+ explicity add LANG to the ENV variables passed to `cf`.
230
+
231
+ * Windows? No clues. Probably not without some changes.
232
+
data/Rakefile CHANGED
@@ -18,16 +18,3 @@ Rake::TestTask.new('test') do |t|
18
18
  t.libs << "test"
19
19
  t.test_files = FileList['test/**/*.rb']
20
20
  end
21
-
22
- namespace :test do
23
- %w{commands runner parser}.each do |component|
24
- Rake::TestTask.new(component) do |t|
25
- if t.respond_to?(:description)
26
- t.description = "Run all #{component} unit tests under the test/#{component} directory"
27
- end
28
-
29
- t.libs << "test"
30
- t.test_files = ["test/#{component}/**/*.rb"]
31
- end
32
- end
33
- end
@@ -25,7 +25,7 @@ module CfScript::Command
25
25
  raise "run called in base command class"
26
26
  end
27
27
 
28
- def can_run?(output, options = {})
28
+ def good_run?(output, options = {})
29
29
  options[:check_status] = options.key?(:check_status) ? options[:check_status] : true
30
30
  options[:check_failed] = options.key?(:check_failed) ? options[:check_failed] : true
31
31
 
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, options = {}, &block)
8
8
  run_cf self, app_name do |output|
9
- return nil unless can_run?(output)
9
+ return nil unless good_run?(output)
10
10
 
11
11
  if app_info = build_app_info(app_name, output)
12
12
  block_given? ? yield(app_info) : app_info
@@ -17,8 +17,10 @@ module CfScript::Command
17
17
 
18
18
  def run(options = {}, &block)
19
19
  run_cf self do |output|
20
- return [] unless can_run?(output)
21
- return [] if output.contains? NO_APPS_FOUND
20
+ blank_list = CfScript::AppList.new
21
+
22
+ return blank_list unless good_run?(output)
23
+ return blank_list if output.contains? NO_APPS_FOUND
22
24
 
23
25
  if rows = output.table(APPS_TABLE)
24
26
  list = build_app_list(rows)
@@ -26,7 +28,7 @@ module CfScript::Command
26
28
  block_given? ? yield(list) : list
27
29
  else
28
30
  error 'rows is nil'
29
- return []
31
+ return blank_list
30
32
  end
31
33
  end
32
34
  end
@@ -0,0 +1,25 @@
1
+ module CfScript::Command
2
+ class Apps::DeleteCommand < CfScript::Command::Base
3
+ def initialize
4
+ super(:apps, :delete)
5
+ end
6
+
7
+ def run(app_name, force = false, delete_routes = false, &block)
8
+ options = { flags: [] }
9
+
10
+ options[:flags] << :f if force
11
+ options[:flags] << :r if delete_routes
12
+
13
+ run_cf self, app_name, options do |output|
14
+ return false unless good_run?(output)
15
+
16
+ if output.ok?
17
+ block_given? ? yield(true) : true
18
+ else
19
+ error "failed to delete app"
20
+ return false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,12 +6,14 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, &block)
8
8
  run_cf self, app_name do |output|
9
- return {} unless can_run?(output)
9
+ return {} unless good_run?(output)
10
10
 
11
11
  if vars = output.section_attributes('User-Provided')
12
12
  block_given? ? yield(vars.to_h) : vars.to_h
13
+ elsif output.contains?('No user-defined env variables have been set')
14
+ return {}
13
15
  else
14
- error 'vars is nil'
16
+ error 'could not get environment variables'
15
17
  return {}
16
18
  end
17
19
  end
@@ -22,9 +22,14 @@ module CfScript::Command
22
22
 
23
23
  def run(app_name, options = {}, &block)
24
24
  run_cf self, app_name, translate_options(options.dup) do |output|
25
- return unless can_run?(output, check_failed: false)
25
+ return unless good_run?(output, check_failed: false)
26
26
 
27
- if app = build_app_info(app_name, output)
27
+ no_start = options.key?(:flags) &&
28
+ options[:flags].include?(:no_start)
29
+
30
+ if no_start && output.ok?
31
+ return true
32
+ elsif app = build_app_info(app_name, output)
28
33
  block_given? ? yield(app) : app
29
34
  else
30
35
  error "app is nil"
@@ -0,0 +1,20 @@
1
+ module CfScript::Command
2
+ class Apps::RenameCommand < CfScript::Command::Base
3
+ def initialize
4
+ super(:apps, :rename)
5
+ end
6
+
7
+ def run(old_name, new_name, &block)
8
+ run_cf self, old_name, new_name do |output|
9
+ return false unless good_run?(output, check_failed: false)
10
+
11
+ if output.ok?
12
+ block_given? ? yield(true) : true
13
+ else
14
+ error "failed to rename app"
15
+ return false
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, &block)
8
8
  run_cf self, app_name do |output|
9
- return unless can_run?(output)
9
+ return unless good_run?(output)
10
10
 
11
11
  if app = build_app_info(app_name, output)
12
12
  block_given? ? yield(app) : app
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, &block)
8
8
  run_cf self, app_name do |output|
9
- return unless can_run?(output)
9
+ return unless good_run?(output)
10
10
 
11
11
  if app = build_app_info(app_name, output)
12
12
  block_given? ? yield(app) : app
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, var_name, var_value, &block)
8
8
  run_cf self, app_name, var_name, var_value do |output|
9
- return false unless can_run?(output)
9
+ return false unless good_run?(output)
10
10
 
11
11
  return true if output.contains?("\nOK\n")
12
12
 
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, &block)
8
8
  run_cf self, app_name do |output|
9
- return unless can_run?(output)
9
+ return unless good_run?(output)
10
10
 
11
11
  if app = build_app_info(app_name, output)
12
12
  block_given? ? yield(app) : app
@@ -6,12 +6,13 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, &block)
8
8
  run_cf self, app_name do |output|
9
- return false unless can_run?(output, check_failed: false)
9
+ return false unless good_run?(output, check_failed: false)
10
10
 
11
11
  if output.ok?
12
12
  block_given? ? yield(true) : true
13
13
  else
14
- error "failed to stop"
14
+ error "failed to stop app"
15
+ return false
15
16
  end
16
17
  end
17
18
  end
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(app_name, var_name, &block)
8
8
  run_cf self, app_name, var_name do |output|
9
- return false unless can_run?(output)
9
+ return false unless good_run?(output)
10
10
 
11
11
  return true if output.contains?("\nOK\n")
12
12
 
@@ -17,7 +17,7 @@ module CfScript::Command
17
17
  'Showing health and status for app'
18
18
  )
19
19
 
20
- if attributes
20
+ unless attributes.empty?
21
21
  app = CfScript::AppInfo.new(app_name, attributes)
22
22
 
23
23
  if rows = output.table(INSTANCE_STATUS_TABLE)
@@ -40,6 +40,8 @@ require 'cf_script/command/cf/apps/restage'
40
40
  require 'cf_script/command/cf/apps/env'
41
41
  require 'cf_script/command/cf/apps/set_env'
42
42
  require 'cf_script/command/cf/apps/unset_env'
43
+ require 'cf_script/command/cf/apps/rename'
44
+ require 'cf_script/command/cf/apps/delete'
43
45
 
44
46
  module CfScript::Command::Apps
45
47
  CfScript::Command.register AppsCommand
@@ -52,4 +54,6 @@ module CfScript::Command::Apps
52
54
  CfScript::Command.register EnvCommand
53
55
  CfScript::Command.register SetEnvCommand
54
56
  CfScript::Command.register UnsetEnvCommand
57
+ CfScript::Command.register RenameCommand
58
+ CfScript::Command.register DeleteCommand
55
59
  end
@@ -10,7 +10,7 @@ module CfScript::Command::General
10
10
 
11
11
  def run(url = nil, &block)
12
12
  run_cf self, url do |output|
13
- return unless can_run?(output)
13
+ return unless good_run?(output)
14
14
 
15
15
  if output.contains? API_NOT_SET
16
16
  error API_NOT_SET
@@ -6,7 +6,7 @@ module CfScript::Command::General
6
6
 
7
7
  def run(username, password, &block)
8
8
  run_cf self, username, password do |output|
9
- unless can_run?(output, check_failed: false)
9
+ unless good_run?(output, check_failed: false)
10
10
  if output.credentials_rejected?
11
11
  error 'Credentials were rejected'
12
12
  else
@@ -20,7 +20,7 @@ module CfScript::Command::General
20
20
  end
21
21
 
22
22
  run_cf self, *args do |output|
23
- unless can_run?(output, check_failed: false)
23
+ unless good_run?(output, check_failed: false)
24
24
  if output.credentials_rejected?
25
25
  error 'Credentials were rejected'
26
26
  else
@@ -6,7 +6,7 @@ module CfScript::Command::General
6
6
 
7
7
  def run(*args, &block)
8
8
  run_cf self, *args do |output|
9
- return false unless can_run?(output)
9
+ return false unless good_run?(output)
10
10
 
11
11
  block_given? ? yield(output.ok?) : output.ok?
12
12
  end
@@ -11,7 +11,7 @@ module CfScript::Command
11
11
  space = args.first && args.first.key?(:s) ? args.first[:s] : ''
12
12
 
13
13
  run_cf self, *args do |output|
14
- return nil unless can_run?(output, check_failed: false)
14
+ return nil unless good_run?(output, check_failed: false)
15
15
 
16
16
  # TODO: check org not found too
17
17
 
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(host, domain, &block)
8
8
  run_cf self, host, domain do |output|
9
- return false unless can_run?(output)
9
+ return false unless good_run?(output)
10
10
 
11
11
  exists = output.matches? /^Route #{host}.#{domain} does exist/
12
12
 
@@ -8,7 +8,7 @@ module CfScript::Command
8
8
  options = host ? { n: host } : {}
9
9
 
10
10
  run_cf self, space, domain, options do |output|
11
- return false unless can_run?(output)
11
+ return false unless good_run?(output)
12
12
 
13
13
  if exists = output.contains?(/^OK$/)
14
14
  block_given? ? yield(exists) : exists
@@ -5,10 +5,13 @@ module CfScript::Command
5
5
  end
6
6
 
7
7
  def run(domain, host = nil, force = true, &block)
8
- options = host ? { n: host, flags: [:f] } : { flags: [:f] }
8
+ options = {}
9
+
10
+ options[:n] = host if host
11
+ options[:flags] = [:f] if force
9
12
 
10
13
  run_cf self, domain, options do |output|
11
- return false unless can_run?(output)
14
+ return false unless good_run?(output)
12
15
 
13
16
  if deleted = output.ok?
14
17
  block_given? ? yield(deleted) : deleted
@@ -8,7 +8,7 @@ module CfScript::Command
8
8
  options = host ? { n: host } : {}
9
9
 
10
10
  run_cf self, app_name, domain, options do |output|
11
- return false unless can_run?(output,
11
+ return false unless good_run?(output,
12
12
  check_status: false,
13
13
  check_failed: false,
14
14
  )
@@ -8,7 +8,7 @@ module CfScript::Command
8
8
 
9
9
  def run(*args, &block)
10
10
  run_cf self do |output|
11
- return unless can_run?(output)
11
+ return unless good_run?(output)
12
12
 
13
13
  if rows = output.table(ROUTES_TABLE)
14
14
  routes = build_route_info(rows)
@@ -8,7 +8,7 @@ module CfScript::Command
8
8
  options = host ? { n: host } : {}
9
9
 
10
10
  run_cf self, app_name, domain, options do |output|
11
- return false unless can_run?(output,
11
+ return false unless good_run?(output,
12
12
  check_status: false,
13
13
  check_failed: false,
14
14
  )
@@ -6,7 +6,7 @@ module CfScript::Command
6
6
 
7
7
  def run(space_name, &block)
8
8
  run_cf self, space_name do |output|
9
- return unless can_run?(output)
9
+ return unless good_run?(output)
10
10
 
11
11
  if space = build_space(space_name, output)
12
12
  block_given? ? yield(space) : space