capricorn 0.2.25 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +1 -0
  3. data/bin/capricorn-app-scaffolder +27 -0
  4. data/bin/capricorn-gem-spec +33 -0
  5. data/bin/capricornctl +12 -0
  6. data/bin/capricornd +31 -0
  7. data/erlang/lib/bert/doc/overview.edoc +4 -0
  8. data/erlang/lib/bert/ebin/bert.app +9 -0
  9. data/erlang/lib/bert/rebar.config +3 -0
  10. data/erlang/lib/bert/src/bert.erl +69 -0
  11. data/erlang/lib/bertio/doc/overview.edoc +4 -0
  12. data/erlang/lib/bertio/ebin/bertio.app +9 -0
  13. data/erlang/lib/bertio/rebar.config +3 -0
  14. data/erlang/lib/bertio/src/bertio.erl +28 -0
  15. data/erlang/lib/bertrpc/doc/overview.edoc +4 -0
  16. data/erlang/lib/bertrpc/ebin/bertrpc.app +12 -0
  17. data/erlang/lib/bertrpc/include/bertrpc.hrl +1 -0
  18. data/erlang/lib/bertrpc/rebar.config +5 -0
  19. data/erlang/lib/bertrpc/src/bertrpc.erl +471 -0
  20. data/erlang/lib/bertrpc/src/bertrpc_hello_world.erl +148 -0
  21. data/erlang/lib/bertrpc/src/fd_tcp.erl +376 -0
  22. data/erlang/lib/capricorn/doc/overview.edoc +4 -0
  23. data/erlang/lib/capricorn/ebin/capricorn.app +56 -0
  24. data/erlang/lib/capricorn/include/capricorn.hrl +76 -0
  25. data/erlang/lib/capricorn/rebar.config +3 -0
  26. data/erlang/lib/capricorn/src/cap_application.erl +170 -0
  27. data/erlang/lib/capricorn/src/cap_cluster.erl +121 -0
  28. data/erlang/lib/capricorn/src/cap_cluster_gems.erl +422 -0
  29. data/erlang/lib/capricorn/src/cap_config.erl +25 -0
  30. data/erlang/lib/capricorn/src/cap_dets_updater.erl +26 -0
  31. data/erlang/lib/capricorn/src/cap_event_sup.erl +35 -0
  32. data/erlang/lib/capricorn/src/cap_events.erl +24 -0
  33. data/erlang/lib/capricorn/src/cap_external_api.erl +87 -0
  34. data/erlang/lib/capricorn/src/cap_external_apps_api.erl +125 -0
  35. data/erlang/lib/capricorn/src/cap_external_gems_api.erl +85 -0
  36. data/erlang/lib/capricorn/src/cap_external_machines_api.erl +18 -0
  37. data/erlang/lib/capricorn/src/cap_gem_utils.erl +111 -0
  38. data/erlang/lib/capricorn/src/cap_internal_api.erl +69 -0
  39. data/erlang/lib/capricorn/src/cap_internal_apps_api.erl +38 -0
  40. data/erlang/lib/capricorn/src/cap_log.erl +113 -0
  41. data/erlang/lib/capricorn/src/cap_machine.erl +338 -0
  42. data/erlang/lib/capricorn/src/cap_machine_apps.erl +410 -0
  43. data/erlang/lib/capricorn/src/cap_machine_apps_sup.erl +57 -0
  44. data/erlang/lib/capricorn/src/cap_sup.erl +200 -0
  45. data/erlang/lib/capricorn/src/cap_util.erl +278 -0
  46. data/erlang/lib/capricorn/src/capricorn.erl +45 -0
  47. data/erlang/lib/capricorn/src/capricorn_app.erl +36 -0
  48. data/erlang/lib/emq/ebin/emq.app +17 -0
  49. data/erlang/lib/emq/src/emq.erl +261 -0
  50. data/erlang/lib/emq/src/emq_app.erl +11 -0
  51. data/erlang/lib/emq/src/emq_pool.erl +178 -0
  52. data/erlang/lib/emq/src/emq_queue.erl +332 -0
  53. data/erlang/lib/emq/src/emq_status.erl +148 -0
  54. data/erlang/lib/emq/src/emq_sup.erl +132 -0
  55. data/erlang/lib/gcd/ebin/gcd.app +18 -0
  56. data/erlang/lib/gcd/include/gcd.hrl +5 -0
  57. data/erlang/lib/gcd/rebar.config +3 -0
  58. data/erlang/lib/gcd/src/gcd.erl +51 -0
  59. data/erlang/lib/gcd/src/gcd_app.erl +13 -0
  60. data/erlang/lib/gcd/src/gcd_event.erl +39 -0
  61. data/erlang/lib/gcd/src/gcd_server.erl +30 -0
  62. data/erlang/lib/gcd/src/gcd_srv.erl +186 -0
  63. data/erlang/lib/gcd/src/gcd_sup.erl +18 -0
  64. data/erlang/rebar +0 -0
  65. data/erlang/rebar.config +9 -0
  66. data/erlang/rel/overlay/bin/capricornd +146 -0
  67. data/erlang/rel/overlay/erts-vsn/bin/erl +34 -0
  68. data/erlang/rel/overlay/erts-vsn/bin/nodetool +80 -0
  69. data/erlang/rel/overlay/etc/capricorn/app.config +59 -0
  70. data/erlang/rel/overlay/etc/capricorn/cluster-vm.args +21 -0
  71. data/erlang/rel/overlay/etc/capricorn/machine-vm.args +21 -0
  72. data/erlang/rel/reltool.config +43 -0
  73. data/ext/Makefile +2 -0
  74. data/ext/extconf.rb +1 -0
  75. data/lib/capricorn-client.rb +86 -0
  76. data/lib/capricorn-client/cli/applications.rb +256 -0
  77. data/lib/capricorn-client/cli/gems.rb +57 -0
  78. data/lib/capricorn-client/cli/machines.rb +9 -0
  79. data/lib/capricorn-client/helpers.rb +62 -0
  80. data/lib/capricorn.rb +5 -99
  81. data/lib/capricorn/driver.rb +86 -0
  82. data/lib/capricorn/recipes/apache-debian.rb +112 -0
  83. data/lib/capricorn/recipes/centos-plesk.rb +162 -0
  84. data/lib/capricorn/recipes/macports.rb +54 -0
  85. data/lib/capricorn/system_context.rb +49 -0
  86. data/lib/capricorn/version.rb +5 -0
  87. metadata +233 -74
  88. data/app_generators/engine/engine_generator.rb +0 -40
  89. data/app_generators/engine/templates/Gmfile +0 -20
  90. data/app_generators/engine/templates/MIT-LICENSE.txt +0 -20
  91. data/app_generators/engine/templates/README.rdoc +0 -7
  92. data/app_generators/engine/templates/config/initializers/rails_init.rb +0 -1
  93. data/app_generators/engine/templates/config/routes.rb +0 -2
  94. data/app_generators/engine/templates/gitignore +0 -9
  95. data/app_generators/engine/templates/init.rb +0 -1
  96. data/app_generators/engine/templates/lib/engine.rb +0 -4
  97. data/app_generators/engine/templates/rails/init.rb +0 -1
  98. data/app_generators/engine/templates/tasks/engine_tasks.rake +0 -4
  99. data/bin/capricorn +0 -20
  100. data/lib/capricorn/actor.rb +0 -23
  101. data/lib/capricorn/actor/actions.rb +0 -76
  102. data/lib/capricorn/actors/apache_actor.rb +0 -56
  103. data/lib/capricorn/actors/base_actor.rb +0 -335
  104. data/lib/capricorn/actors/host_file_actor.rb +0 -77
  105. data/lib/capricorn/actors/mysql_actor.rb +0 -20
  106. data/lib/capricorn/actors/passenger_actor.rb +0 -28
  107. data/lib/capricorn/actors/plesk_actor.rb +0 -228
  108. data/lib/capricorn/actors/sqlite3_actor.rb +0 -44
  109. data/lib/capricorn/app_runner.rb +0 -108
  110. data/lib/capricorn/apps/dev.rb +0 -15
  111. data/lib/capricorn/apps/engines.rb +0 -33
  112. data/lib/capricorn/apps/jobs.rb +0 -35
  113. data/lib/capricorn/apps/satellite.rb +0 -68
  114. data/lib/capricorn/apps/server.rb +0 -73
  115. data/lib/capricorn/client.rb +0 -48
  116. data/lib/capricorn/client/auth_token.rb +0 -98
  117. data/lib/capricorn/daemon.rb +0 -81
  118. data/lib/capricorn/exception_handler.rb +0 -79
  119. data/lib/capricorn/extentions/rubygems_plugin.rb +0 -27
  120. data/lib/capricorn/extentions/thor_extentions.rb +0 -32
  121. data/lib/capricorn/job_queue.rb +0 -203
  122. data/lib/capricorn/satellite.rb +0 -52
  123. data/lib/capricorn/satellite/actions.rb +0 -55
  124. data/lib/capricorn/satellite/dependency_loader.rb +0 -82
  125. data/lib/capricorn/satellite/persistence.rb +0 -50
  126. data/lib/capricorn/server.rb +0 -144
  127. data/lib/capricorn/server/daemon.rb +0 -83
  128. data/lib/capricorn/server/proxy.rb +0 -25
  129. data/lib/capricorn/server/security.rb +0 -120
  130. data/lib/capricorn/system.rb +0 -218
  131. data/lib/capricorn/system/config.rb +0 -49
  132. data/lib/capricorn/system/helper.rb +0 -21
  133. data/lib/capricorn/system/options.rb +0 -79
  134. data/lib/capricorn/system/process_user.rb +0 -73
  135. data/lib/capricorn/system/satellites.rb +0 -44
  136. data/lib/capricorn/system/shell.rb +0 -80
  137. data/lib/rubygems_plugin.rb +0 -1
  138. data/spec/actor/actions_spec.rb +0 -13
  139. data/spec/spec_helper.rb +0 -1
@@ -1,77 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class HostFileActor < Capricorn::Actor
5
-
6
- on_install_satellite :add_host_name
7
- on_uninstall_satellite :remove_host_name
8
-
9
- # addthe fost form the host file
10
- def add_host_name
11
- content = load_file
12
- content[:capricorn]['127.0.0.1'] ||= []
13
- content[:capricorn]['127.0.0.1'].push satellite.domain
14
- dump_file(content)
15
- end
16
-
17
- # remove the fost form the host file
18
- def remove_host_name
19
- content = load_file
20
- content[:capricorn]['127.0.0.1'] ||= []
21
- content[:capricorn]['127.0.0.1'].delete satellite.domain
22
- dump_file(content)
23
- end
24
-
25
- SEPERATOR = '### the content below this line is managed by capricorn'
26
-
27
- private
28
-
29
- def load_file
30
- content = File.read(system.host_file_path)
31
- content_parts = content.split(Capricorn::Actors::HostFileActor::SEPERATOR)
32
-
33
- user_hosts = content_parts[0] || ''
34
- host_lines = content_parts[1] || ''
35
- host_lines = host_lines.split(/\n/)
36
- host_lines = host_lines.inject({}) do |m, host_line|
37
- next if host_line.nil?
38
- host_line = host_line.strip
39
- next if host_line[0,1] == '#'
40
- next if host_line == ''
41
-
42
- host_line = host_line.split(/\s+/)
43
- ip = host_line.shift
44
- m[ip] ||= []
45
- m[ip].concat(host_line)
46
-
47
- m
48
- end
49
-
50
- {
51
- :user => user_hosts,
52
- :capricorn => host_lines
53
- }
54
- end
55
-
56
- def dump_file(content)
57
- File.open(system.host_file_path, 'w+') do |f|
58
- f.puts content[:user].strip
59
- f.puts Capricorn::Actors::HostFileActor::SEPERATOR
60
- content[:capricorn].each do |ip, hosts|
61
- f.puts "#{ip} #{hosts.join(' ')}"
62
- end
63
- end
64
- end
65
-
66
- module Config
67
-
68
- # path to the hosts file.
69
- def host_file_path(&block)
70
- option(:host_file_path, block) { |v| v or '/etc/hosts' }
71
- end
72
-
73
- end
74
-
75
- end
76
- end
77
- end
@@ -1,20 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class MysqlActor < Capricorn::Actor
5
-
6
- on_install_satellite :create_database
7
- before_uninstall_satellite :backup_database
8
- on_uninstall_satellite :drop_database
9
-
10
- def create_database
11
-
12
- end
13
-
14
- def drop_database
15
-
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,28 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class PassengerActor < Capricorn::Actor
5
-
6
- after_install_satellite :restart
7
- after_link_satellite :restart
8
-
9
- # restart the current satellite.
10
- def restart
11
- system.as_user(system.web_user, system.web_group) do
12
- tmp_restart = system.passenger_restart_txt
13
- FileUtils.touch tmp_restart, :verbose => true
14
- end
15
- end
16
-
17
- module Config
18
-
19
- # set the passneger restart file.
20
- def passenger_restart_txt(&block)
21
- satellite_option(:passenger_restart_txt, block) { |s, v| v || File.join(satellite_root, 'tmp', 'restart.txt') }
22
- end
23
-
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,228 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class PleskActor < Capricorn::Actor
5
-
6
- before_install_satellite :create_client
7
- before_install_satellite :create_domain
8
- after_install_satellite :link_htdocs
9
- after_install_satellite :reload_subdomains
10
- after_install_satellite :restart_apache
11
- on_install_satellite :create_database
12
- on_uninstall_satellite :drop_databases
13
-
14
- def create_client
15
- # only do this if this is needed
16
- if false
17
- unless system.client?(system.plesk_client)
18
- system.create_client(system.plesk_client, system.plesk_client, 'mypwd')
19
- end
20
- end
21
- end
22
-
23
- def create_domain
24
- unless system.domain?(satellite.basedomain)
25
- system.create_domain(system.plesk_client, satellite.basedomain,
26
- system.web_user[0,20], (rand(1_000_000_000) + 10_000).to_s)
27
- else
28
- httpdocs_path = "/var/www/vhosts/#{satellite.basedomain}/httpdocs"
29
- system.set_satellite_option(:web_user,
30
- system.get_user_name(File.stat(httpdocs_path).uid))
31
- end
32
-
33
- if satellite.subdomain? and !system.subdomain?(satellite.basedomain, satellite.subdomain)
34
- system.create_subdomain(satellite.basedomain, satellite.subdomain)
35
- end
36
-
37
- FileUtils.mkdir_p(system.satellite_root)
38
- FileUtils.mkdir_p(system.shared_root)
39
- FileUtils.chown_R(system.web_user, system.web_group, system.satellite_root)
40
- FileUtils.chown_R(system.web_user, system.web_group, system.shared_root)
41
- end
42
-
43
- def link_htdocs
44
- httpdocs_path = File.join(File.dirname(system.satellite_root), 'httpdocs')
45
- FileUtils.rm_rf(httpdocs_path)
46
- FileUtils.ln_s(system.satellite_root, httpdocs_path)
47
- FileUtils.chown_R(system.web_user, system.web_group, httpdocs_path)
48
-
49
- File.open(File.join(system.satellite_root, '../conf/vhost.conf'), 'w+') do |f|
50
- f.write %{DocumentRoot #{httpdocs_path}/public
51
- <Directory "#{httpdocs_path}/public">
52
- Options All
53
- AllowOverride All
54
- Order allow,deny
55
- Allow from all
56
- </Directory>
57
- }
58
- end
59
- end
60
-
61
- def reload_subdomains
62
- system.run("#{system.plesk_websrvmng_bin} --reconfigure-vhost --vhost-name=#{satellite.basedomain}")
63
- end
64
-
65
- def restart_apache
66
- system.run("#{system.plesk_httpd_bin} restart")
67
- end
68
-
69
- def create_database
70
- db_name = database_name_for(satellite)
71
- db_user = db_name[0,13]
72
- db_pswd = (rand(1_000_000_000) + 10_000).to_s
73
-
74
- create_database_for(satellite, :d, db_name, db_user, db_pswd)
75
- create_database_for(satellite, :t, db_name, db_user, db_pswd)
76
- create_database_for(satellite, :p, db_name, db_user, db_pswd)
77
-
78
- system.as_user(system.web_user, system.web_group) do
79
- db_file = File.join(system.satellite_root, 'config', 'database.yml')
80
- write_database_config(db_file, db_name, db_user, db_pswd)
81
- end
82
- end
83
-
84
- def drop_databases
85
- db_name = satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
86
-
87
- system.drop_database("#{db_name}_d")
88
- system.drop_database("#{db_name}_t")
89
- system.drop_database("#{db_name}_p")
90
- end
91
-
92
- def write_database_config(db_file, db_name, db_user, db_pswd)
93
- File.open(db_file, 'w+') { |f| f.write(%{
94
- development:
95
- adapter: mysql
96
- database: #{db_name}_d
97
- username: #{db_user}_ud
98
- password: #{db_pswd}
99
- host: localhost
100
- encoding: utf8
101
- socket: /var/lib/mysql/mysql.sock
102
-
103
- test:
104
- adapter: mysql
105
- database: #{db_name}_t
106
- username: #{db_user}_ut
107
- password: #{db_pswd}
108
- host: localhost
109
- encoding: utf8
110
- socket: /var/lib/mysql/mysql.sock
111
-
112
- production:
113
- adapter: mysql
114
- database: #{db_name}_p
115
- username: #{db_user}_up
116
- password: #{db_pswd}
117
- host: localhost
118
- encoding: utf8
119
- socket: /var/lib/mysql/mysql.sock
120
- }) }
121
- end
122
-
123
- def database_name_for(satellite)
124
- satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
125
- end
126
-
127
- def create_database_for(satellite, environment, db_name, db_user, db_pswd)
128
- db_name = "#{db_name}_#{environment}"
129
- db_user = "#{db_user}_u#{environment}"
130
- system.create_database(satellite.basedomain, db_name, db_user, db_pswd)
131
- end
132
-
133
- module Helper
134
-
135
- def create_client(name, login, pwd)
136
-
137
- end
138
-
139
- # check is the client exists
140
- def client?(login)
141
- !(run("#{plesk_client_bin} -i #{login}") =~ /Object not found: Client/)
142
- end
143
-
144
- # create a domain through plesk
145
- def create_domain(client, domain, user, passwd)
146
- run("#{plesk_domain_bin} -c #{domain} -clogin #{client} -status enabled -hosting true -hst_type phys -dns true -www true -login #{user} -passwd #{passwd} -shell /bin/bash")
147
- end
148
-
149
- # check if a domain exists with plesk
150
- def domain?(domain)
151
- !(run("#{plesk_domain_bin} -i #{domain}") =~ /Object not found: Domain/)
152
- end
153
-
154
- # create a subdomain through plesk
155
- def create_subdomain(basedomain, subdomain)
156
- run("#{plesk_subdomain_bin} -c #{subdomain} -d #{basedomain}")
157
- end
158
-
159
- # check if a subdomain exists with plesk
160
- def subdomain?(basedomain, subdomain)
161
- run("#{plesk_subdomain_bin} -i -s #{subdomain} -d #{basedomain}") =~ /SUCCESS: Gathering/
162
- end
163
-
164
- # create a database through plesk
165
- def create_database(basedomain, db_name, db_user, pwd)
166
- o = run("#{plesk_database_bin} -c #{db_name} -domain #{basedomain} -server #{plesk_database_server} -add_user #{db_user} -passwd #{pwd}")
167
- if o =~ /Database with requested name already exists/
168
- o = run("#{plesk_database_bin} -u #{db_name} -add_user #{db_user} -passwd #{pwd}")
169
- if o =~ /Unable to create database user: User/
170
- o = run("#{plesk_database_bin} -u #{db_name} -update_user #{db_user} -passwd #{pwd}")
171
- end
172
- end
173
- end
174
-
175
- # drop a database through plesk
176
- def drop_database(db_name)
177
- run("#{plesk_database_bin} -r #{db_name}")
178
- end
179
-
180
- end
181
-
182
- module Config
183
-
184
- # set the plesk client to be used for this satellite.
185
- def plesk_client(&block)
186
- satellite_option(:plesk_client, block)
187
- end
188
-
189
- # path to the client tool.
190
- def plesk_client_bin(&block)
191
- option(:plesk_client_bin, block) { |v| v or '/usr/local/psa/bin/client' }
192
- end
193
-
194
- # path to the domain tool.
195
- def plesk_domain_bin(&block)
196
- option(:plesk_domain_bin, block) { |v| v or '/usr/local/psa/bin/domain' }
197
- end
198
-
199
- # path to the subdomain tool.
200
- def plesk_subdomain_bin(&block)
201
- option(:plesk_subdomain_bin, block) { |v| v or '/usr/local/psa/bin/subdomain' }
202
- end
203
-
204
- # path to the database tool.
205
- def plesk_database_bin(&block)
206
- option(:plesk_database_bin, block) { |v| v or '/usr/local/psa/bin/database' }
207
- end
208
-
209
- # path to the websrvmng tool.
210
- def plesk_websrvmng_bin(&block)
211
- option(:plesk_websrvmng_bin, block) { |v| v or '/usr/local/psa/admin/sbin/websrvmng' }
212
- end
213
-
214
- # path to the httpd tool.
215
- def plesk_httpd_bin(&block)
216
- option(:plesk_httpd_bin, block) { |v| v or '/etc/init.d/httpd' }
217
- end
218
-
219
- # host and port of database server.
220
- def plesk_database_server(&block)
221
- option(:plesk_database_server, block)
222
- end
223
-
224
- end
225
-
226
- end
227
- end
228
- end
@@ -1,44 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class Sqlite3Actor < Capricorn::Actor
5
-
6
- after_install_satellite :write_config_file
7
-
8
- # write the +database.yml+ config file.
9
- def write_config_file
10
- system.as_user(system.web_user, system.web_group) do
11
-
12
- config = %{# SQLite version 3.x
13
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
14
- development:
15
- adapter: sqlite3
16
- database: db/system/development.sqlite3
17
- pool: 5
18
- timeout: 5000
19
-
20
- # Warning: The database defined as "test" will be erased and
21
- # re-generated from your development database when you run "rake".
22
- # Do not set this db to the same as development or production.
23
- test:
24
- adapter: sqlite3
25
- database: db/system/test.sqlite3
26
- pool: 5
27
- timeout: 5000
28
-
29
- production:
30
- adapter: sqlite3
31
- database: db/system/production.sqlite3
32
- pool: 5
33
- timeout: 5000
34
- }
35
-
36
- db_file = File.join(system.satellite_root, 'config', 'database.yml')
37
- File.open(db_file, 'w+') { |f| f.write config }
38
-
39
- end
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,108 +0,0 @@
1
- Capricorn.runtime_gem('thor', Capricorn::THOR_VERSION)
2
-
3
- require File.dirname(__FILE__)+'/extentions/thor_extentions'
4
-
5
- module Capricorn
6
-
7
- # AppRunner allows us to have multiple apps in different namespaces
8
- class AppRunner < Thor
9
-
10
- # register a subapplication with the app runner.
11
- def self.use(app)
12
- Capricorn::Apps.const_get(app)
13
- end
14
-
15
- # Override Thor#help so we can give info about not-yet-loaded tasks
16
- def help(task = nil)
17
- super
18
-
19
- unless task
20
- search = ".*#{search}" if options["substring"]
21
- search = /^#{search}.*/i
22
- group = options[:group] || "standard"
23
-
24
- classes = Thor.subclasses.select do |k|
25
- (options[:all] || k.group_name == group) &&
26
- Thor::Util.constant_to_thor_path(k.name) =~ search
27
- end
28
- display_klasses(classes)
29
- end
30
- end
31
-
32
- # forward actions to the sub apps
33
- def method_missing(meth, *args)
34
- meth = meth.to_s
35
- super(meth.to_sym, *args) unless meth.include?(?:)
36
-
37
- begin
38
- task = Thor[meth]
39
- task.parse(task.klass.new, ARGV[1..-1])
40
- rescue => e
41
- puts e.message
42
- end
43
- end
44
-
45
- private
46
-
47
- def display_klasses(klasses = Thor.subclasses)
48
- klasses -= [Thor, Capricorn::AppRunner]
49
-
50
- if klasses.empty?
51
- puts "\033[1;34mNo Thor tasks available\033[0m"
52
- else
53
- maxima = column_maxima_for(klasses)
54
-
55
- puts # add some spacing
56
- klasses.each { |k| display_tasks(k, maxima.first, maxima.last) }
57
- end
58
- end
59
-
60
- def column_maxima_for(klasses)
61
- # Calculate the largest base class name
62
- klass_with_longest_name = klasses.max do |x,y|
63
- Thor::Util.constant_to_thor_path(x.name).size <=> Thor::Util.constant_to_thor_path(y.name).size
64
- end
65
- max_base = klass_with_longest_name.name.size
66
-
67
- # Calculate the size of the largest option description
68
- max_left_item = klasses.max do |x,y|
69
- total_x = (x.maxima.usage + x.maxima.opt).to_i
70
- total_y = (y.maxima.usage + y.maxima.opt).to_i
71
- total_x <=> total_y
72
- end
73
-
74
- max_left = max_left_item.maxima.usage + max_left_item.maxima.opt
75
-
76
- return [max_base, max_left]
77
- end
78
-
79
- def display_tasks(klass, max_base, max_left)
80
- if klass.tasks.values.length > 1
81
-
82
- base = Thor::Util.constant_to_thor_path(klass.name)
83
-
84
- if base.to_a.empty?
85
- base = 'default'
86
- puts "\033[1;35m#{base}\033[0m"
87
- else
88
- puts "\033[1;34m#{base}\033[0m"
89
- end
90
-
91
- puts "-" * base.length
92
-
93
- klass.tasks.each true do |name, task|
94
- format_string = "%-#{max_left + max_base + 5}s"
95
- print format_string % task.formatted_usage(true)
96
- puts task.description
97
- end
98
-
99
- unless klass.opts.empty?
100
- puts "\nglobal options: #{Options.new(klass.opts)}"
101
- end
102
-
103
- puts # add some spacing
104
- end
105
- end
106
-
107
- end
108
- end