lib/branch/name/cli.rb in branch-name-3.10.4 vs lib/branch/name/cli.rb in branch-name-3.10.5

- old
+ new

@@ -9,10 +9,11 @@ require_relative 'exitable' require_relative 'loadable' require_relative 'locatable' require_relative 'normalizable' require_relative 'projectable' +require_relative 'services/branch_name_service' require_relative 'subcommands/config' require_relative 'task_defaultable' require_relative 'version' module Branch @@ -23,14 +24,19 @@ class CLI < ::Thor include Clipable include Exitable include Loadable include Locatable - include Normalizable include Projectable include TaskDefaultable + class << self + def exit_on_failure? + true + end + end + class_option :debug, type: :boolean, default: false class_option :verbose, type: :boolean, default: false map %w[--version -v] => :version @@ -91,15 +97,13 @@ method_option :project_location, type: :string, aliases: '-l' method_option :project_files, type: :array, aliases: '-f' method_option :interactive, type: :boolean, optional: true, aliases: '-i' def create(ticket_description, ticket = nil) - validate_ticket_description! ticket_description original_options, altered_options = init_options_for! command: :create self.options = altered_options - - branch_name = validate_and_normalize_branch_name(ticket_description, ticket) + branch_name = BranchNameService.new(description: ticket_description, ticket: ticket, options: options).call say "Branch name: \"#{branch_name}\"", :cyan say "Branch name \"#{branch_name}\" has been copied to the clipboard!", SUCCESS if copy_to_clipboard branch_name if original_options[:interactive] && !options[:project] say 'Ignored: -i is only used with projects (-p).', WARNING @@ -119,10 +123,13 @@ end say "Project folder name: \"#{project_folder_name}\"", :cyan create_project!(project_folder_name) end + rescue ArgumentError => e + say_error e.message, ERROR + exit 1 end desc 'config SUBCOMMAND', 'Manages config files for this gem' subcommand :config, Branch::Name::Subcommands::Config @@ -130,23 +137,9 @@ def version say Branch::Name::VERSION end private - - def validate_ticket_description!(ticket_description) - return unless ticket_description.blank? - - say_error 'description is required', ERROR - exit 1 - end - - def validate_and_normalize_branch_name(ticket_description, ticket) - normalize_branch_name(ticket_description, ticket) do |error| - say_error error.message - exit 1 - end - end def validate_and_create_project_folder_name_from!(branch_name) project_folder_name_from(branch_name) do |error| say_error error.message exit 1