kintsugi 0.7.0 → 0.7.1

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: bd0bf9dde374b1b29b0e386ff0f4f051f6686e04b140199c8b62d6a73c053285
4
- data.tar.gz: 8845644c3e18fb6244f402d2b432966a0f6e437ced4f441cdd1d43a06369ef51
3
+ metadata.gz: 4d6a3f2f971989db51d411587800237c653c8c09f23ed14a5d6e7ab4acbdc0c0
4
+ data.tar.gz: f9eb196e1cb97a9a683ec237d71d4943eb11371409ddd918500d898059c4f16f
5
5
  SHA512:
6
- metadata.gz: 0fd505102998df8f7b0c16d7a0fe7b437e5b6402db784383f752f7b0272fe5b7f2ab2c7b9c18e3de2ee3c071b5cf21577bb4089c792a6ca15286efa3f1f9ae7d
7
- data.tar.gz: 85d252a8135e10b536b042156dc787e9a8d9ac5286736d01113ea4380a49d049f8837430d15490f15c3d14cbdf0f7a3cf75ac5dc4f2047bef55cc7f6fb00f837
6
+ metadata.gz: caa76ce1cae66040d14851dc37f9cbe63269e6565be887f7f31db0016249af5a95bc05e414041aa1f4a2d4e23d534a976383faacf391f6f9bfd2ab880cb524f0
7
+ data.tar.gz: e92ee6af254ea336b067abd7bfc805bc5d878873f5de74ed4d06c2847e75e24b836a8ad2a4f81edfee78d0c9db8378f6e84f41a6fc210b69ee6e5f31a7b938e1
data/lib/kintsugi/cli.rb CHANGED
@@ -31,21 +31,12 @@ module Kintsugi
31
31
  Command = Struct.new(:option_parser, :action, :description, keyword_init: true)
32
32
 
33
33
  def create_driver_subcommand
34
- option_parser =
35
- OptionParser.new do |opts|
36
- opts.banner = "Usage: kintsugi driver BASE OURS THEIRS ORIGINAL_FILE_PATH [options]\n" \
37
- "Uses Kintsugi as a Git merge driver. Parameters " \
38
- "should be the path to base version of the file, path to ours version, path to " \
39
- "theirs version, and the original file path."
40
-
41
- opts.on("--interactive-resolution=FLAG", TrueClass, "In case a conflict that requires " \
42
- "human decision to resolve, show an interactive prompt with choices to resolve it")
43
-
44
- opts.on("-h", "--help", "Prints this help") do
45
- puts opts
46
- exit
47
- end
48
- end
34
+ option_parser = create_base_option_parser
35
+ option_parser.banner = "Usage: kintsugi driver BASE OURS THEIRS ORIGINAL_FILE_PATH " \
36
+ "[options]\n" \
37
+ "Uses Kintsugi as a Git merge driver. Parameters " \
38
+ "should be the path to base version of the file, path to ours version, path to " \
39
+ "theirs version, and the original file path."
49
40
 
50
41
  driver_action = lambda { |options, arguments|
51
42
  if arguments.count != 4
@@ -54,9 +45,7 @@ module Kintsugi
54
45
  exit(1)
55
46
  end
56
47
 
57
- unless options[:"interactive-resolution"].nil?
58
- Settings.interactive_resolution = options[:"interactive-resolution"]
59
- end
48
+ update_settings(options)
60
49
 
61
50
  Kintsugi.three_way_merge(arguments[0], arguments[1], arguments[2], arguments[3])
62
51
  warn "\e[32mKintsugi auto-merged #{arguments[3]}\e[0m"
@@ -70,17 +59,10 @@ module Kintsugi
70
59
  end
71
60
 
72
61
  def create_install_driver_subcommand
73
- option_parser =
74
- OptionParser.new do |opts|
75
- opts.banner = "Usage: kintsugi install-driver [driver-options]\n" \
76
- "Installs Kintsugi as a Git merge driver globally. `driver-options` will be passed " \
77
- "to `kintsugi driver`."
78
-
79
- opts.on("-h", "--help", "Prints this help") do
80
- puts opts
81
- exit
82
- end
83
- end
62
+ option_parser = create_base_option_parser
63
+ option_parser.banner = "Usage: kintsugi install-driver [driver-options]\n" \
64
+ "Installs Kintsugi as a Git merge driver globally. `driver-options` will be passed " \
65
+ "to `kintsugi driver`."
84
66
 
85
67
  action = lambda { |options, arguments|
86
68
  if arguments.count != 0
@@ -94,7 +76,9 @@ module Kintsugi
94
76
  exit(1)
95
77
  end
96
78
 
97
- install_kintsugi_driver_globally(options)
79
+ driver_options = extract_driver_options(options, option_parser)
80
+
81
+ install_kintsugi_driver_globally(driver_options)
98
82
  puts "Done! 🪄"
99
83
  }
100
84
 
@@ -105,9 +89,30 @@ module Kintsugi
105
89
  )
106
90
  end
107
91
 
92
+ def extract_driver_options(options, option_parser)
93
+ options.map do |option_name, option_value|
94
+ switch = option_parser.top.search(:long, option_name.to_s)
95
+ prefix = "--"
96
+ if switch.nil?
97
+ switch = option_parser.top.search(:short, option_name.to_s)
98
+ prefix = "-"
99
+ end
100
+ case switch
101
+ when OptionParser::Switch::NoArgument
102
+ [prefix + option_name.to_s]
103
+ when NilClass
104
+ puts "Invalid flag #{option_name} passed to 'install-driver' subcommand\n\n"
105
+ puts option_parser
106
+ exit(1)
107
+ else
108
+ [prefix + option_name.to_s, option_value]
109
+ end
110
+ end.flatten
111
+ end
112
+
108
113
  def install_kintsugi_driver_globally(options)
109
114
  `git config --global merge.kintsugi.name "Kintsugi driver"`
110
- kintsugi_command = "kintsugi driver %O %A %B %P #{options}"
115
+ kintsugi_command = "kintsugi driver %O %A %B %P #{options.join(" ")}".rstrip
111
116
  `git config --global merge.kintsugi.driver "#{kintsugi_command}"`
112
117
 
113
118
  attributes_file_path = global_attributes_file_path
@@ -173,33 +178,21 @@ module Kintsugi
173
178
  end
174
179
 
175
180
  def create_root_command
176
- option_parser = OptionParser.new do |opts|
177
- opts.banner = "Kintsugi, version #{Version::STRING}\n" \
178
- "Copyright (c) 2021 Lightricks\n\n" \
179
- "Usage: kintsugi <pbxproj_filepath> [options]\n" \
180
- " kintsugi <subcommand> [options]"
181
-
182
- opts.separator ""
183
- opts.on("--changes-output-path=PATH", "Path to which changes applied to the project are " \
184
- "written in JSON format. Used for debug purposes.")
185
-
186
- opts.on("-h", "--help", "Prints this help") do
187
- puts opts
188
- exit
189
- end
190
-
191
- opts.on("-v", "--version", "Prints version") do
192
- puts Version::STRING
193
- exit
194
- end
195
-
196
- opts.on("--allow-duplicates", "Allow to add duplicates of the same entity")
181
+ option_parser = create_base_option_parser
182
+ option_parser.banner = "Kintsugi, version #{Version::STRING}\n" \
183
+ "Copyright (c) 2021 Lightricks\n\n" \
184
+ "Usage: kintsugi <pbxproj_filepath> [options]\n" \
185
+ " kintsugi <subcommand> [options]"
186
+
187
+ option_parser.on("-v", "--version", "Prints version") do
188
+ puts Version::STRING
189
+ exit
190
+ end
197
191
 
198
- opts.on("--interactive-resolution=FLAG", TrueClass, "In case a conflict that requires " \
199
- "human decision to resolve, show an interactive prompt with choices to resolve it")
192
+ option_parser.on("--changes-output-path=PATH", "Path to which changes applied to the " \
193
+ "project are written in JSON format. Used for debug purposes.")
200
194
 
201
- opts.on_tail("\nSUBCOMMANDS\n#{subcommands_descriptions(subcommands)}")
202
- end
195
+ option_parser.on_tail("\nSUBCOMMANDS\n#{subcommands_descriptions(subcommands)}")
203
196
 
204
197
  root_action = lambda { |options, arguments|
205
198
  if arguments.count != 1
@@ -208,13 +201,7 @@ module Kintsugi
208
201
  exit(1)
209
202
  end
210
203
 
211
- if options[:"allow-duplicates"]
212
- Settings.allow_duplicates = true
213
- end
214
-
215
- unless options[:"interactive-resolution"].nil?
216
- Settings.interactive_resolution = options[:"interactive-resolution"]
217
- end
204
+ update_settings(options)
218
205
 
219
206
  project_file_path = File.expand_path(arguments[0])
220
207
  Kintsugi.resolve_conflicts(project_file_path, options[:"changes-output-path"])
@@ -228,6 +215,32 @@ module Kintsugi
228
215
  )
229
216
  end
230
217
 
218
+ def create_base_option_parser
219
+ OptionParser.new do |opts|
220
+ opts.separator ""
221
+
222
+ opts.on("-h", "--help", "Prints this help") do
223
+ puts opts
224
+ exit
225
+ end
226
+
227
+ opts.on("--allow-duplicates", "Allow to add duplicates of the same entity")
228
+
229
+ opts.on("--interactive-resolution=FLAG", TrueClass, "In case a conflict that requires " \
230
+ "human decision to resolve, show an interactive prompt with choices to resolve it")
231
+ end
232
+ end
233
+
234
+ def update_settings(options)
235
+ if options[:"allow-duplicates"]
236
+ Settings.allow_duplicates = true
237
+ end
238
+
239
+ unless options[:"interactive-resolution"].nil?
240
+ Settings.interactive_resolution = options[:"interactive-resolution"]
241
+ end
242
+ end
243
+
231
244
  def subcommands_descriptions(subcommands)
232
245
  longest_subcommand_length = subcommands.keys.map(&:length).max + 4
233
246
  format_string = " %-#{longest_subcommand_length}s%s"
@@ -3,6 +3,6 @@
3
3
  module Kintsugi
4
4
  # This module holds the Kintsugi version information.
5
5
  module Version
6
- STRING = "0.7.0"
6
+ STRING = "0.7.1"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kintsugi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Yohay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt