branch-name 0.1.0.pre.alpha → 1.0.0.pre.beta

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: d882d8879ddec14bdc35c55ef3dbe8248f8015354fc2f80e9facd910340422b5
4
- data.tar.gz: f55756f320579898d41e13a9f27200886a4ed2715eabdf5aa80929ff79637d33
3
+ metadata.gz: b7dad0772990843cd87dc265aa42d9ddd8fc91c0c50db1c8d0e7d48be3ca7129
4
+ data.tar.gz: 6b64ae358a4105d1495f10a5d5d4e24997ee0c45fbdb9e10135e295d3ff686ae
5
5
  SHA512:
6
- metadata.gz: d3e87289c12232e36def910161ed1fe58f6129bf780a18bc4a6e65210fc1169f8f448aef6217b67fa51ab1e30fafb19c02721d6d17528d63f2b470a401e6a352
7
- data.tar.gz: fb33ef5ca18c7c55ceb31d5f7bf32c1159093c590d715b35763eb4331cd3de7fa4a4bea1c88476810dd9bc7eac32ff2d8c96fc8f869f37a33cb054c73f4a6203
6
+ metadata.gz: b90aa2baa2030cd11a7ded0189f3efc273d923e42dad82f6150b670570cf95375930948fb05aaa5a7348429e32a53f2de8a91fbc5f9dfdabf5315851c7078db4
7
+ data.tar.gz: ca83be22b65d2174bfb88ab3cf971306008179856557f4c39870cd427b0cbcfcda921646cb78cd51110b8b0b3eee8e97d54868f61567848fe52cb8d964962668
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (0.1.0.pre.alpha)
4
+ branch-name (1.0.0.pre.beta)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
7
  thor (~> 1.2, >= 1.2.1)
data/branch-name.gemspec CHANGED
@@ -37,5 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'thor', '~> 1.2', '>= 1.2.1'
38
38
 
39
39
  # Remove this for now.
40
- # spec.metadata['rubygems_mfa_required'] = 'true'
40
+ spec.metadata['rubygems_mfa_required'] = 'true'
41
41
  end
@@ -3,13 +3,15 @@
3
3
  require 'active_support'
4
4
  require 'active_support/core_ext/object/blank'
5
5
  require 'bundler'
6
- require 'colorize'
7
6
  require 'thor'
7
+ require_relative 'clipable'
8
8
  require_relative 'configurable'
9
9
  require_relative 'exitable'
10
+ require_relative 'loadable'
10
11
  require_relative 'locatable'
12
+ require_relative 'nameable'
13
+ require_relative 'projectable'
11
14
  require_relative 'subcommands/config'
12
- require_relative 'subcommands/init'
13
15
  require_relative 'version'
14
16
 
15
17
  module Branch
@@ -18,8 +20,15 @@ module Branch
18
20
  # The `branch-name` command.
19
21
  #
20
22
  class CLI < ::Thor
21
- include Locatable
23
+ include Clipable
22
24
  include Exitable
25
+ include Loadable
26
+ include Locatable
27
+ include Nameable
28
+ include Projectable
29
+
30
+ class_option :debug, type: :boolean, default: false
31
+ class_option :verbose, type: :boolean, default: false
23
32
 
24
33
  default_task :create
25
34
  map %w[--version -v] => :version
@@ -32,7 +41,7 @@ module Branch
32
41
 
33
42
  SYNOPSIS
34
43
  \x5
35
- branch-name create [-dsp] TICKET [DESCRIPTION]
44
+ branch-name create [-d|-s|-p|-pL|-pF] TICKET [DESCRIPTION]
36
45
 
37
46
  \x5
38
47
  The following options are available:
@@ -40,54 +49,64 @@ module Branch
40
49
  \x5 -d: Forces the branch name to lower case.
41
50
  The default is --no-downcase
42
51
 
43
- \x5\x5 -s DELIMITER: Indicates the DELIMITER that will be used to delimit tokens in the branch name.
44
- The default DELIMITER is the '_' (underscore) character.
52
+ \x5\x5 -s SEPARATOR: Indicates the SEPARATOR that will be used to delimit tokens in the branch name.
53
+ The default SEPARATOR is: '#{DEFAULT_BRANCH_NAME_OPTIONS['create']['separator']}'.
54
+
55
+ \x5\x5 -p: Indicates that a project should be created.
56
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project']}.
45
57
 
46
- \x5\x5 -p LOCATION: Indicates that a project should be created.
47
- A "project" is a folder that is created in the LOCATION specified
48
- whose name is equivalent to the branch name that is formulated.
49
- The default LOCATION is #{Locatable.project_folder(options: options)}.
58
+ \x5 -pF: Used with the -p option. If -pF is specified, project files
59
+ will be created in the PROJECT_LOCATION specified by the -pL option.
60
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project_files']}.
50
61
 
51
- \x5 -f: Used with the -p option. If -f is specified, scratch.rb and readme.txt files
52
- will be created in the project folder created.
53
- The default is --project-files
62
+ \x5\x5 -pL PROJECT_LOCATION: Indicates where the project should be created.
63
+ A "project" is a folder that is created in the PROJECT_LOCATION specified,
64
+ whose name is equivalent to the branch name that is formulated.
65
+ The default is: "#{Locatable.project_folder(options: options)}".
54
66
  LONG_DESC
55
67
  method_option :downcase, type: :boolean, aliases: '-d'
56
- method_option :separator, type: :string, aliases: '-s', default: '_'
57
- method_option :project, type: :string, aliases: '-p', default: "#{Locatable.project_folder(options: options)}"
58
- method_option :project_files, type: :boolean, aliases: '-f', default: true
68
+ method_option :separator, type: :string, aliases: '-s'
69
+ method_option :project, type: :boolean, aliases: '-p'
70
+ method_option :project_location, type: :string, aliases: '-pL'
71
+ method_option :project_files, type: :array, aliases: '-pF'
59
72
 
60
73
  def create(ticket, ticket_description = nil)
61
- if ticket.blank? && ticket_description.blank?
62
- say_error 'ticket and/or ticket_description is required', :red
74
+ if ticket.blank?
75
+ say_error 'ticket is required', :red
63
76
  exit 1
64
77
  end
65
78
 
66
- branch_name = "#{ticket} #{ticket_description}".strip
67
- branch_name = branch_name.split.join options[:separator]
68
- branch_name = branch_name.downcase if options[:downcase]
69
- branch_name = branch_name.tr('_', '-') if options[:separator] == '-'
70
- branch_name = branch_name.tr('-', '_') if options[:separator] == '_'
71
- branch_name = branch_name.squeeze('-') if options[:separator] == '-'
72
- branch_name = branch_name.squeeze('_') if options[:separator] == '_'
79
+ init_options_for! command: :create
80
+
81
+ branch_name = "#{ticket} #{ticket_description}"
82
+ branch_name = normalize_branch_name branch_name
73
83
 
74
84
  say "Branch name: #{branch_name}", :cyan
75
85
 
76
- if /darwin/ =~ RUBY_PLATFORM
77
- IO.popen('pbcopy', 'w') { |pipe| pipe.puts branch_name }
78
- say "\"#{branch_name}\" has been copied to the clipboard!", :green
79
- end
80
- end
86
+ say "\"#{branch_name}\" has been copied to the clipboard!", :green if copy_to_clipboard branch_name
81
87
 
82
- desc 'init SUBCOMMAND', 'Sets up config files for this gem'
83
- subcommand :init, Branch::Name::Subcommands::Init
88
+ create_project!(branch_name) if options[:project]
89
+ end
84
90
 
85
91
  desc 'config SUBCOMMAND', 'Manages config files for this gem'
86
92
  subcommand :config, Branch::Name::Subcommands::Config
87
93
 
88
94
  desc '--version, -v', 'Displays this gem version'
89
95
  def version
90
- puts Branch::Name::VERSION
96
+ say Branch::Name::VERSION
97
+ end
98
+
99
+ private
100
+
101
+ def init_options_for!(command:)
102
+ say "Options before config file merge: #{options}" if options[:debug]
103
+
104
+ load_options = load_options(defaults: DEFAULT_BRANCH_NAME_OPTIONS)[command.to_s] || {}
105
+ say "No options loaded from config file(s): #{load_options}" if options[:debug] && load_options.blank?
106
+ say "Options loaded from config file(s): #{load_options}" if options[:debug]
107
+
108
+ self.options = Thor::CoreExt::HashWithIndifferentAccess.new(load_options.merge(options))
109
+ say "Options after config file merge: #{options}" if options[:debug]
91
110
  end
92
111
  end
93
112
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ module Clipable
6
+ module_function
7
+
8
+ def copy_to_clipboard(text)
9
+ if /darwin/.match?(RUBY_PLATFORM)
10
+ IO.popen('pbcopy', 'w') { |pipe| pipe.puts text }
11
+ true
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'colorize'
4
+ require 'fileutils'
5
+ require 'yaml'
4
6
  require_relative 'locatable'
5
7
 
6
8
  module Branch
@@ -8,7 +10,18 @@ module Branch
8
10
  module Configurable
9
11
  include Locatable
10
12
 
11
- CONFIG_FILENAME = '.branch-nameconfig'
13
+ CONFIG_FILENAME = '.branch-name'
14
+ # rubocop:disable Style/StringHashKeys - YAML writing/loading necessitates this
15
+ DEFAULT_BRANCH_NAME_OPTIONS = {
16
+ 'create' => {
17
+ 'downcase' => false,
18
+ 'separator' => '_',
19
+ 'project' => false,
20
+ 'project_location' => Locatable.project_folder,
21
+ 'project_files' => %w[scratch.rb readme.txt]
22
+ }
23
+ }.freeze
24
+ # rubocop:enable Style/StringHashKeys
12
25
 
13
26
  module_function
14
27
 
@@ -25,33 +38,71 @@ module Branch
25
38
  end
26
39
 
27
40
  def global_config_file?
28
- Dir.exist? global_config_file
41
+ File.exist? global_config_file
29
42
  end
30
43
 
31
44
  def local_config_file?
32
- Dir.exist? local_config_file
45
+ File.exist? local_config_file
33
46
  end
34
47
 
35
48
  def system_config_file?
36
- Dir.exist? system_config_file
49
+ File.exist? system_config_file
37
50
  end
38
51
 
39
52
  def create_global_config_file!
40
- return false if Dir.exist? global_config_file
41
-
42
- Dir.mkdir(global_config_file) == 0
53
+ create_config_file global_config_file
43
54
  end
44
55
 
45
56
  def create_local_config_file!
46
- return false if Dir.exist? local_config_file
47
-
48
- Dir.mkdir(local_config_file) == 0
57
+ create_config_file local_config_file
49
58
  end
50
59
 
51
60
  def create_system_config_file!
52
- return false if Dir.exist? system_config_file
61
+ create_config_file system_config_file
62
+ end
63
+
64
+ def delete_global_config_file!
65
+ delete_config_file global_config_file
66
+ end
67
+
68
+ def delete_local_config_file!
69
+ delete_config_file local_config_file
70
+ end
71
+
72
+ def delete_system_config_file!
73
+ delete_config_file system_config_file
74
+ end
75
+
76
+ private
77
+
78
+ def create_config_file(config_file)
79
+ folder = File.dirname(config_file)
80
+ unless Dir.exist?(folder)
81
+ say "Destination folder for configuration file (#{folder}) does not exist".red
82
+ return false
83
+ end
84
+
85
+ if File.exist?(config_file)
86
+ puts "Configuration file (#{config_file}) already exists".yellow
87
+ return false
88
+ end
89
+
90
+ File.write(config_file, DEFAULT_BRANCH_NAME_OPTIONS.to_yaml)
91
+ puts "Configuration file (#{config_file}) created".green
92
+
93
+ true
94
+ end
95
+
96
+ def delete_config_file(config_file)
97
+ unless File.exist?(config_file)
98
+ puts "Configuration file (#{config_file}) does not exist".yellow
99
+ return false
100
+ end
101
+
102
+ File.delete config_file
103
+ puts "Configuration file (#{config_file}) deleted".green
53
104
 
54
- Dir.mkdir(system_config_file) == 0
105
+ true
55
106
  end
56
107
  end
57
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Branch
2
4
  module Name
3
5
  module Exitable
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'yaml'
5
+ require_relative 'configurable'
6
+
7
+ module Branch
8
+ module Name
9
+ module Loadable
10
+ include Configurable
11
+
12
+ def load_options(defaults: {})
13
+ options = {}
14
+
15
+ options.merge!(load_config(system_config_file))
16
+ options.merge!(load_config(global_config_file))
17
+ options.merge!(load_config(local_config_file))
18
+
19
+ options.presence || defaults
20
+ end
21
+
22
+ def load_config(config_file)
23
+ return {} unless File.exist? config_file
24
+
25
+ yaml_options = File.read(config_file)
26
+ YAML.safe_load ERB.new(yaml_options).result
27
+ end
28
+ end
29
+ end
30
+ end
@@ -11,7 +11,7 @@ module Branch
11
11
  def home_folder
12
12
  Dir.home
13
13
  end
14
- alias_method :global_folder, :home_folder
14
+ alias global_folder home_folder
15
15
  singleton_class.alias_method :global_folder, :home_folder
16
16
 
17
17
  def local_folder
@@ -22,7 +22,7 @@ module Branch
22
22
  system_folder = Pathname.new('/')
23
23
  unless system_folder.exist? && system_folder.directory?
24
24
  puts "WARNING: system folder #{system_folder} does not exist, " \
25
- "using global folder instead (#{global_folder})".red
25
+ "using global folder instead (#{global_folder})".red
26
26
 
27
27
  return global_folder
28
28
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ module Nameable
6
+ def normalize_branch_name(branch_name)
7
+ branch_name.strip!
8
+ branch_name = branch_name.split.join options[:separator]
9
+ branch_name.downcase! if options[:downcase]
10
+ branch_name.tr!('_', '-') if options[:separator] == '-'
11
+ branch_name.tr!('-', '_') if options[:separator] == '_'
12
+ branch_name.squeeze!('-') if options[:separator] == '-'
13
+ branch_name.squeeze!('_') if options[:separator] == '_'
14
+ branch_name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,46 @@
1
+
2
+ require 'fileutils'
3
+ require_relative 'locatable'
4
+
5
+ module Branch
6
+ module Name
7
+ module Projectable
8
+ include Locatable
9
+
10
+ def create_project!(branch_name)
11
+ raise 'options[:project] is false' unless options[:project]
12
+
13
+ project_folder = "#{options[:project_location]}/#{branch_name}"
14
+
15
+ if Dir.exist? project_folder
16
+ puts "Project folder \"#{project_folder}\" already exists"
17
+ create_project_files!(project_folder)
18
+ return
19
+ end
20
+
21
+ Dir.mkdir project_folder
22
+ create_project_files!(project_folder)
23
+
24
+ puts "Project folder \"#{project_folder}\" with project files #{options[:project_files]} was created".green
25
+ end
26
+
27
+ def create_project_files!(project_folder)
28
+ raise 'options[:project] is false' unless options[:project]
29
+ raise "Project folder \"#{project_folder}\" does not exist" unless Dir.exist? project_folder
30
+
31
+ project_files = options[:project_files]
32
+
33
+ return if project_files.blank?
34
+
35
+ project_files.each do |project_file|
36
+ full_file_name = File.join(project_folder, project_file)
37
+
38
+ next if File.exist? full_file_name
39
+
40
+ FileUtils.touch full_file_name
41
+ puts "Created project file \"#{full_file_name}\""
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
4
3
  require 'thor'
5
4
  require_relative '../configurable'
6
5
  require_relative '../exitable'
6
+ require_relative 'init'
7
7
 
8
8
  module Branch
9
9
  module Name
@@ -43,6 +43,39 @@ module Branch
43
43
  say "System config file does not exist at: \"#{system_folder}\"", :yellow
44
44
  end
45
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
+ end
76
+
77
+ desc 'init SUBCOMMAND', 'Sets up config files for this gem'
78
+ subcommand :init, Branch::Name::Subcommands::Init
46
79
  end
47
80
  end
48
81
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
4
3
  require 'thor'
5
4
  require_relative '../configurable'
6
5
  require_relative '../exitable'
@@ -15,11 +14,11 @@ module Branch
15
14
 
16
15
  default_task :global
17
16
 
18
- desc 'global', 'Creates and initializes a .branch-nameconfig file in the global folder'
17
+ desc 'global', 'Creates and initializes a .branch-name file in the global folder'
19
18
  long_desc <<-LONG_DESC
20
19
  NAME
21
20
  \x5
22
- `branch-name init global` -- will create and initialize a .branch-nameconfig file
21
+ `branch-name init global` -- will create and initialize a .branch-name file
23
22
  in the "#{Locatable.global_folder}" folder.
24
23
 
25
24
  SYNOPSIS
@@ -27,18 +26,14 @@ module Branch
27
26
  branch-name init global
28
27
  LONG_DESC
29
28
  def global
30
- if create_global_config_file!
31
- say "Global config file created \"#{global_config_file}\"", :green
32
- else
33
- say "Global config file already exists \"#{global_config_file}\"", :yellow
34
- end
29
+ create_global_config_file!
35
30
  end
36
31
 
37
- desc 'local', 'Creates and initializes a .branch-nameconfig file in the local folder'
32
+ desc 'local', 'Creates and initializes a .branch-name file in the local folder'
38
33
  long_desc <<-LONG_DESC
39
34
  NAME
40
35
  \x5
41
- `branch-name init local` -- will create and initialize a .branch-nameconfig file
36
+ `branch-name init local` -- will create and initialize a .branch-name file
42
37
  in the "#{Locatable.local_folder}" folder.
43
38
 
44
39
  SYNOPSIS
@@ -46,18 +41,14 @@ module Branch
46
41
  branch-name init local
47
42
  LONG_DESC
48
43
  def local
49
- if create_local_config_file!
50
- say "Local config file created \"#{local_config_file}\"", :green
51
- else
52
- say "Local config file already exists \"#{local_config_file}\"", :yellow
53
- end
44
+ create_local_config_file!
54
45
  end
55
46
 
56
- desc 'system', 'Creates and initializes a .branch-nameconfig file in the system folder'
47
+ desc 'system', 'Creates and initializes a .branch-name file in the system folder'
57
48
  long_desc <<-LONG_DESC
58
49
  NAME
59
50
  \x5
60
- `branch-name init system` -- will create and initialize a .branch-nameconfig file
51
+ `branch-name init system` -- will create and initialize a .branch-name file
61
52
  in the "#{Locatable.system_folder}" folder.
62
53
 
63
54
  SYNOPSIS
@@ -65,11 +56,7 @@ module Branch
65
56
  branch-name init system
66
57
  LONG_DESC
67
58
  def system
68
- # if create_system_config_file!
69
- # say "System config file created \"#{system_config_file}\"", :green
70
- # else
71
- # say "System config file already exists \"#{system_config_file}\"", :yellow
72
- # end
59
+ # create_system_config_file!
73
60
  say_error 'System initialization is not available at this time', :red
74
61
  exit 1
75
62
  end
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '0.1.0-alpha'
6
+ VERSION = '1.0.0-beta'
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: 0.1.0.pre.alpha
4
+ version: 1.0.0.pre.beta
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-17 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -89,9 +89,13 @@ files:
89
89
  - lib/branch/name.rb
90
90
  - lib/branch/name/cli.rb
91
91
  - lib/branch/name/cli/thor_ext/shell/basic/say_error.rb
92
+ - lib/branch/name/clipable.rb
92
93
  - lib/branch/name/configurable.rb
93
94
  - lib/branch/name/exitable.rb
95
+ - lib/branch/name/loadable.rb
94
96
  - lib/branch/name/locatable.rb
97
+ - lib/branch/name/nameable.rb
98
+ - lib/branch/name/projectable.rb
95
99
  - lib/branch/name/subcommands/config.rb
96
100
  - lib/branch/name/subcommands/init.rb
97
101
  - lib/branch/name/version.rb
@@ -103,6 +107,7 @@ metadata:
103
107
  homepage_uri: https://github.com/gangelo/branch_name
104
108
  source_code_uri: https://github.com/gangelo/branch-name
105
109
  changelog_uri: https://github.com/gangelo/branch-name/CHANGELOG.md
110
+ rubygems_mfa_required: 'true'
106
111
  post_install_message:
107
112
  rdoc_options: []
108
113
  require_paths: