git-newline-at-eof 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9174c33ef7a822bbbe6b7f0b791bed36d7b3ad19
4
- data.tar.gz: f3b93079fee26591df3bc50f29a8176dd6206289
3
+ metadata.gz: 1a01c1b70f05acc4a310172b58b8d7e5671512ab
4
+ data.tar.gz: b142b16ed809608cefa7cd1c6cf2d8c4424e9452
5
5
  SHA512:
6
- metadata.gz: 373d11b4fdabfcdda3299720c92211f35d4c06e77119bbe434c488e771a24d35694df78e5a287d2ddb68b8f8b478fe314d8869759a0fcaaba77f42e46c44a81d
7
- data.tar.gz: e79543fb3b7e4aa15abefda059db662d90043f4b57911d4399d873509acadb1996d677a5b9f85d112460b7939e18479825d259071edf0c77aee6f611235b30f2
6
+ metadata.gz: 7767f8d52eca61f9e31736f7d00d1b9e3274a567da7d9569dc965eddfcbdc3891b84568eea6348426f123df39990ef34c93a7847295a6444359244a36cc63b61
7
+ data.tar.gz: 833f844b2f87af807efb00f4953e89aaa6dbd3b0620c3138a065c4c6b9e6e117ca21dbf329ac79dfee2e2b019e014f098abebd42bdd17a947eea01bd4c102ea4
data/README.md CHANGED
@@ -57,6 +57,8 @@ $ git commit -m "Fix last line terminator"
57
57
  1 file changed, 1 insertion(+), 1 deletion(-)
58
58
  ```
59
59
 
60
+ Zero byte file has zero newline for termination because it has zero line.
61
+
60
62
  ### `--discard-last-newline`
61
63
 
62
64
  Remove discarded newline at end of file.
@@ -105,22 +107,37 @@ $ mkdir /tmp/test
105
107
  $ cd /tmp/test
106
108
  $ printf "" > file0
107
109
  $ printf "aaa" > file1
108
- $ printf "bbb\n\n" > file2
109
- $ printf "ccc\n\n\n" > file3
110
+ $ printf "bbb\n" > file2
111
+ $ printf "ccc\n\n" > file3
112
+ $ printf "ddd\n\n\n" > file4
110
113
  $ git init
111
114
  Initialized empty Git repository in /tmp/test/.git/
112
115
  $ git add .
113
116
  $ git commit -m "Initial commit"
114
- [master (root-commit) 28cf1f0] Initial commit
115
- 4 files changed, 6 insertions(+)
117
+ [master (root-commit) 0806035] Initial commit
118
+ 5 files changed, 7 insertions(+)
116
119
  create mode 100644 file0
117
120
  create mode 100644 file1
118
121
  create mode 100644 file2
119
122
  create mode 100644 file3
123
+ create mode 100644 file4
120
124
  $ git newline-at-eof --check-all
121
125
  file1: no newline at end of file
122
- file2: discarded 1 newline at end of file
123
- file3: discarded 2 newlines at end of file
126
+ file3: discarded 1 newline at end of file
127
+ file4: discarded 2 newlines at end of file
128
+ ```
129
+
130
+ ### `--help`
131
+
132
+ Help.
133
+
134
+ ```bash
135
+ $ git newline-at-eof --help
136
+ Usage: git-newline-at-eof [options]
137
+ -f, --feed-last-line Add newline to line what is not terminated by newline at end of file.
138
+ -d, --discard-last-newline Remove discarded newline at end of file.
139
+ -a, --treat-all This is identical with --feed-last-line --discard-last-newline.
140
+ -c, --check-all Check and show warning about newline at end of file.
124
141
  ```
125
142
 
126
143
  ## Supported Versions
@@ -5,29 +5,89 @@ module GitNewlineAtEof
5
5
  class Application
6
6
  def initialize(argv)
7
7
  @files = files
8
- @is_feed_last_line = false
9
- @is_discard_last_newline = false
10
- @is_treat_all = false
11
- @is_check_all = false
8
+ @options = {}
9
+ @options[:feed_last_line] = false
10
+ @options[:discard_last_newline] = false
11
+ @options[:treat_all] = false
12
+ @options[:check_all] = false
13
+ @options[:opted] = false
12
14
 
13
- opt = OptionParser.new
14
- opt.on('-f', '--feed-last-line') { |v| @is_feed_last_line = true }
15
- opt.on('-d', '--discard-last-newline') { |v| @is_discard_last_newline = true }
16
- opt.on('-a', '--treat-all') { |v| @is_treat_all = true }
17
- opt.on('-c', '--check-all') { |v| @is_check_all = true }
18
- opt.parse!(argv)
15
+ @opt = OptionParser.new
16
+ [
17
+ [
18
+ '-f', '--feed-last-line',
19
+ 'Add newline to line what is not terminated by newline at end of file.',
20
+ proc { |v|
21
+ @options[:feed_last_line] = true
22
+ @options[:opted] = true
23
+ }
24
+ ],
25
+ [
26
+ '-d',
27
+ '--discard-last-newline',
28
+ 'Remove discarded newline at end of file.',
29
+ proc { |v|
30
+ @options[:discard_last_newline] = true
31
+ @options[:opted] = true
32
+ }
33
+ ],
34
+ [
35
+ '-a',
36
+ '--treat-all',
37
+ 'This is identical with --feed-last-line --discard-last-newline.',
38
+ proc { |v|
39
+ @options[:treat_all] = true
40
+ @options[:opted] = true
41
+ }
42
+ ],
43
+ [
44
+ '-c',
45
+ '--check-all',
46
+ 'Check and show warning about newline at end of file.',
47
+ proc { |v|
48
+ @options[:check_all] = true
49
+ @options[:opted] = true
50
+ }
51
+ ],
52
+ [
53
+ '-h',
54
+ '--help',
55
+ 'Show this message.',
56
+ proc { |v|
57
+ puts @opt.help
58
+ @options[:opted] = true
59
+ }
60
+ ],
61
+ [
62
+ '-v',
63
+ '--version',
64
+ 'Show version.',
65
+ proc {
66
+ @options[:opted] = true
67
+ puts @opt.ver
68
+ }
69
+ ]
70
+ ].each do |short, long, desc, proc_obj|
71
+ @opt.on(short, long, desc, &proc_obj)
72
+ end
73
+ @opt.program_name = 'git newline-at-eof'
74
+ @opt.version = GitNewlineAtEof::VERSION
75
+ @opt.parse!(argv)
19
76
  end
20
77
 
21
78
  def run
22
- if @is_check_all
79
+ unless @options[:opted]
80
+ puts @opt.help
81
+ end
82
+ if @options[:check_all]
23
83
  check_all
24
- elsif @is_treat_all
84
+ elsif @options[:treat_all]
25
85
  treat_all
26
86
  else
27
- if @is_feed_last_line
87
+ if @options[:feed_last_line]
28
88
  feed_last_line_all
29
89
  end
30
- if @is_discard_last_newline
90
+ if @options[:discard_last_newline]
31
91
  discard_last_newline_all
32
92
  end
33
93
  end
@@ -1,3 +1,3 @@
1
1
  module GitNewlineAtEof
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-newline-at-eof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Ass