diff --git a/lib/dsu/subcommands/project.rb b/lib/dsu/subcommands/project.rb index 698cf7d3..350668c9 100644 --- a/lib/dsu/subcommands/project.rb +++ b/lib/dsu/subcommands/project.rb @@ -22,12 +22,15 @@ class Project < BaseSubcommand desc I18n.t('subcommands.project.create.desc'), I18n.t('subcommands.project.create.usage') long_desc I18n.t('subcommands.project.create.long_desc') - option :project_name, type: :string, required: true, aliases: '-n', banner: 'PROJECT_NAME' option :description, type: :string, required: false, aliases: '-d', banner: 'DESCRIPTION' option :prompts, type: :hash, default: {}, hide: true, aliases: '-p' - def create - project_name = options[:project_name] - description = options[:description] + def create(project_name = nil) + description = options[:description].to_s.strip + project_name = project_name.to_s.strip + if project_name.blank? + return Views::Shared::Error.new(messages: I18n.t('subcommands.project.create.messages.project_name_blank')).render + end + presenter = Presenters::Project::CreatePresenter.new(project_name: project_name, description: description, options: options) Views::Project::Create.new(presenter: presenter, options: options).render diff --git a/lib/dsu/views/project/list.rb b/lib/dsu/views/project/list.rb index 34cc3281..a9987655 100644 --- a/lib/dsu/views/project/list.rb +++ b/lib/dsu/views/project/list.rb @@ -7,9 +7,17 @@ module Views module Project # TODO: I18n. class List < Views::BaseListView - DETAIL_HEADER_STRING = "#{'No.'.ljust(4)} " \ - "#{'Project'.ljust(15)} " \ - "#{'Description'.ljust(10)}".freeze + NO_JUSTIFICATION = 4 + PROJECT_JUSTIFICATION = 15 + DEFAULT_JUSTIFICATION = 10 + CURRENT_JUSTIFICATION = 10 + DESCRIPTION_JUSTIFICATION = 10 + + DETAIL_HEADER_STRING = "#{'No.'.ljust(NO_JUSTIFICATION)} " \ + "#{'Project'.ljust(PROJECT_JUSTIFICATION)} " \ + "#{'Default'.center(DEFAULT_JUSTIFICATION)} " \ + "#{'Current'.center(CURRENT_JUSTIFICATION)} " \ + "#{'Description'.ljust(DESCRIPTION_JUSTIFICATION)}".freeze def render super do @@ -39,6 +47,8 @@ def display_detail display_detail_data( formatted_index(index: index), project.project_name, + project.default_project?, + project.current_project?, project.description ) end @@ -48,12 +58,23 @@ def display_detail_header puts apply_theme(DETAIL_HEADER_STRING, theme_color: color_theme.index) end - def display_detail_data(index, project_name, project_desc) + def display_detail_data(index, project_name, default_project, current_project, project_desc) puts "#{index_detail_data(index)} " \ "#{project_name_detail_data(project_name)} " \ + "#{project_default_detail_data(default_project)} " \ + "#{project_current_detail_data(current_project)} " \ "#{project_desc_detail_data(project_desc)}" end + # def display_detail_data(index, project_name, default_project, current_project, project_desc) + # puts "#{index_detail_data(index)}|" \ + # "#{project_name_detail_data(project_name)}|" \ + # "#{project_default_detail_data(default_project)}|" \ + # "#{project_current_detail_data(current_project)}|" \ + # "#{project_desc_detail_data(project_desc)}" + # end + + def display_footer footer = "\nTotal projects: #{presenter.projects.count}" puts apply_theme(footer, theme_color: color_theme.footer) @@ -65,15 +86,25 @@ def display_header end def index_detail_data(value) - apply_theme(value.to_s.ljust(4), theme_color: color_theme.index) + apply_theme(value.to_s.ljust(NO_JUSTIFICATION), theme_color: color_theme.index) end def project_name_detail_data(value) - apply_theme(value.to_s.ljust(15), theme_color: color_theme.body.bold!) + apply_theme(value.to_s.ljust(PROJECT_JUSTIFICATION), theme_color: color_theme.body.bold!) + end + + def project_default_detail_data(value) + value = value ? '*' : ' ' + apply_theme(value.to_s.center(DEFAULT_JUSTIFICATION), theme_color: color_theme.body.bold!) + end + + def project_current_detail_data(value) + value = value ? '*' : ' ' + apply_theme(value.to_s.center(CURRENT_JUSTIFICATION), theme_color: color_theme.body.bold!) end def project_desc_detail_data(value) - apply_theme(value.to_s.ljust(10), theme_color: color_theme.body) + apply_theme(value.to_s.ljust(DESCRIPTION_JUSTIFICATION), theme_color: color_theme.body) end def theme_name diff --git a/lib/locales/en/subcommands.yml b/lib/locales/en/subcommands.yml index 9f6e5894..0b5772b1 100644 --- a/lib/locales/en/subcommands.yml +++ b/lib/locales/en/subcommands.yml @@ -474,29 +474,32 @@ en: $ dsu list y project: create: - desc: create|c OPTIONS - usage: Creates a DSU project using the given OPTIONS + desc: create|c PROJECT_NAME [OPTIONS] + usage: Creates a DSU project using the given PROJECT_NAME and OPTIONS long_desc: | - Creates a DSU project using the given OPTIONS. + Creates a DSU project using the given PROJECT_NAME and OPTIONS. - dsu project create OPTIONS + dsu project create PROJECT_NAME [OPTIONS] - dsu p c OPTIONS + dsu p c PROJECT_NAME [OPTIONS] - OPTIONS: + PROJECT_NAME: + + The name of the project to create. PROJECT_NAME must be between 2 and 12 characters (inclusive) in length. - -n|--name PROJECT_NAME: The name of the project to create. PROJECT_NAME must be between 2 and 12 characters (inclusive) in length. + OPTIONS: -d|--description DESCRIPTION: Optional. The description of the project. DESCRIPTION must be between 2 and 256 characters (inclusive) in length. If DESCRIPTION is not provided, the project description will be " project" where = the name of the project. EXAMPLES: - $ dsu project create -n "My project" -d "My project description" + $ dsu project create "My project" --description "My project description" - $ dsu p c -n "My project" + $ dsu p c "My project" -d "My project description" messages: created: Created project "%{project_name}". already_exists: Project "%{project_name}" already exists. + project_name_blank: No value provided for project name. prompts: create_confirm: Create project "%{project_name}"? create_options: @@ -507,24 +510,44 @@ en: - y - n delete: - desc: delete|d OPTIONS - usage: Permanently deletes the DSU project indicated by the given OPTIONS + desc: delete|d [PROJECT_NAME | PROJECT_NUMBER] + usage: Permanently deletes the DSU project indicated by the optional PROJECT_NAME or PROJECT_NUMBER long_desc: | - Permanently deletes the DSU project indicated by the given OPTIONS. + Permanently deletes the DSU project indicated by given option PROJECT_NAME or PROJECT_NUMBER. - dsu project delete OPTIONS + dsu project delete [PROJECT_NAME | PROJECT_NUMBER] - dsu p d OPTIONS + dsu p d [PROJECT_NAME | PROJECT_NUMBER] - OPTIONS: + PROJECT_NAME: - -n|--name PROJECT_NAME: The name of the project to delete. + The name of the project to delete. + + PROJECT_NUMBER: + + The number of the project to delete. If PROJECT_NUMBER is used, the project equating to the nth project in the list of projects will be used (see `dsu project list`). + + NOTES + + PROJECT_NAME and PROJECT_NUMBER are optional. If neither are provided, the current, default project will be used. EXAMPLES: - $ dsu project delete -n "My project" + $ dsu project delete "My project" + + $ dsu p d "My project" + + # The below examples delete the project equating to the nth project in the list of projects (see `dsu project list`). + + $ dsu project delete 2 + + $ dsu p d 2 + + # The below examples delete the current, default project. + + $ dsu project delete - $ dsu p d -n "My project" + $ dsu p d messages: deleted: Deleted project "%{project_name}". prompts: