1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
From d9162927289bc35648551e8eec647980c88da78b Mon Sep 17 00:00:00 2001
From: Jari Aalto <jari.aalto@cante.net>
Date: Sun, 15 Jun 2014 19:34:53 +0300
Subject: [PATCH] Add Help and option handling
Organization: Private
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
splitpatch.rb | 66 ++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 46 insertions(+), 20 deletions(-)
--- a/splitpatch.rb
+++ b/splitpatch.rb
@@ -157,37 +157,63 @@
end
+def help
+ puts <<EOF
+SYNOPSIS
+ #{PROGRAM} [options] FILE.patch
+
+OPTIONS
+ -h,--help
+ -H,--hunk
+ -V,--version
+
+DESCRIPTION
+
+ Split the patch up into files or hunks
+
+ Divide a patch or diff file into pieces. The split can made by file
+ or by hunk basis. This makes it possible to separate changes that
+ might not be desirable or assemble the patch into a more coherent set
+ of changes. See e.g. combinediff(1) from patchutils package.
-######################## MAIN ########################
+ Note: only patches in unified format are recognized.
+EOF
+end
+
+def version
+ puts "#{VERSION} #{LICENSE} #{AUTHOR}"
+end
+######################## MAIN ########################
-if ARGV.length < 1 or ARGV.length > 3
- puts "Wrong parameter. Usage: splitpatch.rb [--fullname] [--hunks] <patchfile>"
- exit 1
-elsif ARGV[0] == "--help"
- puts "splitpatch splits a patch that is supposed to patch multiple files"
- puts "into a set of patches."
- puts "Currently splits unified diff patches."
- puts "If the --hunk option is given, a new file is created for each hunk."
- puts "If the --fullname option is given, new files are named using the"
- puts "full path of the patch to avoid duplicates in large projects."
+if ARGV.length < 1 or ARGV.length > 2
+ puts "ERROR: missing argument. See --help."
exit 1
else
- s = Splitter.new(ARGV[-1])
- if s.validFile?
- if ARGV[0] == "--fullname" or ARGV[1] == "--fullname"
- s.fullname(true)
+ opt = ARGV[0]
+ if /^-h$|--help/.match(opt)
+ help
+ exit 0
+ elsif /^-H$|--hunks?/.match(opt)
+ hunk = 1
+ elsif /^-V$|--version/.match(opt)
+ version
+ exit 0
+ elsif /^-/.match(opt)
+ puts "ERROR: Unknonw option: #{opt}. See --help."
+ exit 1
end
-
- if ARGV[0] == "--hunks" or ARGV[1] == "--hunks"
+ file = ARGV[-1]
+ s = Splitter.new(file)
+ if s.validFile?
+ if hunk
s.splitByHunk
else
s.splitByFile
end
else
- puts "File does not exist or is not readable"
+ puts "File does not exist or is not readable: #{file}"
end
end
-
-
+# End of file
|