lib/shelly/cli/main.rb in shelly-0.0.55.pre vs lib/shelly/cli/main.rb in shelly-0.0.55
- old
+ new
@@ -14,13 +14,13 @@
register(Deploys, "deploys", "deploys <command>", "View deploy logs")
register(Config, "config", "config <command>", "Manage application configuration files")
check_unknown_options!(:except => :rake)
# FIXME: it should be possible to pass single symbol, instead of one element array
- before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :logs, :delete, :ip, :logout, :execute, :rake]
- before_hook :inside_git_repository?, :only => [:add]
- before_hook :cloudfile_present?, :only => [:logs, :stop, :start, :ip, :execute, :rake]
+ before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :logs, :delete, :ip, :logout, :execute, :rake, :setup]
+ before_hook :inside_git_repository?, :only => [:add, :setup]
+ before_hook :cloudfile_present?, :only => [:logs, :stop, :start, :ip, :execute, :rake, :setup]
map %w(-v --version) => :version
desc "version", "Display shelly version"
def version
say "shelly version #{Shelly::VERSION}"
@@ -30,10 +30,11 @@
def register(email = nil)
user = Shelly::User.new
say "Registering with email: #{email}" if email
user.email = (email || ask_for_email)
user.password = ask_for_password
+ ask_for_acceptance_of_terms
user.register
if user.ssh_key_exists?
say "Uploading your public SSH key from #{user.ssh_key_path}"
else
say_error "No such file or directory - #{user.ssh_key_path}", :with_exit => false
@@ -79,12 +80,11 @@
@app = Shelly::App.new
@app.code_name = options["code-name"] || ask_for_code_name
@app.databases = options["databases"] || ask_for_databases
@app.create
- git_remote = @app.git_remote_exist?
- if !git_remote or (git_remote and yes?("Git remote #{@app} exists, overwrite (yes/no): "))
+ if overwrite_remote?(@app)
say "Adding remote #{@app} #{@app.git_url}", :green
@app.add_git_remote
else
say "You have to manually add git remote:"
say "`git remote add NAME #{@app.git_url}`"
@@ -115,14 +115,18 @@
def list
user = Shelly::User.new
apps = user.apps
unless apps.empty?
say "You have following clouds available:", :green
- print_table(apps.map do |app|
- state = app["state"] == "deploy_failed" ? " (Support has been notified)" : ""
- [app["code_name"], "| #{app["state"].gsub("_", " ")}#{state}"]
- end, :ident => 2)
+ apps_table = apps.map do |app|
+ state = app["state"]
+ msg = if state == "deploy_failed" || state == "configuration_failed"
+ " (deployment log: `shelly deploys show last -c #{app["code_name"]}`)"
+ end
+ [app["code_name"], "| #{state.gsub("_", " ")}#{msg}"]
+ end
+ print_table(apps_table, :ident => 2)
else
say "You have no clouds yet", :green
end
end
@@ -148,41 +152,74 @@
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
def start
multiple_clouds(options[:cloud], "start")
@app.start
say "Starting cloud #{@app}.", :green
+ say "This can take up to 10 minutes."
say "Check status with: `shelly list`"
rescue Client::ConflictException => e
case e[:state]
when "running"
- say_error "Not starting: cloud '#{@app}' is already running", :with_exit => false
+ say_error "Not starting: cloud '#{@app}' is already running"
when "deploying", "configuring"
- say_error "Not starting: cloud '#{@app}' is currently deploying", :with_exit => false
+ say_error "Not starting: cloud '#{@app}' is currently deploying"
when "no_code"
say_error "Not starting: no source code provided", :with_exit => false
say_error "Push source code using:", :with_exit => false
- say_error " git push production master", :with_exit => false
+ say " git push production master"
when "deploy_failed", "configuration_failed"
say_error "Not starting: deployment failed", :with_exit => false
say_error "Support has been notified", :with_exit => false
- say_error "Check `shelly deploys show last --cloud #{@app}` for reasons of failure", :with_exit => false
+ say_error "Check `shelly deploys show last --cloud #{@app}` for reasons of failure"
when "not_enough_resources"
say_error %{Sorry, There are no resources for your servers.
-We have been notified about it. We will be adding new resources shortly}, :with_exit => false
+We have been notified about it. We will be adding new resources shortly}
+ when "no_billing"
+ say_error "Please fill in billing details to start #{@app}.", :with_exit => false
+ say_error "Visit: #{@app.edit_billing_url}", :with_exit => false
+ when "payment_declined"
+ say_error "Not starting. Invoice for cloud '#{@app}' was declined."
end
- if !e[:can_be_started] and e[:state] == "turned_off"
- url = "#{@app.shelly.shellyapp_url}/apps/#{@app.code_name}/billing"
- say_error "Not starting.", :with_exit => false
- say_error "For more details please visit:", :with_exit => false
- say_error url
- end
exit 1
rescue Client::NotFoundException => e
raise unless e.resource == :cloud
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
end
+ desc "setup", "Set up clouds"
+ def setup
+ say "Investigating Cloudfile"
+ cloudfile = Cloudfile.new
+ cloudfile.clouds.each do |cloud|
+ begin
+ app = App.new(cloud)
+ say "Adding #{app} cloud", :green
+ app.git_url = app.attributes["git_info"]["repository_url"]
+ if overwrite_remote?(app)
+ say "git remote add #{app} #{app.git_url}"
+ app.add_git_remote
+ say "git fetch production"
+ app.git_fetch_remote
+ say "git checkout -b #{app} --track #{app}/master"
+ app.git_add_tracking_branch
+ else
+ say "You have to manually add remote:"
+ say "`git remote add #{app} #{app.git_url}`"
+ say "`git fetch production`"
+ say "`git checkout -b #{app} --track #{app}/master`"
+ end
+
+ say_new_line
+ rescue Client::NotFoundException => e
+ raise unless e.resource == :cloud
+ say_error "You have no access to '#{app}' cloud defined in Cloudfile"
+ end
+ end
+
+ say "Your application is set up.", :green
+ end
+
desc "stop", "Stop the cloud"
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
def stop
multiple_clouds(options[:cloud], "stop")
@app.stop
@@ -284,11 +321,11 @@
say "Redeploying your application for cloud '#{@app}'", :green
rescue Client::ConflictException => e
case e[:state]
when "deploying", "configuring"
say_error "Your application is being redeployed at the moment"
- when "no_code", "turned_off"
+ when "no_code", "no_billing", "turned_off"
say_error "Cloud #{@app} is not running", :with_exit => false
say "Start your cloud with `shelly start --cloud #{@app}`"
exit 1
else raise
end
@@ -327,9 +364,14 @@
end
def valid_databases?(databases)
kinds = Shelly::App::DATABASE_KINDS
databases.all? { |kind| kinds.include?(kind) }
+ end
+
+ def overwrite_remote?(app)
+ git_remote = app.git_remote_exist?
+ !git_remote or (git_remote and yes?("Git remote #{app} exists, overwrite (yes/no): "))
end
def ask_for_password(options = {})
options = {:with_confirmation => true}.merge(options)
loop do