gem-new 0.1.0 → 0.1.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.
@@ -219,19 +219,25 @@ private
219
219
  old_content = File.read(path)
220
220
  return false if old_content == new_content
221
221
 
222
- while result.nil?
222
+ puts diff(configuration, path, new_content) if configuration.auto_diff
223
+
224
+ loop do
223
225
  print("File already exists, replace? ([N]o, [y]es, [d]iff) ")
224
226
  $stdout.flush
225
227
  case $stdin.gets
226
228
  when nil then abort("Terminated")
227
229
  when /^y(?:es)?$/i then return true
228
- when /^n(?:o)?$/i then return false
229
- when /^d(?:iff)?$/i then puts Open3.popen3(configuration.diff_tool % path) { |i,o,e| i.puts new_content; i.close; o.read }
230
+ when /^n(?:o)?$/i, /^$/ then return false
231
+ when /^d(?:iff)?$/i then puts diff(configuration, path, new_content)
230
232
  else puts "Invalid reply"
231
233
  end
232
234
  end
233
235
  end
234
236
 
237
+ def diff(configuration, path, new_content)
238
+ Open3.popen3(configuration.diff_tool % path) { |i,o,e| i.puts new_content; i.close; o.read }
239
+ end
240
+
235
241
  def prompt(question, default=:yes)
236
242
  print "#{question} #{default == :yes ? '([Y]es, [n]o)' : '([N]o, [y]es)'} "
237
243
  $stdout.flush
@@ -250,7 +256,7 @@ private
250
256
  # the template used without -t option
251
257
  default_template: default
252
258
  # the diff command used to show diffs on update, %s is the path to the old file
253
- diff_tool: diff -y --label old --label new %s -
259
+ diff_tool: diff -u --label old --label new %s -
254
260
  # whether a diff should be shown right away in updates, without asking first
255
261
  auto_diff: true
256
262
  # content variables are used for subsitution in template files, also see path_variables
@@ -24,6 +24,10 @@ class Gem::Commands::NewCommand < Gem::Command
24
24
  @config['config_version']
25
25
  end
26
26
 
27
+ def auto_diff
28
+ @config['auto_diff']
29
+ end
30
+
27
31
  def initial_version
28
32
  "0.0.1"
29
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-new
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ files:
43
43
  - lib/gem/commands/new_command/version.rb
44
44
  - lib/gem/commands/new_command.rb
45
45
  - lib/rubygems_plugin.rb
46
- homepage: http://github.com/apeiros/gem-new
46
+ homepage: https://github.com/apeiros/gem-new
47
47
  licenses: []
48
48
  post_install_message:
49
49
  rdoc_options: []