shelly 0.1.23 → 0.1.24.pre

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ * [feature] Option --help [-h] added to all tasks
2
+
1
3
  ## 0.1.23 / 2012-08-08
2
4
 
3
5
  * Don't display mail server IP address in shelly info
data/README.md CHANGED
@@ -13,7 +13,3 @@
13
13
  ## Running tests
14
14
 
15
15
  bundle exec rake
16
-
17
- or
18
-
19
- guard
data/lib/shelly/app.rb CHANGED
@@ -9,8 +9,7 @@ module Shelly
9
9
  SERVER_SIZES = %w(small large)
10
10
 
11
11
  attr_accessor :code_name, :databases, :ruby_version, :environment,
12
- :git_url, :domains, :web_server_ip, :mail_server_ip, :size, :thin,
13
- :redeem_code
12
+ :git_url, :domains, :web_server_ip, :size, :thin, :redeem_code
14
13
 
15
14
  def initialize(code_name = nil)
16
15
  self.code_name = code_name
@@ -32,7 +32,7 @@ module Shelly
32
32
 
33
33
  say "Available backups:", :green
34
34
  say_new_line
35
- print_table(to_display, :ident => 2)
35
+ print_table(to_display, :indent => 2)
36
36
  else
37
37
  say "No database backups available"
38
38
  end
@@ -4,13 +4,21 @@ require "thor/thor"
4
4
  require "thor/group"
5
5
  require "thor/options"
6
6
  require "thor/arguments"
7
- require "thor/basic"
8
7
 
9
8
  module Shelly
10
9
  module CLI
11
10
  class Command < Thor
12
11
  include Helpers
13
12
  class_option :debug, :type => :boolean, :desc => "Show debug information"
13
+ class_option :help, :type => :boolean, :aliases => "-h", :desc => "Describe available tasks or one specific task"
14
+
15
+ def initialize(*)
16
+ super
17
+ if options[:help]
18
+ help(self.class.send(:retrieve_task_name, ARGV.dup))
19
+ exit(0)
20
+ end
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -79,8 +79,7 @@ module Shelly
79
79
  end
80
80
 
81
81
  desc "delete PATH", "Delete configuration file"
82
- def delete(path = nil)
83
- say_error "No configuration file specified" unless path
82
+ def delete(path)
84
83
  app = multiple_clouds(options[:cloud], "delete #{path}")
85
84
  answer = yes?("Are you sure you want to delete 'path' (yes/no): ")
86
85
  if answer
@@ -19,7 +19,6 @@ module Shelly
19
19
 
20
20
  check_unknown_options!(:except => :rake)
21
21
 
22
- # FIXME: it should be possible to pass single symbol, instead of one element array
23
22
  before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :logs, :delete, :info, :ip, :logout, :execute, :rake, :setup, :console, :dbconsole]
24
23
  before_hook :inside_git_repository?, :only => [:add, :setup, :check]
25
24
 
@@ -134,7 +133,7 @@ module Shelly
134
133
  end
135
134
  [app["code_name"], "| #{state.humanize}#{msg}"]
136
135
  end
137
- print_table(apps_table, :ident => 2)
136
+ print_table(apps_table, :indent => 2)
138
137
  else
139
138
  say "You have no clouds yet", :green
140
139
  end
@@ -149,22 +148,21 @@ module Shelly
149
148
  " (deployment log: `shelly deploys show last -c #{app}`)"
150
149
  end
151
150
  say "Cloud #{app}:", msg.present? ? :red : :green
152
- print_wrapped "State: #{app.state}#{msg}", :ident => 2
151
+ print_wrapped "State: #{app.state}#{msg}", :indent => 2
153
152
  say_new_line
154
- print_wrapped "Deployed commit sha: #{app.git_info["deployed_commit_sha"]}", :ident => 2
155
- print_wrapped "Deployed commit message: #{app.git_info["deployed_commit_message"]}", :ident => 2
156
- print_wrapped "Deployed by: #{app.git_info["deployed_push_author"]}", :ident => 2
153
+ print_wrapped "Deployed commit sha: #{app.git_info["deployed_commit_sha"]}", :indent => 2
154
+ print_wrapped "Deployed commit message: #{app.git_info["deployed_commit_message"]}", :indent => 2
155
+ print_wrapped "Deployed by: #{app.git_info["deployed_push_author"]}", :indent => 2
157
156
  say_new_line
158
- print_wrapped "Repository URL: #{app.git_info["repository_url"]}", :ident => 2
159
- print_wrapped "Web server IP: #{app.web_server_ip}", :ident => 2
160
- print_wrapped "Mail server IP: #{app.mail_server_ip}", :ident => 2
157
+ print_wrapped "Repository URL: #{app.git_info["repository_url"]}", :indent => 2
158
+ print_wrapped "Web server IP: #{app.web_server_ip}", :indent => 2
161
159
  say_new_line
162
160
  if app.statistics.present?
163
- print_wrapped "Statistics:", :ident => 2
161
+ print_wrapped "Statistics:", :indent => 2
164
162
  app.statistics.each do |stat|
165
- print_wrapped "#{stat['name']}:", :ident => 4
166
- print_wrapped "Load average: 1m: #{stat['load']['avg01']}, 5m: #{stat['load']['avg05']}, 15m: #{stat['load']['avg15']}", :ident => 6
167
- print_wrapped "CPU: #{stat['cpu']['wait']}%, MEM: #{stat['memory']['percent']}%, SWAP: #{stat['swap']['percent']}%", :ident => 6
163
+ print_wrapped "#{stat['name']}:", :indent => 4
164
+ print_wrapped "Load average: 1m: #{stat['load']['avg01']}, 5m: #{stat['load']['avg05']}, 15m: #{stat['load']['avg15']}", :indent => 6
165
+ print_wrapped "CPU: #{stat['cpu']['wait']}%, MEM: #{stat['memory']['percent']}%, SWAP: #{stat['swap']['percent']}%", :indent => 6
168
166
  end
169
167
  end
170
168
  rescue Client::GatewayTimeoutException
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.1.23"
2
+ VERSION = "0.1.24.pre"
3
3
  end
data/lib/thor/options.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  class Thor
2
2
  class Options < Arguments
3
-
4
3
  def check_unknown!
4
+ unknown = @extra.select { |str| str =~ /^--?(?:(?!--).)*$/ }
5
5
  raise UnknownArgumentError, "shelly: unrecognized option '#{@unknown.join(', ')}'\n" +
6
6
  "Usage: shelly [COMMAND]... [OPTIONS]\n" +
7
- "Try 'shelly --help' for more information" unless @unknown.empty?
7
+ "Try 'shelly --help' for more information" unless unknown.empty?
8
8
  end
9
-
10
9
  end
11
10
  end
data/lib/thor/thor.rb CHANGED
@@ -2,7 +2,7 @@ class Thor
2
2
  class << self
3
3
  def before_hook(method, options = {})
4
4
  @hook = {} unless @hook
5
- @hook[method] = options
5
+ @hook[method] = {:only => Array(options[:only])}
6
6
  end
7
7
 
8
8
  def hooks
@@ -12,9 +12,9 @@ class Thor
12
12
  def send(*args)
13
13
  if args.first == :dispatch && !args[2].empty?
14
14
  running_task = args[2].first
15
-
15
+ help = args[2].include?('--help') || args[2].include?('-h')
16
16
  @hook.each do |method, options|
17
- if options[:only].include?(running_task.to_sym)
17
+ if options[:only].include?(running_task.to_sym) && !help
18
18
  new.send(method)
19
19
  end
20
20
  end
@@ -28,12 +28,46 @@ class Thor
28
28
  rescue Thor::Error => e
29
29
  ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.message)
30
30
  exit(1) if exit_on_failure?
31
+ rescue Errno::EPIPE
32
+ # This happens if a thor task is piped to something like `head`,
33
+ # which closes the pipe when it's done reading. This will also
34
+ # mean that if the pipe is closed, further unnecessary
35
+ # computation will not occur.
36
+ exit(0)
31
37
  end
32
38
 
33
- # We overwrite this method so namespace is show
39
+ # We overwrite this method so namespace is shown
34
40
  # shelly *backup* restore FILENAME
35
- def handle_argument_error(task, error)
36
- raise InvocationError, "#{task.name.inspect} was called incorrectly. Call as #{self.banner(task, nil, self.to_s != 'Shelly::CLI::Main').inspect}."
41
+ def handle_argument_error(task, error, arity = nil)
42
+ banner = self.banner(task, nil, self.to_s != 'Shelly::CLI::Main')
43
+ raise InvocationError, "#{task.name.inspect} was called incorrectly. Call as `#{banner}`"
44
+ end
45
+
46
+ protected
47
+ # this has to overwritten so that in tests args are passed correctly
48
+ # only change is the commented line
49
+ # its for some edge cases when boolean options are passed in some
50
+ # strange order
51
+ def dispatch(meth, given_args, given_opts, config) #:nodoc:
52
+ meth ||= retrieve_task_name(given_args)
53
+ task = all_tasks[normalize_task_name(meth)]
54
+
55
+ if task
56
+ args, opts = Thor::Options.split(given_args)
57
+ else
58
+ args, opts = given_args, nil
59
+ task = Thor::DynamicTask.new(meth)
60
+ end
61
+
62
+ opts = given_opts || opts || []
63
+ config.merge!(:current_task => task, :task_options => task.options)
64
+
65
+ instance = new(args, opts, config)
66
+ yield instance if block_given?
67
+ # args = instance.args
68
+ trailing = args[Range.new(arguments.size, -1)]
69
+
70
+ instance.invoke_task(task, trailing || [])
37
71
  end
38
72
  end
39
73
  end
data/shelly.gemspec CHANGED
@@ -14,8 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.rubyforge_project = "shelly"
15
15
  s.add_development_dependency "rspec", "~> 2.11.0"
16
16
  s.add_development_dependency "rake"
17
- s.add_development_dependency "guard"
18
- s.add_development_dependency "guard-rspec"
19
17
  s.add_development_dependency "simplecov"
20
18
  if RUBY_PLATFORM =~ /darwin/
21
19
  s.add_development_dependency "ruby_gntp"
@@ -23,7 +21,7 @@ Gem::Specification.new do |s|
23
21
  end
24
22
  s.add_development_dependency "fakefs"
25
23
  s.add_development_dependency "fakeweb"
26
- s.add_runtime_dependency "wijet-thor", "~> 0.14.7"
24
+ s.add_runtime_dependency "thor", "~> 0.15.4"
27
25
  s.add_runtime_dependency "rest-client"
28
26
  s.add_runtime_dependency "json"
29
27
  s.add_runtime_dependency "progressbar"
@@ -29,7 +29,6 @@ describe Shelly::CLI::Files do
29
29
 
30
30
  it "should exit if rsync isn't installed" do
31
31
  FakeFS::File.stub(:executable?).and_return(false)
32
-
33
32
  $stdout.should_receive(:puts).with(red "You need to install rsync in order to upload and download files")
34
33
  lambda { invoke(@cli_files, :upload, "some/path") }.should raise_error(SystemExit)
35
34
  end
@@ -25,38 +25,34 @@ describe Shelly::CLI::Main do
25
25
 
26
26
  describe "#help" do
27
27
  it "should display available commands" do
28
- expected = <<-OUT
29
- Tasks:
30
- shelly add # Add a new cloud
31
- shelly backup <command> # Manage database backups
32
- shelly check # Check if application fulfills Shelly Cloud requirements
33
- shelly config <command> # Manage application configuration files
34
- shelly console # Open application console
35
- shelly dbconsole # Run rails dbconsole
36
- shelly delete # Delete the cloud
37
- shelly deploys <command> # View deploy logs
38
- shelly files <command> # Upload and download files to and from persistent storage
39
- shelly help [TASK] # Describe available tasks or one specific task
40
- shelly info # Show basic information about cloud
41
- shelly list # List available clouds
42
- shelly login [EMAIL] # Log into Shelly Cloud
43
- shelly logout # Logout from Shelly Cloud
44
- shelly logs # Show latest application logs
45
- shelly open # Open application page in browser
46
- shelly rake TASK # Run rake task
47
- shelly redeploy # Redeploy application
48
- shelly register [EMAIL] # Register new account
49
- shelly setup # Set up git remotes for deployment on Shelly Cloud
50
- shelly start # Start the cloud
51
- shelly stop # Shutdown the cloud
52
- shelly user <command> # Manage collaborators
53
- shelly version # Display shelly version
54
-
55
- Options:
56
- [--debug] # Show debug information
57
- OUT
58
28
  out = IO.popen("bin/shelly --debug").read.strip
59
- out.should == expected.strip
29
+ out.should include("Tasks:")
30
+ out.should include("shelly add # Add a new cloud")
31
+ out.should include("shelly backup <command> # Manage database backups")
32
+ out.should include("shelly check # Check if application fulfills Shelly Cloud requirements")
33
+ out.should include("shelly config <command> # Manage application configuration files")
34
+ out.should include("shelly console # Open application console")
35
+ out.should include("shelly dbconsole # Run rails dbconsole")
36
+ out.should include("shelly delete # Delete the cloud")
37
+ out.should include("shelly deploys <command> # View deploy logs")
38
+ out.should include("shelly files <command> # Upload and download files to and from persistent storage")
39
+ out.should include("shelly help [TASK] # Describe available tasks or one specific task")
40
+ out.should include("shelly info # Show basic information about cloud")
41
+ out.should include("shelly list # List available clouds")
42
+ out.should include("shelly login [EMAIL] # Log into Shelly Cloud")
43
+ out.should include("shelly logout # Logout from Shelly Cloud")
44
+ out.should include("shelly logs # Show latest application logs")
45
+ out.should include("shelly open # Open application page in browser")
46
+ out.should include("shelly rake TASK # Run rake task")
47
+ out.should include("shelly redeploy # Redeploy application")
48
+ out.should include("shelly register [EMAIL] # Register new account")
49
+ out.should include("shelly setup # Set up git remotes for deployment on Shelly Cloud")
50
+ out.should include("shelly start # Start the cloud")
51
+ out.should include("shelly stop # Shutdown the cloud")
52
+ out.should include("shelly user <command> # Manage collaborators")
53
+ out.should include("Options")
54
+ out.should include("[--debug] # Show debug information")
55
+ out.should include("-h, [--help] # Describe available tasks or one specific task")
60
56
  end
61
57
 
62
58
  it "should display options in help for logs" do
@@ -68,6 +64,14 @@ OUT
68
64
  out.should include("[--from=FROM] # Time from which to find the logs")
69
65
  out.should include("[--debug] # Show debug information")
70
66
  end
67
+
68
+ it "should display help when user is not logged in" do
69
+ out = IO.popen("bin/shelly list --help").read.strip
70
+ out.should include("Usage:")
71
+ out.should include("shelly list")
72
+ out.should include("List available clouds")
73
+ out.should_not include("You are not logged in. To log in use: `shelly login`")
74
+ end
71
75
  end
72
76
 
73
77
  describe "#register" do
@@ -848,7 +852,7 @@ We have been notified about it. We will be adding new resources shortly")
848
852
  "repository_url" => "git@winniecloud.net:example-cloud",
849
853
  "deployed_push_author" => "megan@example.com"
850
854
  },
851
- "web_server_ip" => "22.22.22.22" }.merge(options)
855
+ "web_server_ip" => "22.22.22.22"}.merge(options)
852
856
  end
853
857
  end
854
858
 
data/spec/spec_helper.rb CHANGED
@@ -23,4 +23,4 @@ class FakeFS::File
23
23
  def self.executable?(file)
24
24
  true
25
25
  end
26
- end
26
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
5
- prerelease:
4
+ version: 0.1.24.pre
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Shelly Cloud team
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -43,38 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: guard
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: guard-rspec
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
46
  - !ruby/object:Gem::Dependency
79
47
  name: simplecov
80
48
  requirement: !ruby/object:Gem::Requirement
@@ -156,13 +124,13 @@ dependencies:
156
124
  - !ruby/object:Gem::Version
157
125
  version: '0'
158
126
  - !ruby/object:Gem::Dependency
159
- name: wijet-thor
127
+ name: thor
160
128
  requirement: !ruby/object:Gem::Requirement
161
129
  none: false
162
130
  requirements:
163
131
  - - ~>
164
132
  - !ruby/object:Gem::Version
165
- version: 0.14.7
133
+ version: 0.15.4
166
134
  type: :runtime
167
135
  prerelease: false
168
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -170,7 +138,7 @@ dependencies:
170
138
  requirements:
171
139
  - - ~>
172
140
  - !ruby/object:Gem::Version
173
- version: 0.14.7
141
+ version: 0.15.4
174
142
  - !ruby/object:Gem::Dependency
175
143
  name: rest-client
176
144
  requirement: !ruby/object:Gem::Requirement
@@ -279,7 +247,6 @@ files:
279
247
  - .travis.yml
280
248
  - CHANGELOG.md
281
249
  - Gemfile
282
- - Guardfile
283
250
  - README.md
284
251
  - Rakefile
285
252
  - bin/shelly
@@ -307,7 +274,6 @@ files:
307
274
  - lib/shelly/user.rb
308
275
  - lib/shelly/version.rb
309
276
  - lib/thor/arguments.rb
310
- - lib/thor/basic.rb
311
277
  - lib/thor/options.rb
312
278
  - lib/thor/thor.rb
313
279
  - scrolls/shellycloud.rb
@@ -346,9 +312,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
346
312
  required_rubygems_version: !ruby/object:Gem::Requirement
347
313
  none: false
348
314
  requirements:
349
- - - ! '>='
315
+ - - ! '>'
350
316
  - !ruby/object:Gem::Version
351
- version: '0'
317
+ version: 1.3.1
352
318
  requirements: []
353
319
  rubyforge_project: shelly
354
320
  rubygems_version: 1.8.24
data/Guardfile DELETED
@@ -1,6 +0,0 @@
1
- guard 'rspec', :cli => '--color --format doc' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch('lib/shelly/helpers.rb') { "spec" }
4
- watch(%r{^lib/shelly/(.+)\.rb$}) { |m| "spec/shelly/#{m[1]}_spec.rb" }
5
- watch('spec/spec_helper.rb') { "spec" }
6
- end
data/lib/thor/basic.rb DELETED
@@ -1,9 +0,0 @@
1
- class Thor
2
- module Shell
3
-
4
- def print_wrapped(*args)
5
- shell.print_wrapped(*args)
6
- end
7
-
8
- end
9
- end