lib/uffizzi/cli/project.rb in uffizzi-cli-0.6.0 vs lib/uffizzi/cli/project.rb in uffizzi-cli-0.7.2

- old
+ new

@@ -3,35 +3,44 @@ require 'uffizzi' require 'uffizzi/auth_helper' require 'uffizzi/response_helper' module Uffizzi - class CLI::Project < Thor + class Cli::Project < Thor include ApiClient - desc 'compose', 'compose' + desc 'compose', 'Manage the compose file for a project' method_option :file, required: false, aliases: '-f' require_relative 'project/compose' - subcommand 'compose', Uffizzi::CLI::Project::Compose + subcommand 'compose', Uffizzi::Cli::Project::Compose - desc 'secret', 'Secrets Actions' + desc 'secret', 'Manage secrets for a project' require_relative 'project/secret' - subcommand 'secret', Uffizzi::CLI::Project::Secret + subcommand 'secret', Uffizzi::Cli::Project::Secret - desc 'list', 'list' + desc 'list', 'List all projects in the account' def list run('list') end + desc 'set-default PROJECT_SLUG', 'set-default' + def set_default(project_slug) + run('set-default', project_slug: project_slug) + end + + map('set-default' => :set_default) + private - def run(command) + def run(command, project_slug: nil) return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? case command when 'list' handle_list_command + when 'set-default' + handle_set_default_command(project_slug) end end def handle_list_command server = ConfigFile.read_option(:server) @@ -48,9 +57,24 @@ projects = response[:body][:projects] return Uffizzi.ui.say('No projects related to this email') 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) + + if ResponseHelper.ok?(response) + handle_succeed_set_default_response(response) + else + ResponseHelper.handle_failed_response(response) + end + end + + def handle_succeed_set_default_response(response) + set_default_project(response[:body][:project]) + Uffizzi.ui.say('Default project has been updated.') end def print_projects(projects) projects_list = projects.reduce('') do |acc, project| "#{acc}#{project[:slug]}\n"