branch-name 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56671e5fc00e4ad0045dad3658a70038a878d4352fb711c8aad559d5132516ff
4
- data.tar.gz: 7317863bb70d45b73df3c64ff0e6a73251e6245a920b1e99f21fa7ffa9b31a95
3
+ metadata.gz: ecf9d15cb3f6a7be37ca9d39377e9d8c103b71557ae26a01dbf19670ce3c9548
4
+ data.tar.gz: 2ee162f10d1bd5bf48cde5e2d7611241600030098b9e50331472eef08077bbad
5
5
  SHA512:
6
- metadata.gz: 9078aa3f683ff648fcfe3a4d37ac4e0f39346d13f207a82c32e2c090c1549914626d225114985ff23190203daf101226af4aa4494e8ba340ef73f600f5b98ed3
7
- data.tar.gz: cd69167ddb0f89e7e70e68d8c936ee9aa2c411445f31e46cd624cbc5ee7664247ecd0619d66d5e04fb50d3ef8a2f53e773411eecca96ab3a635b42e579be94e7
6
+ metadata.gz: d7dd261862332096d9dd74d38ade8fd517b72ea07fe867a8d2b2b6cbf367b13e296ce2f8fc35cd9bd2a697e53a51d39edc842ca9ad644a6ece15dcd4e0c0b3ac
7
+ data.tar.gz: cba46ce2945c423427d1e39930d9695841a0153fa041d61899f90b396a156162a4dcce047f1c04d1b131ce7573aa497b3f351538d8d12f6bc7820fcf2fe39b6e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## ['3.0.0'] - 2022-09-26
2
+ * Enhancements:
3
+ * Changes:
4
+ * Default default commands to :help.
5
+ * Remove references to system for options, folder locations, etc. These were not being used and the nature of this tool is that global options should suffice.
6
+ * Bug Fixes: Not really a branch-name bug, but patched Thor bug that displays nested subcommands incorrectly.
7
+
8
+ ## ['2.2.0'] - 2022-09-24
9
+ * Enhancements:
10
+ * Add support for `branch-name create` `-x` argument (see `branch-name help create`) which allows you to position the ticket and ticket description within the formulated branch name.
11
+ * The `branch-name create :project_location` option string now accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directive.
12
+ * Add better test coverage, although not what it should be (I'm working on it); this started a "quick and dirty" tool.
13
+ * `branch-name create` will now create the PROJECT_LOCATION if it does not exist.
14
+ * Update README.md file.
15
+
1
16
  ## ['2.1.0'] - 2022-09-22
2
17
  * Enhancements: Add support for Windows clipboard. Branch names created are copied to the clibboard for macOS and Windows now.
3
18
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (2.1.0)
4
+ branch-name (3.0.0)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
7
  os (~> 1.1, >= 1.1.4)
data/README.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # `branch-name`
2
2
 
3
+ [![GitHub version](http://badge.fury.io/gh/gangelo%2Fbranch-name.svg)](https://badge.fury.io/gh/gangelo%2Fbranch-name)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/branch-name.svg)](https://badge.fury.io/rb/branch-name)
6
+
7
+ [![](http://ruby-gem-downloads-badge.herokuapp.com/branch-name?type=total)](http://www.rubydoc.info/gems/branch-name/)
8
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/branch-name/)
9
+
10
+ [![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/branch-name/issues)
11
+
12
+ [![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)
13
+
3
14
  `branch-name` is a gem that provides a command-line interface that allows you to accomplish several tasks, tasks I *personally* find myself having to carry out every time I work on a feature branch. I created this gem *for myself*; however, you are free to use it yourself, if any of these tasks fits into your personal routine:
4
15
 
5
16
  1. Formulate a git *feature branch name*, given a [jira](https://www.atlassian.com/software/jira) ticket and jira ticket description. **Why? Because I am constantly having to create git feature branch names that are based on jira ticket and jira ticket descriptions.**
@@ -42,9 +53,9 @@ $ branch-name config init global
42
53
  #=> Configuration file (/Users/<username>/.branch-name) created
43
54
  ```
44
55
 
45
- This creates a `.branch-name` .yaml configuration file the home folder of the current user (`$ whoami` on *macOS*) with the following option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `brnch-name` command is *not* found in the `.branch-name` confg file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command are not currently supported.
56
+ This creates a `.branch-name` yaml configuration file the home folder of the current user (`$ whoami` on *macOS*) with the below option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `branch-name` command is *not* found in the `.branch-name` config file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command are not currently supported.
46
57
 
47
- For example, the following default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
58
+ Below is a list of _default_ options created when initializing _global_ options; consequently, these default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
48
59
 
49
60
  ```yaml
50
61
  # /Users/<username>/.branch-name
@@ -52,23 +63,27 @@ For example, the following default options will be used whenever the `branch-nam
52
63
  create:
53
64
  downcase: false
54
65
  separator: _
66
+ format_string: "%t %d"
55
67
  project: false
56
- project_location: "/Users/<username>"
68
+ project_location: "/Users/<username>/branch-name/projects/%Y/%m (%B)"
57
69
  project_files:
58
- - scratch.rb
59
70
  - readme.txt
71
+ - scratch.rb
72
+ - snippets.rb
60
73
  ```
61
74
 
62
- NOTE: It is recommended that you change the default `create: project_location` to a more suitable location depending on your *os*. For example, on *macOS* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
75
+ NOTE: You can manually change any of the options you wish. It is recommended that you change the default `create: project_location` to meet your needs, depending on your *os*. For example, on *macOS* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
76
+
77
+ The `create: project_location` option string also accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directives.
63
78
 
64
- Any or all of these options can be overwritten on the command-line:
79
+ The `create: format_string` option string can be used to position the *ticket* (`%t`) and *ticket description* (`%d`) within the branch name formulated. You can also include any other information you wish in the format string, for example: "`<username> %t %d`". However, non-word characters will be stripped (see `Branch::Name::Normalizable::NON_WORD_CHARS_REGEX` which equates to `/[\W_]/`)
65
80
 
66
- For more information:
81
+ Any or all of these options can also be overwritten on the command-line. For more information:
67
82
  `$ branch-name config help init`
68
83
 
69
84
  ### Creating Feature Branch Names and Projects Examples
70
85
 
71
- NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply formulates a suitable feature branch name given a *jira* ticket and *jira* ticket description.
86
+ NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply _formulates_ a suitable feature branch name given a *jira* ticket and *jira* ticket description.
72
87
 
73
88
  NOTE: The below examples will assume the following `global` config file defaults (`$ branch-name config init global`) that have been *manually* manipulated to have the following options:
74
89
 
@@ -79,7 +94,7 @@ create:
79
94
  downcase: false
80
95
  separator: _
81
96
  project: false
82
- project_location: "/Users/<username>/feature-branches/2022"
97
+ project_location: "/Users/<username>/feature-branches/%Y"
83
98
  project_files:
84
99
  - readme.txt
85
100
  - scratch.rb
@@ -12,6 +12,7 @@ require_relative 'locatable'
12
12
  require_relative 'normalizable'
13
13
  require_relative 'projectable'
14
14
  require_relative 'subcommands/config'
15
+ require_relative 'task_defaultable'
15
16
  require_relative 'version'
16
17
 
17
18
  module Branch
@@ -26,11 +27,11 @@ module Branch
26
27
  include Locatable
27
28
  include Normalizable
28
29
  include Projectable
30
+ include TaskDefaultable
29
31
 
30
32
  class_option :debug, type: :boolean, default: false
31
33
  class_option :verbose, type: :boolean, default: false
32
34
 
33
- default_task :create
34
35
  map %w[--version -v] => :version
35
36
 
36
37
  desc 'create [OPTIONS] DESCRIPTION [TICKET]', 'Formulate a branch name based on a ticket
@@ -43,7 +44,7 @@ module Branch
43
44
 
44
45
  SYNOPSIS
45
46
  \x5
46
- branch-name create [-l|-f|-d|-s|-p] DESCRIPTION [TICKET]
47
+ branch-name create [-l|-f|-d|-s|-p|-x] DESCRIPTION [TICKET]
47
48
 
48
49
  \x5
49
50
  The following options are available:
@@ -69,9 +70,17 @@ module Branch
69
70
  A "project" is a folder that is created in the PROJECT_LOCATION specified,
70
71
  whose name is equivalent to the branch name that is formulated.
71
72
  The default is: "#{Locatable.project_folder(options: options)}".
73
+
74
+ \x5 -x FORMAT_STRING: This is a string that determines the format of the branch name
75
+ that is formulated. The following are a list of required placeholders you must put
76
+ in your format string to format the brach name: [%t, %d].
77
+ \x5Where %t will be replaced by the ticket.
78
+ \x5Where %d will be replaced by the ticket description.
79
+ \x5The default is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
72
80
  LONG_DESC
73
81
  method_option :downcase, type: :boolean, aliases: '-d'
74
82
  method_option :separator, type: :string, aliases: '-s'
83
+ method_option :format_string, type: :string, aliases: '-x'
75
84
  method_option :project, type: :boolean, aliases: '-p'
76
85
  method_option :project_location, type: :string, aliases: '-l'
77
86
  method_option :project_files, type: :array, aliases: '-f'
@@ -84,7 +93,10 @@ module Branch
84
93
 
85
94
  init_options_for! command: :create
86
95
 
87
- branch_name = normalize_branch_name(ticket_description, ticket)
96
+ branch_name = normalize_branch_name(ticket_description, ticket) do |error|
97
+ say_error error.message
98
+ exit 1
99
+ end
88
100
 
89
101
  say "Branch name: #{branch_name}", :cyan
90
102
 
@@ -21,7 +21,6 @@ module Branch
21
21
 
22
22
  def copy_to_clipboard_macos(text)
23
23
  copy_to_clipboard_with(app: 'pbcopy', text: text)
24
-
25
24
  end
26
25
 
27
26
  def copy_to_clipboard_windows(text)
@@ -16,8 +16,9 @@ module Branch
16
16
  'create' => {
17
17
  'downcase' => false,
18
18
  'separator' => '_',
19
+ 'format_string' => '%t %d',
19
20
  'project' => false,
20
- 'project_location' => Locatable.project_folder,
21
+ 'project_location' => "#{Locatable.project_folder}/branch-name/projects/%Y/%m (%B)",
21
22
  'project_files' => %w[readme.txt scratch.rb snippets.rb]
22
23
  }
23
24
  }.freeze
@@ -33,10 +34,6 @@ module Branch
33
34
  File.join(local_folder, CONFIG_FILENAME)
34
35
  end
35
36
 
36
- def system_config_file
37
- File.join(system_folder, CONFIG_FILENAME)
38
- end
39
-
40
37
  def global_config_file?
41
38
  File.exist? global_config_file
42
39
  end
@@ -45,10 +42,6 @@ module Branch
45
42
  File.exist? local_config_file
46
43
  end
47
44
 
48
- def system_config_file?
49
- File.exist? system_config_file
50
- end
51
-
52
45
  def create_global_config_file!
53
46
  create_config_file global_config_file
54
47
  end
@@ -57,10 +50,6 @@ module Branch
57
50
  create_config_file local_config_file
58
51
  end
59
52
 
60
- def create_system_config_file!
61
- create_config_file system_config_file
62
- end
63
-
64
53
  def delete_global_config_file!
65
54
  delete_config_file global_config_file
66
55
  end
@@ -69,10 +58,6 @@ module Branch
69
58
  delete_config_file local_config_file
70
59
  end
71
60
 
72
- def delete_system_config_file!
73
- delete_config_file system_config_file
74
- end
75
-
76
61
  private
77
62
 
78
63
  def create_config_file(config_file)
@@ -12,7 +12,6 @@ module Branch
12
12
  def load_options(defaults: {})
13
13
  options = {}
14
14
 
15
- options.merge!(load_config(system_config_file))
16
15
  options.merge!(load_config(global_config_file))
17
16
  options.merge!(load_config(local_config_file))
18
17
 
@@ -19,27 +19,12 @@ module Branch
19
19
  Dir.pwd
20
20
  end
21
21
 
22
- def system_folder
23
- system_folder = Pathname.new('/')
24
- unless system_folder.exist? && system_folder.directory?
25
- puts "WARNING: system folder #{system_folder} does not exist, " \
26
- "using global folder instead (#{global_folder})".red
27
-
28
- return global_folder
29
- end
30
- system_folder.to_s
31
- end
32
-
33
22
  def project_folder(options: {})
34
23
  return home_folder if options.blank?
35
24
 
36
25
  home_folder
37
26
  end
38
27
 
39
- def system_folder_equals_global_folder?
40
- syetem_folder == global_folder
41
- end
42
-
43
28
  def temp_folder
44
29
  Dir.tmpdir
45
30
  end
@@ -1,25 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'option_error'
4
+
3
5
  module Branch
4
6
  module Name
5
7
  module Normalizable
6
8
  NON_WORD_CHARS_REGEX = /[\W_]/
7
9
 
8
10
  def normalize_branch_name(ticket_description, ticket)
9
- normalized_ticket_description = normalize_ticket_description ticket_description
10
- return normalized_ticket_description if ticket.blank?
11
+ formatted_branch_name = format_string_or_default
12
+ formatted_branch_name = formatted_branch_name.gsub('%t', ticket || '')
13
+ formatted_branch_name = formatted_branch_name.gsub('%d', ticket_description)
14
+ formatted_branch_name = normalize_token formatted_branch_name
15
+ rescue Branch::Name::OptionError => e
16
+ raise unless block_given?
11
17
 
12
- normalized_ticket = normalize_ticket ticket
13
- "#{normalized_ticket}#{options[:separator]}#{normalized_ticket_description}"
18
+ yield e
14
19
  end
15
20
 
16
21
  private
17
22
 
23
+ def format_string_or_default
24
+ format_string = options[:format_string].presence ||
25
+ Configurable::DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']
26
+ unless %w[%t %d].all? { |o| format_string.include?(o) }
27
+ raise Branch::Name::OptionError.new(
28
+ 'was called having argument [-x/--format-string] ' \
29
+ 'which did not contain %t and %d format placeholders',
30
+ current_command_chain.first
31
+ )
32
+ end
33
+
34
+ format_string
35
+ end
36
+
18
37
  def normalize_ticket_description(ticket_description)
19
38
  normalize_token ticket_description
20
39
  end
21
40
 
22
41
  def normalize_ticket(ticket)
42
+ return if ticket.blank?
43
+
23
44
  ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
24
45
  normalize_token(token)
25
46
  end.join(options[:separator])
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ class OptionError < StandardError
6
+ attr_reader :command
7
+
8
+ def initialize(msg, command)
9
+ super(msg)
10
+
11
+ @command = command
12
+ end
13
+
14
+ def message
15
+ "ERROR: \"branch-name #{command}\" #{super}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,8 @@ module Branch
11
11
  def create_project!(branch_name)
12
12
  raise 'options[:project] is false' unless options[:project]
13
13
 
14
- project_folder = "#{options[:project_location]}/#{branch_name}"
14
+ project_location = Time.new.strftime(options[:project_location])
15
+ project_folder = "#{project_location}/#{branch_name}"
15
16
 
16
17
  if Dir.exist? project_folder
17
18
  puts "Project folder \"#{project_folder}\" already exists"
@@ -19,7 +20,7 @@ module Branch
19
20
  return
20
21
  end
21
22
 
22
- Dir.mkdir project_folder
23
+ FileUtils.mkdir_p(project_folder)
23
24
  create_project_files!(project_folder)
24
25
 
25
26
  puts "Project folder \"#{project_folder}\" with project files #{options[:project_files]} was created".green
@@ -3,7 +3,9 @@
3
3
  require 'thor'
4
4
  require_relative '../configurable'
5
5
  require_relative '../exitable'
6
+ require_relative 'delete'
6
7
  require_relative 'init'
8
+ require_relative '../task_defaultable'
7
9
 
8
10
  module Branch
9
11
  module Name
@@ -11,8 +13,7 @@ module Branch
11
13
  class Config < ::Thor
12
14
  include Configurable
13
15
  include Exitable
14
-
15
- default_task :info
16
+ include TaskDefaultable
16
17
 
17
18
  desc 'info', 'Displays information about this gem configuration'
18
19
  long_desc <<-LONG_DESC
@@ -36,46 +37,13 @@ module Branch
36
37
  else
37
38
  say "Local config file does not exist at: \"#{local_folder}\"", :yellow
38
39
  end
39
-
40
- if system_config_file?
41
- say "System config file exists: \"#{system_config_file}\"", :green
42
- else
43
- say "System config file does not exist at: \"#{system_folder}\"", :yellow
44
- end
45
- end
46
-
47
- desc 'delete [OPTION]', 'Removes .branch-name file(s)'
48
- long_desc <<-LONG_DESC
49
- NAME
50
- \x5
51
- `branch-name config delete [OPTION]` -- will remove one or all .branch-name file(s)
52
- depending on the OPTION.
53
-
54
- SYNOPSIS
55
- \x5
56
- branch-name config delete [-a|-g|-l|-s]
57
- LONG_DESC
58
- method_option :all, type: :boolean, aliases: '-a'
59
- method_option :global, type: :boolean, aliases: '-g'
60
- method_option :local, type: :boolean, aliases: '-l'
61
- method_option :system, type: :boolean, aliases: '-s'
62
-
63
- def delete
64
- if options[:all]
65
- delete_global_config_file!
66
- delete_local_config_file!
67
- delete_system_config_file!
68
- elsif options[:global]
69
- delete_global_config_file!
70
- elsif options[:local]
71
- delete_local_config_file!
72
- elsif options[:system]
73
- delete_system_config_file!
74
- end
75
40
  end
76
41
 
77
42
  desc 'init SUBCOMMAND', 'Sets up config files for this gem'
78
43
  subcommand :init, Branch::Name::Subcommands::Init
44
+
45
+ desc 'delete SUBCOMMAND', 'Deletes one of all config files for this gem'
46
+ subcommand :delete, Branch::Name::Subcommands::Delete
79
47
  end
80
48
  end
81
49
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require_relative '../configurable'
5
+ require_relative '../exitable'
6
+ require_relative 'nestable'
7
+ require_relative '../task_defaultable'
8
+
9
+ module Branch
10
+ module Name
11
+ module Subcommands
12
+ class Delete < ::Thor
13
+ include Configurable
14
+ include Exitable
15
+ include Nestable
16
+ include TaskDefaultable
17
+
18
+ class << self
19
+ def ascestor_name
20
+ 'config delete'
21
+ end
22
+ end
23
+
24
+ desc 'all', 'Deletes all config files (local and global) for this gem'
25
+ subcommand_help_override "#{ascestor_name} all"
26
+ long_desc <<-LONG_DESC
27
+ NAME
28
+ \x5
29
+ `branch-name config delete all` -- will remove the all .branch-name config files.
30
+
31
+ SYNOPSIS
32
+ \x5
33
+ branch-name config delete all
34
+ LONG_DESC
35
+ method_option :all, type: :boolean, aliases: '-a'
36
+
37
+ def all
38
+ delete_global_config_file!
39
+ delete_local_config_file!
40
+ end
41
+
42
+ desc 'global', 'Deletes the global config file for this gem'
43
+ subcommand_help_override "#{ascestor_name} global"
44
+ long_desc <<-LONG_DESC
45
+ NAME
46
+ \x5
47
+ `branch-name config delete global` -- will remove the global .branch-name config file.
48
+
49
+ SYNOPSIS
50
+ \x5
51
+ branch-name config delete global
52
+ LONG_DESC
53
+ method_option :global, type: :boolean, aliases: '-g'
54
+
55
+ def global
56
+ delete_global_config_file!
57
+ end
58
+
59
+ desc 'local', 'Deletes the local config file for this gem'
60
+ subcommand_help_override "#{ascestor_name} local"
61
+ long_desc <<-LONG_DESC
62
+ NAME
63
+ \x5
64
+ `branch-name config delete local` -- will remove the local .branch-name config file.
65
+
66
+ SYNOPSIS
67
+ \x5
68
+ branch-name config delete local
69
+ LONG_DESC
70
+ method_option :local, type: :boolean, aliases: '-l'
71
+
72
+ def local
73
+ delete_local_config_file!
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ module Subcommands
6
+ # This module helps fix a bug in Thor that prohibits help for nested
7
+ # subcommands from displaying help properly. Nested subcommands fail
8
+ # to display their subcommand ancestor command name. This fixes that
9
+ # bug. This module is used in conjunction with the Nestable module.
10
+ module HelpNestable
11
+ class << self
12
+ def included(base)
13
+ # Thor override
14
+ base.desc 'help [COMMAND]', 'Describe available commands or one specific command'
15
+ base.subcommand_help_override "config init help [SUBCOMMAND]"
16
+ def help(command = nil, subcommand = false)
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,63 +3,55 @@
3
3
  require 'thor'
4
4
  require_relative '../configurable'
5
5
  require_relative '../exitable'
6
+ require_relative 'nestable'
7
+ require_relative '../task_defaultable'
6
8
 
7
9
  module Branch
8
10
  module Name
9
11
  module Subcommands
10
- # https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-config
11
12
  class Init < ::Thor
12
13
  include Configurable
13
14
  include Exitable
15
+ include Nestable
16
+ include TaskDefaultable
14
17
 
15
- default_task :global
18
+ class << self
19
+ def ascestor_name
20
+ 'config init'
21
+ end
22
+ end
16
23
 
17
24
  desc 'global', 'Creates and initializes a .branch-name file in the global folder'
25
+ subcommand_help_override "#{ascestor_name} global"
18
26
  long_desc <<-LONG_DESC
19
27
  NAME
20
28
  \x5
21
- `branch-name init global` -- will create and initialize a .branch-name file
29
+ `branch-name config init global` -- will create and initialize a .branch-name file
22
30
  in the "#{Locatable.global_folder}" folder.
23
31
 
24
32
  SYNOPSIS
25
33
  \x5
26
- branch-name init global
34
+ branch-name config init global
27
35
  LONG_DESC
28
36
  def global
29
37
  create_global_config_file!
30
38
  end
31
39
 
32
40
  desc 'local', 'Creates and initializes a .branch-name file in the local folder'
41
+ subcommand_help_override "#{ascestor_name} local"
33
42
  long_desc <<-LONG_DESC
34
43
  NAME
35
44
  \x5
36
- `branch-name init local` -- will create and initialize a .branch-name file
45
+ `branch-name config init local` -- will create and initialize a .branch-name file
37
46
  in the "#{Locatable.local_folder}" folder.
38
47
 
39
48
  SYNOPSIS
40
49
  \x5
41
- branch-name init local
50
+ branch-name config init local
42
51
  LONG_DESC
43
52
  def local
44
53
  create_local_config_file!
45
54
  end
46
-
47
- desc 'system', 'Creates and initializes a .branch-name file in the system folder'
48
- long_desc <<-LONG_DESC
49
- NAME
50
- \x5
51
- `branch-name init system` -- will create and initialize a .branch-name file
52
- in the "#{Locatable.system_folder}" folder.
53
-
54
- SYNOPSIS
55
- \x5
56
- branch-name init system
57
- LONG_DESC
58
- def system
59
- # create_system_config_file!
60
- say_error 'System initialization is not available at this time', :red
61
- exit 1
62
- end
63
55
  end
64
56
  end
65
57
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'help_nestable'
4
+
5
+ module Branch
6
+ module Name
7
+ module Subcommands
8
+ # This module fixes a bug in Thor that prohibits help for nested
9
+ # subcommands from displaying help properly. Nested subcommands fail
10
+ # to display their subcommand ancestor command name. This fixes that
11
+ # bug.
12
+ module Nestable
13
+ class << self
14
+ def included(base)
15
+ base.extend ClassMethods
16
+ base.include HelpNestable
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def ascestor_name
22
+ raise NotImplementedError
23
+ end
24
+
25
+ # Thor override
26
+ def banner(command, _namespace = nil, subcommand = false)
27
+ command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |_formatted_usage|
28
+ command_name = command.name.to_sym
29
+ "#{basename} #{@subcommand_help_override[command.usage]}"
30
+ end.join("\n")
31
+ end
32
+
33
+ def subcommand_help_override(help_string)
34
+ raise "Thor.desc must be called for \"#{help_string}\" " \
35
+ 'prior to calling .subcommand_help_override' if @usage.blank?
36
+
37
+ @subcommand_help_override = {} unless defined? @subcommand_help_override
38
+ @subcommand_help_override[@usage] = help_string
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ # Forces the default Thor task to be :help
6
+ module TaskDefaultable
7
+ class << self
8
+ def included(base)
9
+ base.default_command :help
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '2.1.0'
6
+ VERSION = '3.0.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch-name
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -115,9 +115,14 @@ files:
115
115
  - lib/branch/name/loadable.rb
116
116
  - lib/branch/name/locatable.rb
117
117
  - lib/branch/name/normalizable.rb
118
+ - lib/branch/name/option_error.rb
118
119
  - lib/branch/name/projectable.rb
119
120
  - lib/branch/name/subcommands/config.rb
121
+ - lib/branch/name/subcommands/delete.rb
122
+ - lib/branch/name/subcommands/help_nestable.rb
120
123
  - lib/branch/name/subcommands/init.rb
124
+ - lib/branch/name/subcommands/nestable.rb
125
+ - lib/branch/name/task_defaultable.rb
121
126
  - lib/branch/name/version.rb
122
127
  - sig/branch/name.rbs
123
128
  homepage: https://github.com/gangelo/branch-name