lib/shelly/cli/config.rb in shelly-0.0.43 vs lib/shelly/cli/config.rb in shelly-0.0.44.pre

- old
+ new

@@ -31,110 +31,97 @@ print_configs(shelly_configs) end else say "Cloud #{cloud} has no configuration files" end - rescue Client::APIError => e - if e.resource_not_found == :cloud - say_error "You have no access to '#{@app}' cloud defined in Cloudfile" - else - raise e - end + rescue Client::NotFoundException => e + raise unless e.resource == :cloud + say_error "You have no access to '#{@app}' cloud defined in Cloudfile" end end end - method_option :cloud, :type => :string, :aliases => "-c", - :desc => "Specify which cloud to show configuration file for" + method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" desc "show PATH", "View configuration file" def show(path = nil) say_error "No configuration file specified" unless path - multiple_clouds(options[:cloud], "show #{path}", "Specify cloud using:") + multiple_clouds(options[:cloud], "show #{path}") config = @app.config(path) say "Content of #{config["path"]}:", :green say config["content"] - rescue Client::APIError => e - case e.resource_not_found + rescue Client::NotFoundException => e + case e.resource when :cloud say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile" when :config say_error "Config '#{path}' not found", :with_exit => false say_error "You can list available config files with `shelly config list --cloud #{@app}`" - else; raise e + else raise end end map "new" => :create - method_option :cloud, :type => :string, :aliases => "-c", - :desc => "Specify which cloud to create configuration file for" + method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" desc "create PATH", "Create configuration file" def create(path = nil) say_error "No path specified" unless path output = open_editor(path) - multiple_clouds(options[:cloud], "create #{path}", "Specify cloud using:") + multiple_clouds(options[:cloud], "create #{path}") @app.create_config(path, output) say "File '#{path}' created, it will be used after next code deploy", :green - rescue Client::APIError => e - if e.resource_not_found == :cloud - say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile" - elsif e.validation? - e.each_error { |error| say_error error, :with_exit => false } - exit 1 - else - say_error e.message - end + rescue Client::NotFoundException => e + raise unless e.resource == :cloud + say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile" + rescue Client::ValidationException => e + e.each_error { |error| say_error error, :with_exit => false } + exit 1 end map "update" => :edit - method_option :cloud, :type => :string, :aliases => "-c", - :desc => "Specify which cloud to edit configuration file for" + method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" desc "edit PATH", "Edit configuration file" def edit(path = nil) say_error "No configuration file specified" unless path - multiple_clouds(options[:cloud], "edit #{path}", "Specify cloud using:") + multiple_clouds(options[:cloud], "edit #{path}") config = @app.config(path) content = open_editor(config["path"], config["content"]) @app.update_config(path, content) say "File '#{config["path"]}' updated, it will be used after next code deploy", :green - rescue Client::APIError => e - if e.resource_not_found == :cloud + rescue Client::NotFoundException => e + case e.resource + when :cloud say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile" - elsif e.resource_not_found == :config + when :config say_error "Config '#{path}' not found", :with_exit => false say_error "You can list available config files with `shelly config list --cloud #{@app}`" - elsif e.validation? - e.each_error { |error| say_error error, :with_exit => false } - exit 1 - else - say_error e.message + else raise end + rescue Client::ValidationException => e + e.each_error { |error| say_error error, :with_exit => false } + exit 1 end - method_option :cloud, :type => :string, :aliases => "-c", - :desc => "Specify for which cloud to delete configuration file for" + method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" desc "delete PATH", "Delete configuration file" def delete(path = nil) say_error "No configuration file specified" unless path - multiple_clouds(options[:cloud], "delete #{path}", "Specify cloud using:") + multiple_clouds(options[:cloud], "delete #{path}") answer = yes?("Are you sure you want to delete 'path' (yes/no): ") if answer @app.delete_config(path) say "File deleted, redeploy your cloud to make changes", :green else say "File not deleted" end - rescue Client::APIError => e - if e.resource_not_found == :cloud + rescue Client::NotFoundException => e + case e.resource + when :cloud say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile" - elsif e.resource_not_found == :config + when :config say_error "Config '#{path}' not found", :with_exit => false say_error "You can list available config files with `shelly config list --cloud #{@app}`" - elsif e.validation? - e.each_error { |error| say_error error, :with_exit => false } - exit 1 - else - say_error e.message + else raise end end no_tasks do def print_configs(configs) @@ -164,6 +151,6 @@ end end end end -end \ No newline at end of file +end