Class: Branch::Name::CLI

Inherits:
Thor
  • Object
show all
Includes:
Clipable, Exitable, Loadable, Locatable, Projectable, TaskDefaultable
Defined in:
lib/branch/name/cli.rb

Overview

The ‘branch-name` command.

Constant Summary

Constants included from Normalizable

Normalizable::BRANCH_NAME_REGEX, Normalizable::DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR, Normalizable::PROJECT_FOLDER_REGEX, Normalizable::PROJECT_FOLDER_TOKEN_SEPARATORS

Constants included from Configurable

Branch::Name::Configurable::CONFIG_FILENAME, Branch::Name::Configurable::DEFAULT_BRANCH_NAME_OPTIONS

Constants included from Colorizable

Branch::Name::Colorizable::ABORTED, Branch::Name::Colorizable::ERROR, Branch::Name::Colorizable::SUCCESS, Branch::Name::Colorizable::WARNING

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TaskDefaultable

included

Methods included from Projectable

#create_project!, #create_project_files!, #project_folder_for

Methods included from Normalizable

#normalize_branch_name, #project_folder_name_from

Methods included from Locatable

global_folder?, home_folder, local_folder, project_folder, temp_folder

Methods included from Loadable

#load_config, #load_options

Methods included from Configurable

#create_config_file, #create_global_config_file!, #create_local_config_file!, #delete_global_config_file!, #delete_local_config_file!, #global_config_file, #global_config_file?, #local_config_file, #local_config_file?, #print_global_config_file, #print_local_config_file

Methods included from Exitable

#included

Methods included from Clipable

copy_to_clipboard, copy_to_clipboard_macos, copy_to_clipboard_windows, copy_to_clipboard_with

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/branch/name/cli.rb', line 33

def exit_on_failure?
  true
end

Instance Method Details

#create(ticket_description, ticket = nil) ⇒ Object

rubocop:disable Metrics/MethodLength



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/branch/name/cli.rb', line 101

def create(ticket_description, ticket = nil) # rubocop:disable Metrics/MethodLength
  original_options, altered_options = init_options_for! command: :create
  self.options = altered_options
  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
  end
  interactive_default = options['interactive']
  options[:interactive] = interactive_default if original_options[:interactive].nil?

  if options[:project]
    project_folder_name = validate_and_create_project_folder_name_from! branch_name
    if options[:interactive]
      project_folder = project_folder_for branch_name
      unless yes? "Create project for branch \"#{branch_name}\" " \
                  "in folder \"#{project_folder}\" (y/n)?", :cyan
        say 'Aborted.', ABORTED
        return
      end
    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

#versionObject



137
138
139
# File 'lib/branch/name/cli.rb', line 137

def version
  say Branch::Name::VERSION
end