auser-poolparty 1.2.4 → 1.2.7

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 (52) hide show
  1. data/VERSION.yml +1 -1
  2. data/bin/cloud +8 -1
  3. data/bin/cloud-contract +1 -1
  4. data/bin/cloud-provision +0 -1
  5. data/bin/server-cloud-elections +9 -9
  6. data/bin/server-list-active +10 -17
  7. data/bin/server-manage-election +4 -5
  8. data/examples/basic.rb +5 -4
  9. data/examples/fairchild.rb +1 -1
  10. data/lib/poolparty.rb +1 -1
  11. data/lib/poolparty/core/hash.rb +10 -2
  12. data/lib/poolparty/helpers/optioner.rb +5 -5
  13. data/lib/poolparty/lite.rb +5 -2
  14. data/lib/poolparty/modules/cloud_resourcer.rb +12 -5
  15. data/lib/poolparty/modules/pretty_printer.rb +1 -1
  16. data/lib/poolparty/monitors/monitor_rack.rb +2 -2
  17. data/lib/poolparty/monitors/monitors/{time_monitor.rb → clock_monitor.rb} +2 -2
  18. data/lib/poolparty/monitors/monitors/neighborhood_monitor.rb +8 -5
  19. data/lib/poolparty/monitors/monitors/stats_monitor.rb +45 -29
  20. data/lib/poolparty/net/remoter/connections.rb +0 -1
  21. data/lib/poolparty/net/remoter/interactive.rb +6 -6
  22. data/lib/poolparty/net/remoter_base.rb +10 -2
  23. data/lib/poolparty/net/remoter_bases/ec2/ec2.rb +14 -6
  24. data/lib/poolparty/net/remoter_bases/metavirt/metavirt.rb +1 -1
  25. data/lib/poolparty/plugins/apache2/apache.rb +16 -8
  26. data/lib/poolparty/poolparty/cloud.rb +22 -5
  27. data/lib/poolparty/poolparty/default.rb +21 -15
  28. data/lib/poolparty/poolparty/key.rb +1 -1
  29. data/lib/poolparty/poolparty/neighborhoods.rb +15 -4
  30. data/lib/poolparty/poolparty/pool.rb +1 -1
  31. data/lib/poolparty/poolparty/resource.rb +1 -0
  32. data/lib/poolparty/provision/boot_strapper.rb +10 -4
  33. data/lib/poolparty/provision/dr_configure.rb +9 -9
  34. data/lib/poolparty/schema.rb +5 -6
  35. data/lib/poolparty/templates/monitor.ru +1 -0
  36. data/spec/poolparty/core/ordered_hash_spec.rb +7 -7
  37. data/spec/poolparty/net/remote_instance_spec.rb +1 -1
  38. data/spec/poolparty/poolparty/cloud_spec.rb +18 -0
  39. data/spec/poolparty/poolparty/example_spec.rb +29 -9
  40. data/spec/poolparty/poolparty/key_spec.rb +1 -1
  41. data/spec/poolparty/poolparty/neighborhoods_spec.rb +1 -1
  42. data/tasks/poolparty.rake +2 -0
  43. data/vendor/gems/dslify/VERSION.yml +4 -0
  44. data/vendor/gems/dslify/dslify.gemspec +29 -0
  45. data/vendor/gems/dslify/lib/dslify.rb +1 -1
  46. data/vendor/gems/dslify/test/dslify_test.rb +82 -13
  47. data/vendor/gems/git-style-binaries/VERSION.yml +1 -1
  48. data/vendor/gems/git-style-binaries/doc/poolparty-binaries.screenplay +389 -20
  49. data/vendor/gems/git-style-binaries/git-style-binaries.gemspec +2 -2
  50. data/vendor/gems/git-style-binaries/lib/git-style-binary/helpers/name_resolver.rb +2 -2
  51. data/vendor/gems/git-style-binaries/lib/git-style-binary/parser.rb +2 -2
  52. metadata +5 -3
@@ -17,6 +17,7 @@ module PoolParty
17
17
  JSON.parse(h).each {|k,v| self[k.to_sym] = v}
18
18
  end
19
19
  end
20
+
20
21
 
21
22
  def [](k)
22
23
  hsh[k]
@@ -53,16 +54,14 @@ module PoolParty
53
54
 
54
55
  $pool_specfile = "/etc/poolparty/clouds.rb"
55
56
 
56
- remoter_base = PoolParty::Remote.module_eval(options.remote_base.split('::')[-1].camelcase)
57
- # TODO: Seriously, make this sexier
58
-
57
+ # TODO: Seriously, make this sexier
59
58
  cld = OpenStruct.new(options)
60
59
  cld.keypair = ::PoolParty::Key.new("/etc/poolparty/#{node[:keypair]}")
61
- cld.remoter_base = remoter_base
60
+ # cld.remoter_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
61
+ cld.remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
62
62
  cld.build_and_store_new_config_file = "/etc/poolparty/clouds.json"
63
63
  cld.dependency_resolver = PoolParty.module_eval(options.dependency_resolver.split("::")[-1].camelcase).send(:new)
64
-
65
- cld
64
+
66
65
  end
67
66
  end
68
67
  end
@@ -9,6 +9,7 @@ require "poolparty/monitors/monitor_rack"
9
9
  app = Rack::Builder.new do
10
10
  # use Rack::Reloader, 2
11
11
  use Rack::ShowExceptions
12
+ use Rack::CommonLogger
12
13
  # use Rack::PostBodyContentTypeParser #parses json requests to params hash
13
14
  run Monitors::MonitorRack.new()
14
15
  end
@@ -38,11 +38,11 @@ describe "Ordered Hash" do
38
38
  @oh[:arr] = [1,2,3]
39
39
  @oh.to_json.should == "{\"var1\":10,\"var2\":2,\"var3\":3,\"var4\":4,\"arr\":[1,2,3]}"
40
40
  end
41
- it "PoolParty Key" do
42
- @oh[:key] = [Key.new, Key.new('path/to/nowhere')]
43
- expected=<<JSO
44
- {\"var1\":10,\"var2\":2,\"var3\":3,\"var4\":4,\"key\":[{\"basename\":\"id_rsa\",\"full_filepath\": \"/etc/poolparty/id_rsa\"},{\"basename\":\"path/to/nowhere\",\"full_filepath\": \"/etc/poolparty/path/to/nowhere\"}]}
45
- JSO
46
- @oh.to_json.should == expected.strip
47
- end
41
+ it "PoolParty Key" #do
42
+ # @oh[:key] = [Key.new, Key.new('path/to/nowhere')]
43
+ # expected=<<JSO
44
+ # {\"var1\":10,\"var2\":2,\"var3\":3,\"var4\":4,\"key\":[{\"basename\":\"id_rsa\",\"full_filepath\": \"/etc/poolparty/id_rsa\"},{\"basename\":\"path/to/nowhere\",\"full_filepath\": \"/etc/poolparty/path/to/nowhere\"}]}
45
+ # JSO
46
+ # @oh.to_json.should == expected.strip
47
+ # end
48
48
  end
@@ -5,7 +5,7 @@ include PoolParty::Remote
5
5
 
6
6
  describe "Remote Instance" do
7
7
  before(:each) do
8
- @valid_hash = {:ip => "127.0.0.1", :name => "master", :responding => "true"}
8
+ @valid_hash = {:public_ip=>'33.44.55.66', :ip => "127.0.0.1", :name => "master", :responding => "true"}
9
9
  end
10
10
 
11
11
  it "should have tests for the abstaract RemoteInstance class" do
@@ -296,6 +296,24 @@ describe "Cloud" do
296
296
  end
297
297
  end
298
298
  end
299
+
300
+ describe "JSON" do
301
+ before(:each) do
302
+ pool :jason do
303
+ user "fred"
304
+ minimum_instances 10
305
+ access_key "pool_a_key"
306
+ cloud :stratus do
307
+ keypair "fake_keypair"
308
+ access_key "cloud_a_key"
309
+ end
310
+ end
311
+
312
+ end
313
+ it "should have to_json method" do
314
+ clouds[:stratus].to_json.class.should == String
315
+ end
316
+ end
299
317
 
300
318
  # describe "instances" do
301
319
  # before(:each) do
@@ -1,6 +1,26 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require "open-uri"
3
3
 
4
+ # pool :application do
5
+ # instances 1..5
6
+ #
7
+ # cloud :basic_app do
8
+ # minimum_instances 3
9
+ # keypair 'front'
10
+ # image_id "ami-abc123"
11
+ # has_file :name => "/etc/motd", :content => "Welcome to your PoolParty instance"
12
+ # end
13
+ #
14
+ # cloud :basic_db do
15
+ # using :vmrun do
16
+ # vmx_hash "/path/to/vmx_file" => "192.168.248.122"
17
+ # end
18
+ # minimum_instances 1
19
+ # image_id "ami-1234bc"
20
+ # end
21
+ #
22
+ # end
23
+
4
24
  describe "basic" do
5
25
  before(:each) do
6
26
  PoolParty.reset!
@@ -24,17 +44,17 @@ describe "basic" do
24
44
  it "should have a cloud called :db" do
25
45
  pools[:application].clouds[:basic_db].should_not == nil
26
46
  end
27
- it "should set the minimum_instances on the cloud to 2 (overriding the pool options)" do
28
- pools[:application].minimum_instances.should == 3
29
- clouds[:basic_app].minimum_instances.should == 12
47
+ it "should set the minimum_instances on the cloud (overriding the pool options)" do
48
+ pools[:application].minimum_instances.should == 1
49
+ clouds[:basic_app].minimum_instances.should == 3
30
50
  end
31
- it "should set the maximum_instances on the cloud to 50" do
32
- clouds[:basic_app].maximum_instances.should == 50
51
+ it "should set the maximum_instances on the cloud to 5" do
52
+ clouds[:basic_app].maximum_instances.should == 5
33
53
  end
34
- it "should set the minimum_instances on the db cloud to 3" do
35
- clouds[:basic_db].minimum_instances.should == 19
36
- clouds[:basic_app].minimum_instances.should == 12
37
- pools[:application].minimum_instances.should ==3
54
+ it "should set the minimum_instances on the db cloud " do
55
+ clouds[:basic_db].minimum_instances.should == 1
56
+ clouds[:basic_app].minimum_instances.should == 3
57
+ pools[:application].minimum_instances.should == 1
38
58
  end
39
59
  it "should set the parent to the pool" do
40
60
  clouds[:basic_app].parent.should == pools[:application]
@@ -8,7 +8,7 @@ describe "Key" do
8
8
  Key.new.filepath.should == "id_rsa"
9
9
  end
10
10
  it "should provide valid to_json" do
11
- lambda {Key.new("file").to_json}.should_not raise_error end
11
+ lambda {Key.new("file").to_hash.to_json}.should_not raise_error end
12
12
  describe "that exists" do
13
13
  before(:each) do
14
14
  @keypair = "/var/home/id_rsa"
@@ -41,7 +41,7 @@ describe "Neighborhoods" do
41
41
  Neighborhoods.clump(sample_instances_list,filepath)
42
42
  end
43
43
  it "should load from the default properly with the first's instance's ip" do
44
- str = "[{\"instance_id\":\"master\",\"launching_time\":\"2009/03/26 01:06:18 -0700\",\"ip\":\"127.0.0.1\"},{\"instance_id\":\"node1\",\"launching_time\":\"2009/03/26 01:06:18 -0700\",\"ip\":\"127.0.0.2\"}]"
44
+ str = "{\"instances\":[{\"instance_id\":\"master\",\"launching_time\":\"2009/03/26 01:06:18 -0700\",\"ip\":\"127.0.0.1\"},{\"instance_id\":\"node1\",\"launching_time\":\"2009/03/26 01:06:18 -0700\",\"ip\":\"127.0.0.2\"}]}"
45
45
  ::File.should_receive(:file?).with("/etc/poolparty/neighborhood.json").and_return true
46
46
  ::File.stub!(:file?).and_return false
47
47
 
@@ -11,6 +11,8 @@ task :slow_spec do
11
11
  puts "#{stats[:failures]} total errors"
12
12
  end
13
13
  namespace(:poolparty) do
14
+ task :build_gem => ["poolparty:vendor:setup", "poolparty:vendor:update", :gemspec, :build]
15
+
14
16
  namespace(:setup) do
15
17
  desc "Generate a manifest for quicker loading times"
16
18
  task :manifest do
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dslify}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ari Lerner"]
9
+ s.date = %q{2009-05-14}
10
+ s.email = %q{arilerner@mac.com}
11
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
12
+ s.files = ["README.rdoc", "VERSION.yml", "lib/dslify.rb", "test/dslify_test.rb", "test/test_helper.rb", "LICENSE"]
13
+ s.has_rdoc = true
14
+ s.homepage = %q{http://github.com/auser/dslify}
15
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.3.2}
18
+ s.summary = %q{TODO}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
@@ -68,7 +68,7 @@ module Dslify
68
68
  def method_missing(m,*a,&block)
69
69
  if m.to_s[-1..-1] == '?'
70
70
  t = m.to_s.gsub(/\?/, '').to_sym
71
- warn "DEPRECATED: Dslify will no longer support ? methods. Fix yo code."
71
+ warn "DEPRECATED: Dslify will no longer support ? methods. Fix yo code.: #{m}"
72
72
  respond_to?(t) && !self.send(t, *a, &block).nil?
73
73
  else
74
74
  super
@@ -26,7 +26,9 @@ class QuickieTest < Test::Unit::TestCase
26
26
  end
27
27
  it "should set and retrieve values back with an = sign" do
28
28
  @q.author = ["Ari Lerner"]
29
+ @q.snobs = "Michael"
29
30
  assert_equal @q.author, ["Ari Lerner"]
31
+ assert_equal @q.snobs, "Michael"
30
32
  end
31
33
  it "should set these values in the h Hash on the object" do
32
34
  assert_raise NoMethodError do
@@ -43,19 +45,6 @@ class QuickieTest < Test::Unit::TestCase
43
45
  end
44
46
  assert_equal @q.author.class, Quickie
45
47
  end
46
- it "should not blow up when called with a ? at the end of the method" do
47
- @q.set_vars_from_options({:pete => "and pete"})
48
- assert_nothing_raised do
49
- @q.pete?
50
- end
51
- end
52
- it "should return false if the method exists" do
53
- assert_equal @q.bobs?, false
54
- end
55
- it "should return true if the option is set" do
56
- @q.gilligans_island "is a tv show"
57
- assert @q.gilligans_island?
58
- end
59
48
  end
60
49
 
61
50
  context "calling methods on an instance" do
@@ -194,4 +183,84 @@ class QuickieTest < Test::Unit::TestCase
194
183
  # assert_equal t.taste, @bar.taste
195
184
  # end
196
185
  end
186
+ context "methods" do
187
+ setup do
188
+ class MrDanger
189
+ include Dslify
190
+ default_options :where_to => "The Grand Canyon"
191
+ def initialize(o={})
192
+ set_vars_from_options(o)
193
+ end
194
+ def where_to(*a)
195
+ "New York City"
196
+ end
197
+ end
198
+ end
199
+
200
+ should "not override the method where_to" do
201
+ assert_equal MrDanger.new.where_to, "New York City"
202
+ end
203
+ should "not override the method where_to when called with set_vars_from_options" do
204
+ assert_equal MrDanger.new(:where_to => "Bank of America").where_to, "New York City"
205
+ end
206
+ end
207
+
208
+ context "when calling with a block" do
209
+ setup do
210
+ class ToddTheSquare
211
+ include Dslify
212
+ default_options :provider => :vmrun, :t => :nothing
213
+
214
+ def provider(&block)
215
+ instance_eval &block if block
216
+ end
217
+ end
218
+ end
219
+
220
+ should "should not evaluate the block" do
221
+ tts = ToddTheSquare.new
222
+ assert_equal tts.t, :nothing
223
+ end
224
+
225
+ should "should evaluate the block" do
226
+ tts = ToddTheSquare.new
227
+ tts.provider do
228
+ self.t = :something
229
+ end
230
+ assert_equal tts.t, :something
231
+ end
232
+ end
233
+
234
+ context "set_vars_from_options" do
235
+ setup do
236
+ class VarrrrrrrrMatey
237
+ include Dslify
238
+ default_options :say => "hello", :to => "world"
239
+
240
+ def initialize(o={}, &block)
241
+ set_vars_from_options(o)
242
+ instance_eval &block if block
243
+ end
244
+
245
+ def to_s
246
+ say + " " + to
247
+ end
248
+ end
249
+ end
250
+
251
+ should "set the vars on the options with no options" do
252
+ assert_equal VarrrrrrrrMatey.new.to_s, "hello world"
253
+ end
254
+ should "update the options if called with options" do
255
+ assert_equal VarrrrrrrrMatey.new({:say => "goodbye"}).to_s, "goodbye world"
256
+ end
257
+ should "update the options if called with block" do
258
+ @v = VarrrrrrrrMatey.new do
259
+ to "me"
260
+ end
261
+ assert_equal @v.to_s, "hello me"
262
+ end
263
+ end
264
+
265
+
197
266
  end
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 6
4
+ :patch: 7
@@ -8,38 +8,407 @@
8
8
  plugin "terminal"
9
9
  plugin "keystack"
10
10
 
11
- launch "Terminal", at(10, 10, 800, 600)
11
+ def cleanup
12
+ FileUtils.rm_rf(File.expand_path("~/poolparty-gsb-test/bin"))
13
+ end
14
+
15
+ cleanup
16
+
17
+ perform "Introduction" do
18
+ launch "Terminal", at(10, 10, 800, 600)
19
+ pause 1
20
+
21
+ say <<-eos
22
+ Hey, welcome to the git-style-binaries screencast.
23
+ First, lets talk a little about what a git-style-binary even is.
24
+ eos
25
+ end
26
+
27
+ cli "cd #{ENV['POOLPARTY_SRC']}"
28
+
29
+ perform "Describing Git Binaries" do
30
+ pause 1
31
+ while_saying "as you can see here, git has over one hundred binaries that all perform various functions." do
32
+ type "git-"
33
+ pause 1
34
+ keystroke_literal('tab')
35
+ keystroke_literal('tab')
36
+ type "y"
37
+ pause 2
38
+ type " "
39
+ keystroke_using('u', :control)
40
+ end
41
+
42
+ while_saying "for instance, we have. git-add for adding files. git-status for
43
+ getting the status of our repo and so on" do
44
+ cli "git-add"
45
+ pause 2
46
+ cli "git-status"
47
+ end
48
+
49
+ while_saying "one of the nice things about the git-style-binaries is that you
50
+ can choose to call the command with or without the dash.. so for instance, i
51
+ can call either 'git-add' or 'git add'." do
52
+ cli "git-add"
53
+ pause 2
54
+ cli "git add"
55
+ end
56
+
57
+ perform "Describe Help" do
58
+ while_saying "the help in git is also very handy. for instance, if you call
59
+ git help it will give you a listing of many of the available subcommands" do
60
+ cli "git help"
61
+ move to(44, 94)
62
+ move to(133, 87)
63
+ move to(127, 346)
64
+ move to(41, 343)
65
+ move to(44, 94)
66
+ end
67
+
68
+ while_saying "you can also ask for help about any of the subcommands. if we
69
+ want to get help on 'git-add', we simply type 'git help add'" do
70
+ cli "git help add"
71
+ type 'q'
72
+ end
73
+ end
74
+
75
+ pause 2
76
+
77
+ perform "Describe Validation" do
78
+ while_saying "git also performs option validation, as you would expect. for
79
+ instance, if we provide an invalid option such as 'asdf' we get an error" do
80
+ cli "git add --asdf"
81
+ end
82
+ end
83
+
84
+ while_saying "the goal of the git-style-binaries ruby gem is to bring this
85
+ functionality to your own custom binaries in an easy-to-use way. so lets take
86
+ a look at an example"
87
+ pause 2
88
+
89
+ end
90
+
91
+
92
+ perform "Introducing PoolParty" do
93
+ while_saying "we're going to be using PoolParty's binaries as an example on
94
+ how to build git-style-binaries using this gem" do
95
+ end
12
96
 
13
- # say <<-eos
14
- # Hey, welcome to the git-style-binaries screencast.
15
- # First, lets talk a little about what a git-style-binary even is.
16
- # eos
97
+ while_saying "just in case you're not familiar with poolparty, its a cloud
98
+ management system by Ari Lerner. It allows you to manage your cloud using ruby
99
+ code and plugins rather than, say, folders of bash scripts." do
100
+ # launch "Safari", at(10, 10, 800, 600)
101
+ # url "http://www.poolpartyrb.com" # ?
102
+ # pause 3
103
+ # keystroke_literal_using('tab', :command) # go back to terminal
104
+ end
105
+
106
+ while_saying "in poolparty the main binary is 'cloud'. we can do cloud help to see all of the available subcommands." do
107
+ cli "cloud help"
108
+ end
109
+
110
+ while_saying "as you can see here we have 'cloud-start', for starting our
111
+ cloud, 'cloud configure' to reconfigure our cloud after we change something,
112
+ even cloud-ssh, to ssh directly into a node of our cloud." do
113
+ pause 2
114
+ move to(86, 400)
115
+ pause 2
116
+ move to(72, 380)
117
+ end
118
+
119
+ pause 2
120
+ type "q"
121
+
122
+ while_saying "what i'd like to do is, rather than just opening up the existing
123
+ binaries, Im going to build poolparty-like binaries from the ground up. this
124
+ way you can see how to do this on your own."
125
+ end
126
+
127
+
128
+ perform "entering poolpary" do
129
+ cli "cd ~"
130
+ cli "mkdir -p poolparty-gsb-test/bin"
131
+ cli "cd poolparty-gsb-test"
132
+ end
133
+
134
+ perform "creating primary" do
135
+ while_saying "first we need to create our *primary* binary." do
136
+ cli "vim bin/cloud"
137
+ pause 2
138
+ type_pre <<-eof
139
+ i#!/usr/bin/env ruby
140
+ require 'git-style-binary/command'
141
+ eof
142
+ cli ":w"
143
+ cli ":e"
144
+ end
145
+
146
+ while_saying "and thats it! thats all we need if we want the default functionality" do
147
+ cli ":x"
148
+ end
149
+ end
17
150
 
18
151
  pause 1
19
- while_saying "as you can see here, git has over one hundred binaries that all perform various functions." do
20
- type "git-"
152
+
153
+ # opt :cloud_name, "Name of the working cloud", :type => String, :default => nil
154
+
155
+ perform "create cloud-start" do
156
+ while_saying "now lets create cloud-start.
157
+ we start by requiring git-style-binary/command, just like last time.
158
+ now we open up a #command block.
159
+ specify a version.
160
+ specify a banner and a short description.
161
+ and we put what we want to do in the 'run' block." do
162
+
163
+ cli "vim bin/cloud-start"
21
164
  pause 1
22
- keystroke_literal('tab')
23
- keystroke_literal('tab')
24
- type "y"
165
+ vim_insert <<-eof
166
+ #!/usr/bin/env ruby
167
+ eof
168
+ cli ":w"
169
+ cli ":e"
170
+ cli ":set paste" # no auto indending
171
+ type "j"
172
+
173
+ vim_insert <<-eof
174
+ require 'git-style-binary/command'
175
+
176
+ GitStyleBinary.command do
177
+ version "PoolParty cloud-start 0.0.1"
178
+ banner <<-\EOS
179
+ Usage: cloud-start \#{all_options_string}
180
+
181
+ EOS
182
+ eof
183
+
184
+ vim_insert <<-eof
185
+ short_desc "List the clouds"
186
+
187
+ run do |command|
188
+ puts "Options: \#{command.opts.inspect}"
189
+ end
190
+ end
191
+ eof
192
+ end
193
+
194
+ while_saying "the run block yields a command object. commands has an 'opts' attribute accessor, or you can just use brackets on 'command'" do
195
+ type ":0
196
+ cli ":w"
197
+ end
198
+
199
+ while_saying "you can add more options by calling 'opt' in the command block" do
200
+ vim_line_after("short_")
201
+ vim_insert " opt :name, \"the name of the cloud you are starting\", :type => String,
25
202
  :default => \"default\""
203
+ end
204
+
205
+ while_saying "git-style-binaries uses the gem trollop for the option parsing.
206
+ trollop allows you to easily add validations and type conversions to options.
207
+ see their website for information on the syntax" do
208
+ end
209
+ # cli ":x"
210
+ pause 2
211
+ end
212
+
213
+ perform "running cloud-start" do
214
+ while_saying "now lets run cloud-start -h" do
215
+ keystroke_using('t', :command) # go back to terminal
216
+ pause 1
217
+ cli "cd poolparty-gsb-test"
218
+ cli "chmod +x bin/*"
219
+ cli "./bin/cloud-start -h"
220
+ end
221
+ pause 2
222
+ while_saying "notice a few things here. we've got automatic coloring, a list of all of our flags, and a list of all of our options. trollop has even automatically created the short flags for us" do
223
+ move to(36, 82)
224
+ pause 1
225
+ move to(123, 100)
226
+ pause 1
227
+ move to(279, 200)
228
+ pause 1
229
+ move to(96, 261)
230
+ move to(80, 521)
231
+ move to(96, 261)
232
+ pause 1
233
+ move to(53, 255)
234
+ move to(71, 259)
235
+ pause 1
236
+ move to(53, 255)
237
+ end
238
+ pause 3
239
+ type "q"
240
+ keystroke_using('w', :command) # go back to terminal
26
241
  pause 2
27
- type " "
28
- keystroke_using('u', :control)
29
242
  end
30
243
 
31
- while_saying "so, for instance, we have. git-add. for adding files. git-status for getting the status of our repo and so on" do
32
- cli "git-add"
244
+
245
+ perform "creating cloud-ssh" do
246
+
247
+ while_saying "i'd like to show you a few more features of gsb. first lets create one more simple binary - cloud ssh" do
248
+ cli ":x"
249
+ pause 1
250
+
251
+ cli "vim bin/cloud-ssh"
252
+ pause 1
253
+ vim_insert <<-eof
254
+ #!/usr/bin/env ruby
255
+ eof
256
+ cli ":w"
257
+ cli ":e"
258
+ cli ":set paste" # no auto indending
259
+ type "j"
260
+
261
+ vim_insert <<-eof
262
+ require 'git-style-binary/command'
263
+
264
+ GitStyleBinary.command do
265
+ version "PoolParty cloud-ssh 0.0.1"
266
+ banner <<-\EOS
267
+ Usage: cloud-ssh \#{all_options_string}
268
+
269
+ EOS
270
+ eof
271
+
272
+ vim_insert <<-eof
273
+ short_desc "ssh into your cloud"
274
+ opt :name, "name of the cloud", :type => String
275
+
276
+ run do |command|
277
+ puts "you are sshing into \#{command[:name]}!"
278
+ end
279
+ end
280
+ eof
281
+ pause 1
282
+ cli ":x"
33
283
  pause 2
34
- cli "git-status"
284
+ end
285
+
35
286
  end
36
287
 
37
- while_saying "we want to emulate that effect with poolparty." do
38
- cli "cd #{ENV['POOLPARTY_SRC']}"
288
+ perform "show help with both binaries" do
289
+
290
+ while_saying "now we have two binaries, cloud-start and cloud-ssh" do
291
+ cli "tree ."
292
+ end
293
+
294
+ while_saying "one of the cool things about gsb is that it will automatically pick up these files when you run the help commands" do
295
+ cli "./bin/cloud -h"
296
+ end
297
+
298
+ while_saying "see, here we have both cloud-start and cloud-ssh, along with their short descriptions, which are automatically loaded from their respective files" do
299
+ pause 0.5
300
+ shake 46, 401
301
+ pause 0.5
302
+ shake 49, 338
303
+ pause 0.5
304
+ move to(88, 291)
305
+ move to(354, 297)
306
+ pause 1
307
+ cli 'q'
308
+ end
309
+
39
310
  end
40
311
 
41
- pause 2
312
+ perform "modify cloud primary" do
42
313
 
43
- while_saying "just in case you're not familiar with poolparty, its a cloud management system. "
44
- # open safari poolpartyrb.com
314
+ while_saying "notice that if we do cloud help start. we see that it already
315
+ has a number of options. these options come from the default binary options." do
316
+ cli "./bin/cloud help start"
317
+ pause 1
318
+ move to(123, 266)
319
+ pause 1
320
+ shake 116, 431
321
+ pause 1
322
+ move to(99, 515)
323
+ type 'q'
324
+ end
325
+
326
+ while_saying "gsb's get their options from three places 1) the default in code 2) the primary and 3) the subcommand itself" do
327
+ type "1) default options (in code)"
328
+ pause 0.5
329
+ keystroke_using('u', :control)
330
+ type "2) primary (ex: ./bin/cloud)"
331
+ pause 0.5
332
+ keystroke_using('u', :control)
333
+ type "3) subcommand (./bin/cloud-start)"
334
+ pause 0.5
335
+ keystroke_using('u', :control)
336
+ end
337
+
338
+ while_saying "if we add options to our primary these will be automatically inherited by the subcommands." do
339
+ end
340
+
341
+ while_saying "we want to be able to specify the name of our clouds.rb
342
+ specfile in any of the subcommands. so all we need to do is add that to the
343
+ primary.
344
+
345
+ now when we want to customize the primary we need to do a bit more work.
346
+ " do
347
+ cli "vim bin/cloud"
348
+ pause 2
349
+ type "jj"
350
+ type 'o' + ''
351
+ vim_insert <<-eof
352
+ GitStyleBinary.primary do
353
+ version "PoolParty cloud command"
354
+ banner <<-\EOS
355
+ eof
356
+ vim_insert <<-eof
357
+ Usage: cloud \\\#{all_options_string} COMMAND [ARGS]
358
+
359
+ The cloud subcommands commands are:
360
+ \\\#{GitStyleBinary.pretty_known_subcommands(:short).join(" ")}
361
+ EOS
362
+ opt :spec, "The name of the clouds.rb file", :type => String
363
+
364
+ run do
365
+ end
366
+ end
367
+ eof
368
+ pause 2
369
+ type ":x
370
+ end
371
+ end
372
+
373
+ perform "show subcommand opts" do
374
+
375
+ while_saying "now if we run the subcommand -h, we see that the spec option is there" do
376
+ cli "./bin/cloud-start -h"
377
+ pause 1
378
+ shake 61, 259
379
+ pause 1
380
+ type "q"
381
+ end
382
+
383
+ while_saying "you can also specify callbacks in your primary if you want to.
384
+ for instance, say you want to call something before the run block of each
385
+ subcommand. simply define a before_run block in your primary" do
386
+
387
+ cli "vim bin/cloud"
388
+ pause 2
389
+ vim_line_after("opt ")
390
+ vim_insert <<-eof
391
+ before_run do
392
+ puts "this happened before run"
393
+ end
394
+ eof
395
+ pause 2
396
+ type ":x
397
+
398
+ end
399
+
400
+ while_saying "now we run our subcommand again. and you can see that it gets the options!" do
401
+ cli "./bin/cloud-start"
402
+ end
403
+
404
+ end
405
+
406
+ perform "summary" do
407
+ while_saying "i hope this has been helpful for you. now go out and create your own git-style-binaries!"
408
+ end
409
+
410
+
411
+ at_exit do
412
+ cleanup
413
+ end
45
414
 
46
415
  # vim: ft=ruby