lib/uffizzi/cli/project.rb in uffizzi-cli-1.0.5 vs lib/uffizzi/cli/project.rb in uffizzi-cli-2.0.27

- old
+ new

@@ -2,10 +2,11 @@ require 'uffizzi' require 'uffizzi/auth_helper' require 'uffizzi/response_helper' require 'uffizzi/helpers/project_helper' +require 'uffizzi/helpers/config_helper' require 'uffizzi/services/project_service' module Uffizzi class Cli::Project < Thor include ApiClient @@ -34,10 +35,11 @@ def describe(project_slug) run('describe', project_slug: project_slug) end map('set-default' => :set_default) + map('set' => :set_default) method_option :name, required: true method_option :slug, default: '' method_option :description, required: false desc 'create', 'Create a project' @@ -68,11 +70,11 @@ handle_describe_command(project_slug) end end def handle_describe_command(project_slug) - response = describe_project(ConfigFile.read_option(:server), project_slug) + response = fetch_project(ConfigFile.read_option(:server), project_slug) if ResponseHelper.ok?(response) handle_succeed_describe_response(response) else ResponseHelper.handle_failed_response(response) @@ -85,11 +87,12 @@ ProjectService.describe_project(project, options[:output]) end def handle_list_command server = ConfigFile.read_option(:server) - response = fetch_projects(server) + account_id = ConfigFile.read_option(:account, :id) + response = fetch_account_projects(server, account_id) if ResponseHelper.ok?(response) handle_list_success_response(response) else ResponseHelper.handle_failed_response(response) @@ -100,11 +103,12 @@ name = options[:name] slug = options[:slug].empty? ? Uffizzi::ProjectHelper.generate_slug(name) : options[:slug] raise Uffizzi::Error.new('Slug must not content spaces or special characters') unless slug.match?(/^[a-zA-Z0-9\-_]+\Z/i) server = ConfigFile.read_option(:server) - account_id = ConfigFile.read_option(:account_id) + account_id = ConfigFile.read_option(:account, :id) + params = { name: name, description: options[:description], slug: slug, } @@ -128,18 +132,18 @@ end end def handle_list_success_response(response) projects = response[:body][:projects] - return Uffizzi.ui.say('No projects related to this email') if projects.empty? + return Uffizzi.ui.say('No projects found') if projects.empty? set_default_project(projects.first) if projects.size == 1 print_projects(projects) end def handle_set_default_command(project_slug) - response = describe_project(ConfigFile.read_option(:server), project_slug) + response = fetch_project(ConfigFile.read_option(:server), project_slug) if ResponseHelper.ok?(response) handle_succeed_set_default_response(response) else ResponseHelper.handle_failed_response(response) @@ -150,13 +154,13 @@ set_default_project(response[:body][:project]) Uffizzi.ui.say('Default project has been updated.') end def handle_create_success_response(response) - project_name = response[:body][:project][:name] - - Uffizzi.ui.say("Project #{project_name} was successfully created") + project = response[:body][:project] + ConfigFile.write_option(:project, project[:slug]) + Uffizzi.ui.say("Project '#{project[:name]}' with slug '#{project[:slug]}' was successfully created") end def print_projects(projects) projects_list = projects.reduce('') do |acc, project| "#{acc}#{project[:slug]}\n" @@ -164,9 +168,13 @@ Uffizzi.ui.say(projects_list) end def set_default_project(project) ConfigFile.write_option(:project, project[:slug]) - ConfigFile.write_option(:account_id, project[:account_id]) + account = project[:account] + return ConfigFile.write_option(:account, Uffizzi::ConfigHelper.account_config(account[:id], account[:name])) if account + + # For core versions < core_v2.2.3 + ConfigFile.write_option(:account, Uffizzi::ConfigHelper.account_config(project[:account_id])) end end end