wielder_of_anor 0.3.2 → 0.4.0

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: 0f08a4a73db94f9e44b7764c819655e2f14361c1
4
- data.tar.gz: f504c95bc2412f9964f410a532df44a999b36571
3
+ metadata.gz: 47f95532e9ef0f162cee99d705e5ff57d76e603f
4
+ data.tar.gz: 19b253f236f65500cc08ed86a79b4292d2e7ad1c
5
5
  SHA512:
6
- metadata.gz: 0451030755baf95f3303803b9f0be8c41950d85f2261c826000a4d22357dd9a7da9fe9463399abb3b75b1248119cde5ec50a50d5ebdeab0f88a1d0d4cca86b5f
7
- data.tar.gz: 9dc546b61a21472022dad1c0d627096e036525ed583d78e4d95ce7ccad4019af3d2952474f2fdb38cb28581324b4121a29bfe2f08d917bbea75d5edda5aabef4
6
+ metadata.gz: cb7b6cdaeaf0762b20bdb52bf95d0129ff7b61060859f2b6872c8ba913c6bbc087777cf95ced720bdd2e2cf66ff4671711ca6d04034886d24ea14dc45b58caf4
7
+ data.tar.gz: f7aadde722183cd655b094feaee85aa976a24ad2bbdaa75eab375ddb5f3d05ec096d8eca3993f61a6057a1cf4fa9a0f913636fd0b3e7d2129c992f854218dd02
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- docs/forbidden_words
2
- docs/files_changed
3
- config/config.yaml
4
- Gemfile.lock
5
- .idea
1
+ docs/forbidden_words
2
+ docs/files_changed
3
+ config/config.yaml
4
+ Gemfile.lock
5
+ .idea
6
6
  .bundle
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 iamsellek
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 iamsellek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,115 +1,115 @@
1
- # Wielder of Anor
2
- Checks a user's staged files for "forbidden" words (as determined by the user)
3
- and, if any are found, alerts the user to the locations of said words.
4
-
5
- ## Longer Description
6
- I am absent-minded. Very absent-minded. Absent-minded to the point that I'll
7
- throw some "puts" or "console.log" commands into my code for debugging purposes
8
- only to completely forget about them and then happily push all my code to
9
- master branch without a care in the world. This...is not okay. Yet despite my
10
- constant reminders to my brain that it most certainly is not okay, it keeps
11
- quite happily forgetting everything about everything when it's time to commit
12
- my code. And since I (apparently) can't magically fix the way my brain works, I
13
- figured I'd make my computer double-check me since, you know, that is the entire
14
- reason we invented computers to begin with. Enter Wielder of Anor.
15
-
16
- Wielder of Anor is a quick and easy way to ensure that you aren't pushing your
17
- code to production (or anywhere else it shouldn't be) with "forbidden words" you
18
- don't want there. You yourself determine which words are forbidden, so this app
19
- should be helpful to anyone wanting to prevent certain text from making it past
20
- your dev environment. Maybe you're like me and you can never remember to pull
21
- your debugging commands out of your code before committing. Maybe you're a code
22
- master and commit swaths of code at a time, laughing at the mere mortals around
23
- you who commit smaller chunks of work several times a day, and you can't be
24
- bothered to check through your tens of thousands of lines of code to ensure you
25
- didn't leave some debugging command in there somewhere. Or maybe your code gets
26
- more and more filled with swear words the more frustrating a problem gets and
27
- you just can't let one of those slip to production again because seriously it'd
28
- be like the third or fourth time and you like working here and can't imagine
29
- staying here if you slip up another time or two and...
30
-
31
- Ahem. Sorry.
32
-
33
- So. If you need to prevent anything in your code from making it past your dev
34
- environment and need a reliable way to do this, use Wielder of Anor.
35
-
36
- ## Installation
37
- Installation is simple! Just run a `gem install wielder_of_anor`, then run
38
- `wielder_of_anor` and follow the instructions. You're now good to go!
39
-
40
- ## Use/What It Does
41
- To use Wielder of Anor, just run it *from within the code directory you want to
42
- run the forbidden words checks against* (this is important). From your code
43
- directory, just type `wielder_of_anor` followed by your arguments. You can pass
44
- in a couple of arguments here.
45
-
46
- The first argument can be:
47
-
48
- * Your eventual commit message (in quotes), if you've chosen to allow Wielder
49
- of Anor itself to run your commits for you. If you've chosen to *not* allow it
50
- to run your commits for you, this argument will be ignored.
51
- * 'help' - This will simply print out shorter versions of the options you are
52
- currently reading.
53
- * 'config' - This will re-run the configuration process. IF YOU SET ANY OF YOUR
54
- FILE LOCATIONS TO POINT TO PREVIOUSLY EXISTING FILES, THOSE FILES *WILL* BE
55
- OVERWRITTEN.
56
- * 'words' - This will spit out all of the forbidden words that you currently
57
- are checking for.
58
-
59
- There is currently only one option for the second argument:
60
-
61
- * The second argument can only be '1' and will be ignored unless there is a
62
- commit message as the first argument. If this argument is passed, Wielder of
63
- Anor will skip checking for any forbidden words whatsoever and jump straight
64
- to the commit portion of the app. This is mainly here so that you can easily
65
- force a commit after Wielder of Anor tells you of some forbidden words that
66
- you've decided to allow for whatever reason. For instance, say 'puts' is one
67
- of your forbidden words and there's a commented-out puts statement in your
68
- code that you didn't put there and that, as such, you don't want to delete.
69
- It's the only forbidden word showing up, so the rest of your code is clean.
70
- So, instead of now having to type out a full git commit command, you can now
71
- just hit your up arrow, hit the spacebar, type a '1' and hit enter.
72
-
73
- Once run, Wielder of Anor will run a bash command that'll export the result of a
74
- `git diff HEAD --staged --name-only` (so all files that you have 'git add'ed
75
- since git HEAD) to a file. It'll then check every line in every one of those
76
- files for any of your forbidden words and print out the locations of any and
77
- every one it finds.
78
-
79
- If it found none (or if you've skipped the search and are forcing a commit), you
80
- are good to go and can tell the app to then run the git commit command, if
81
- you've opted to allow it to do so. At this point, Wielder of Anor will run a
82
- `git commit -m` followed by your commit message (your first argument when
83
- running the app). Once it prints out "COMMITTED.", execution will end. Don't
84
- forget to run your git push!
85
-
86
- ## Wielder of Anor? Wut.
87
- You know, the thing Gandalf calls himself to the Balrog as he's all "YOU SHALL
88
- NOT PASS!" over and over? When he's, you know, preventing the Balrog from
89
- getting past him? He...he prevents a *forbidden* thing from...
90
-
91
- A gatekeeper. This app is a gatekeeper. Gandalf was a Gatekeeper that one
92
- time. It's artistic. Or something.
93
-
94
- ## License
95
- The MIT License (MIT)
96
-
97
- Copyright (c) 2016 Chris Sellek
98
-
99
- Permission is hereby granted, free of charge, to any person obtaining a copy
100
- of this software and associated documentation files (the "Software"), to deal
101
- in the Software without restriction, including without limitation the rights
102
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
103
- copies of the Software, and to permit persons to whom the Software is
104
- furnished to do so, subject to the following conditions:
105
-
106
- The above copyright notice and this permission notice shall be included in all
107
- copies or substantial portions of the Software.
108
-
109
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ # Wielder of Anor
2
+ Checks a user's staged files for "forbidden" words (as determined by the user)
3
+ and, if any are found, alerts the user to the locations of said words.
4
+
5
+ ## Longer Description
6
+ I am absent-minded. Very absent-minded. Absent-minded to the point that I'll
7
+ throw some "puts" or "console.log" commands into my code for debugging purposes
8
+ only to completely forget about them and then happily push all my code to
9
+ master branch without a care in the world. This...is not okay. Yet despite my
10
+ constant reminders to my brain that it most certainly is not okay, it keeps
11
+ quite happily forgetting everything about everything when it's time to commit
12
+ my code. And since I (apparently) can't magically fix the way my brain works, I
13
+ figured I'd make my computer double-check me since, you know, that is the entire
14
+ reason we invented computers to begin with. Enter Wielder of Anor.
15
+
16
+ Wielder of Anor is a quick and easy way to ensure that you aren't pushing your
17
+ code to production (or anywhere else it shouldn't be) with "forbidden words" you
18
+ don't want there. You yourself determine which words are forbidden, so this app
19
+ should be helpful to anyone wanting to prevent certain text from making it past
20
+ your dev environment. Maybe you're like me and you can never remember to pull
21
+ your debugging commands out of your code before committing. Maybe you're a code
22
+ master and commit swaths of code at a time, laughing at the mere mortals around
23
+ you who commit smaller chunks of work several times a day, and you can't be
24
+ bothered to check through your tens of thousands of lines of code to ensure you
25
+ didn't leave some debugging command in there somewhere. Or maybe your code gets
26
+ more and more filled with swear words the more frustrating a problem gets and
27
+ you just can't let one of those slip to production again because seriously it'd
28
+ be like the third or fourth time and you like working here and can't imagine
29
+ staying here if you slip up another time or two and...
30
+
31
+ Ahem. Sorry.
32
+
33
+ So. If you need to prevent anything in your code from making it past your dev
34
+ environment and need a reliable way to do this, use Wielder of Anor.
35
+
36
+ ## Installation
37
+ Installation is simple! Just run a `gem install wielder_of_anor`, then run
38
+ `wielder_of_anor` and follow the instructions. You're now good to go!
39
+
40
+ ## Use/What It Does
41
+ To use Wielder of Anor, just run it *from within the code directory you want to
42
+ run the forbidden words checks against* (this is important). From your code
43
+ directory, just type `wielder_of_anor` followed by your arguments. You can pass
44
+ in a couple of arguments here.
45
+
46
+ The first argument can be:
47
+
48
+ * Your eventual commit message (in quotes), if you've chosen to allow Wielder
49
+ of Anor itself to run your commits for you. If you've chosen to *not* allow it
50
+ to run your commits for you, this argument will be ignored.
51
+ * 'help' - This will simply print out shorter versions of the options you are
52
+ currently reading.
53
+ * 'config' - This will re-run the configuration process. IF YOU SET ANY OF YOUR
54
+ FILE LOCATIONS TO POINT TO PREVIOUSLY EXISTING FILES, THOSE FILES *WILL* BE
55
+ OVERWRITTEN.
56
+ * 'words' - This will spit out all of the forbidden words that you currently
57
+ are checking for.
58
+
59
+ There is currently only one option for the second argument:
60
+
61
+ * The second argument can only be '1' and will be ignored unless there is a
62
+ commit message as the first argument. If this argument is passed, Wielder of
63
+ Anor will skip checking for any forbidden words whatsoever and jump straight
64
+ to the commit portion of the app. This is mainly here so that you can easily
65
+ force a commit after Wielder of Anor tells you of some forbidden words that
66
+ you've decided to allow for whatever reason. For instance, say 'puts' is one
67
+ of your forbidden words and there's a commented-out puts statement in your
68
+ code that you didn't put there and that, as such, you don't want to delete.
69
+ It's the only forbidden word showing up, so the rest of your code is clean.
70
+ So, instead of now having to type out a full git commit command, you can now
71
+ just hit your up arrow, hit the spacebar, type a '1' and hit enter.
72
+
73
+ Once run, Wielder of Anor will run a bash command that'll export the result of a
74
+ `git diff HEAD --staged --name-only` (so all files that you have 'git add'ed
75
+ since git HEAD) to a file. It'll then check every line in every one of those
76
+ files for any of your forbidden words and print out the locations of any and
77
+ every one it finds.
78
+
79
+ If it found none (or if you've skipped the search and are forcing a commit), you
80
+ are good to go and can tell the app to then run the git commit command, if
81
+ you've opted to allow it to do so. At this point, Wielder of Anor will run a
82
+ `git commit -m` followed by your commit message (your first argument when
83
+ running the app). Once it prints out "COMMITTED.", execution will end. Don't
84
+ forget to run your git push!
85
+
86
+ ## Wielder of Anor? Wut.
87
+ You know, the thing Gandalf calls himself to the Balrog as he's all "YOU SHALL
88
+ NOT PASS!" over and over? When he's, you know, preventing the Balrog from
89
+ getting past him? He...he prevents a *forbidden* thing from...
90
+
91
+ A gatekeeper. This app is a gatekeeper. Gandalf was a Gatekeeper that one
92
+ time. It's artistic. Or something.
93
+
94
+ ## License
95
+ The MIT License (MIT)
96
+
97
+ Copyright (c) 2016 Chris Sellek
98
+
99
+ Permission is hereby granted, free of charge, to any person obtaining a copy
100
+ of this software and associated documentation files (the "Software"), to deal
101
+ in the Software without restriction, including without limitation the rights
102
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
103
+ copies of the Software, and to permit persons to whom the Software is
104
+ furnished to do so, subject to the following conditions:
105
+
106
+ The above copyright notice and this permission notice shall be included in all
107
+ copies or substantial portions of the Software.
108
+
109
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
115
115
  SOFTWARE.
data/bin/wielder_of_anor CHANGED
@@ -1,17 +1,17 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'wielder_of_anor'
4
-
5
- woa = WielderOfAnor::WielderOfAnor.new
6
-
7
- woa.help if ARGV[0] == 'help'
8
-
9
- woa.first_run if ARGV[0] == 'config'
10
-
11
- woa.output_forbidden_words if ARGV[0] == 'words'
12
-
13
- woa.add_forbidden_word(ARGV[1]) if ARGV[0] == 'add'
14
-
15
- woa.prepare(ARGV[0], ARGV[1])
16
-
17
- woa.wielder_of_anor
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wielder_of_anor'
4
+
5
+ woa = WielderOfAnor::WielderOfAnor.new
6
+
7
+ woa.help if ARGV[0] == 'help'
8
+
9
+ woa.first_run if ARGV[0] == 'config'
10
+
11
+ woa.output_forbidden_words if ARGV[0] == 'words'
12
+
13
+ woa.add_forbidden_word(ARGV[1]) if ARGV[0] == 'add'
14
+
15
+ woa.prepare(ARGV[0], ARGV[1])
16
+
17
+ woa.wielder_of_anor
@@ -1,383 +1,389 @@
1
- require 'shellwords'
2
- require 'yaml'
3
- require 'rainbow'
4
- require 'fileutils'
5
-
6
- require_relative 'wielder_of_anor/version'
7
-
8
- module WielderOfAnor
9
- class WielderOfAnor
10
- include WielderOfAnorVersion
11
-
12
- def initialize
13
- set_app_directory
14
-
15
- @forbidden_words = []
16
- end
17
-
18
- ##############################################################################
19
- ##############################################################################
20
- ## ##
21
- ## commit_message is the git commit message the user would like to send ##
22
- ## once we have verified that there are no forbidden words present in their ##
23
- ## code. ##
24
- ## ##
25
- ## force_commit is either '1' or nil. If it's 1, we will commit later even ##
26
- ## if there are forbidden words present. ##
27
- ## ##
28
- ##############################################################################
29
- ##############################################################################
30
-
31
- def prepare(commit_message, force_commit)
32
- # If there's just one, it's the current version. Don't run if the current config is present.
33
- restore_settings if Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*").length > 1 &&
34
- !(File.exists?("#{@app_directory}/lib/config.yaml"))
35
- first_run unless File.exists?("#{@app_directory}/lib/config.yaml")
36
-
37
- config = YAML.load_file("#{@app_directory}/lib/config.yaml")
38
- @commit_message = commit_message
39
- @force_commit = force_commit
40
- @current_directory = Dir.pwd
41
- @files_changed_file_location = config['files_changed_file_location']
42
- @commit_for_user = config['commit_for_user']
43
-
44
- # Don't want to use a previous version.
45
- File.delete(@files_changed_file_location) if File.exists?(@files_changed_file_location)
46
-
47
- git_diff
48
-
49
- @files_changed_file = File.open(@files_changed_file_location, "r")
50
- @forbidden_words = config['forbidden_words']
51
- end
52
-
53
- def help
54
- lines_pretty_print 'Wielder of Anor can accept up to two parameters on run. The first parameter can be:'
55
-
56
- single_space
57
-
58
- lines_pretty_print '- Your eventual commit message (in quotes). This is ignored if you have not allowed '\
59
- 'Wielder of Anor to commit for you.'
60
- lines_pretty_print '- help - You should already know what this does :).'
61
- lines_pretty_print '- config - Re-runs the initial set up.'
62
-
63
- single_space
64
-
65
- lines_pretty_print 'And your second parameter can only be \'1\', and it\'ll be ignored unless all of the '\
66
- 'following is true:'
67
-
68
- single_space
69
-
70
- lines_pretty_print '- You have allowed Wielder of Anor to run commits for you.'
71
- lines_pretty_print '- Your first parameter is your commit message.'
72
-
73
- abort
74
- end
75
-
76
- def output_forbidden_words
77
- set_app_directory
78
- config = YAML.load_file("#{@app_directory}/lib/config.yaml")
79
-
80
- unless config && config['forbidden_words']
81
- lines_pretty_print Rainbow('You have yet to set your forbidden words! Please run the app with the parameter '\
82
- '\'config\' to set up your configurations and forbidden words.').red
83
-
84
- abort
85
- end
86
-
87
- lines_pretty_print Rainbow('Your forbidden words are:').yellow
88
-
89
- single_space
90
-
91
- config['forbidden_words'].each do |word|
92
- lines_pretty_print Rainbow(word).yellow
93
- end
94
-
95
- single_space
96
-
97
- abort
98
- end
99
-
100
- # Attempt to restore settings from previous version.
101
- def restore_settings
102
- lines_pretty_print 'I see that you have a previous wielder_of_anor installation on this machine.'
103
- lines_pretty_print Rainbow('Would you like to restore its settings?').yellow
104
-
105
- answered = false
106
-
107
- until answered
108
- answer = STDIN.gets.strip!
109
-
110
- single_space
111
-
112
- if answer == 'yes' || answer == 'y' || answer == 'no' || answer == 'n'
113
- answered = true
114
- else
115
- lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow
116
- end
117
- end
118
-
119
- return if answer == 'no' || answer == 'n'
120
-
121
- lines_pretty_print 'One moment, please.'
122
-
123
- single_space
124
-
125
- all_gems = Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*")
126
-
127
- # glob orders things in the array alphabetically, so the second-to-last one in the array is the
128
- # most recent version that is not the current version.
129
- previous_config_file = "#{all_gems[-2]}/lib/config.yaml"
130
- FileUtils.copy_file(previous_config_file, "#{@app_directory}/lib/config.yaml")
131
-
132
- lines_pretty_print 'Done! Please run me again when you\'re ready.'
133
-
134
- abort
135
- end
136
-
137
- def first_run
138
- lines_pretty_print 'Thanks for downloading Wielder of Anor! Let\'s run through the '\
139
- 'initial setup!'
140
-
141
- STDIN.gets
142
-
143
- files_changed_file_location = "#{@app_directory}/lib/files_changed"
144
-
145
- commit_for_user = set_commit_for_user
146
-
147
- single_space
148
-
149
- forbidden_words = set_forbidden_words
150
-
151
- set_configs(files_changed_file_location, forbidden_words, commit_for_user)
152
- end
153
-
154
- def set_commit_for_user
155
- lines_pretty_print 'Would you like Wielder of Anor to run your commits for you once you'\
156
- ' have verified that your code is free of forbidden words?'
157
- lines_pretty_print Rainbow('(Type \'yes\' or \'no\'. Just hitting enter defaults to no.)').yellow
158
-
159
- commit_for_user = STDIN.gets.strip!.downcase
160
- commit_for_user = 'no' if commit_for_user == ''
161
-
162
- until commit_for_user == 'yes' || commit_for_user =='y' || commit_for_user == 'no' || commit_for_user == 'n' do
163
- lines_pretty_print Rainbow('Please type either \'yes\' or \'no\'.').yellow
164
- commit_for_user = STDIN.gets.strip!.downcase
165
- end
166
-
167
- commit_for_user
168
- end
169
-
170
- def set_configs(files_changed_file_location, forbidden_words, commit_for_user)
171
- config = {}
172
- config['files_changed_file_location'] = files_changed_file_location
173
-
174
- if commit_for_user == 'yes' || commit_for_user == 'y'
175
- config['commit_for_user'] = true
176
- else
177
- config['commit_for_user'] = false
178
- end
179
-
180
- config['forbidden_words'] = forbidden_words
181
-
182
- file = File.open("#{@app_directory}/lib/config.yaml", 'w')
183
- YAML.dump(config, file)
184
- file.close
185
-
186
- lines_pretty_print 'And with that, we\'re done! Feel free to run Wielder of Anor again if'\
187
- ' you\'d like to check your code now!'
188
-
189
- abort
190
- end
191
-
192
- def set_forbidden_words
193
- forbidden_words = []
194
-
195
- done = false
196
-
197
- lines_pretty_print 'Great! Now that we\'re done with the files, let\'s add your forbidden '\
198
- 'words from here!'
199
- single_space
200
-
201
- until done do
202
- lines_pretty_print Rainbow('Enter a forbidden word and hit enter. If you are done entering '\
203
- 'forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count > 0
204
-
205
- lines_pretty_print Rainbow('Added! Enter another forbidden word and hit enter. If you are done '\
206
- 'entering forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count == 0
207
- word = STDIN.gets.strip!
208
-
209
- single_space
210
-
211
- if word == 'x211'
212
- done = true
213
- else
214
- forbidden_words << word
215
- end
216
- end
217
-
218
- forbidden_words
219
- end
220
-
221
- def git_diff
222
- bash("git diff HEAD --name-only --staged > #{@files_changed_file_location}")
223
- end
224
-
225
- def add_forbidden_word(word)
226
- set_app_directory
227
- config_yaml = YAML.load_file("#{@app_directory}/lib/config.yaml")
228
- config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
229
-
230
- if word.nil?
231
- lines_pretty_print Rainbow('Please submit your word as a second parameter.').red
232
-
233
- abort
234
- end
235
-
236
- if config_yaml['forbidden_words'].include?(word)
237
- lines_pretty_print Rainbow("''#{word}'' is already a forbidden word!").red
238
-
239
- abort
240
- end
241
-
242
- config_yaml['forbidden_words'] << word
243
-
244
- YAML.dump(config_yaml, config_file)
245
-
246
- lines_pretty_print 'Added!'
247
-
248
- abort
249
- end
250
-
251
- def wielder_of_anor
252
- found_forbidden = false
253
- count = File.foreach(@files_changed_file).inject(0) {|c, line| c+1}
254
-
255
- if count == 0
256
- single_space
257
-
258
- lines_pretty_print Rainbow('No files have been added. Please use the git add command to add files to your '\
259
- 'commit.').red
260
-
261
- single_space
262
-
263
- abort
264
- end
265
-
266
- # If we're forcing the commit, don't bother checking for forbidden words.
267
- unless @force_commit
268
- single_space
269
-
270
- print_header_footer
271
-
272
- single_space
273
-
274
- @files_changed_file.each_line do |files_changed_line|
275
- code_file = File.open("#{@current_directory}/#{files_changed_line.strip}", "r")
276
- index = 0
277
-
278
- code_file.each_line do |line|
279
- index += 1
280
- @forbidden_words.each do |word|
281
- if line.include?(word)
282
- found_forbidden = true
283
- lines_pretty_print Rainbow("-- FORBIDDEN WORD FOUND ON LINE #{index} IN #{files_changed_line.strip}: --").red
284
- lines_pretty_print Rainbow(" #{line}").yellow
285
- double_space
286
- end
287
- end
288
- end
289
-
290
- code_file.close
291
- end
292
-
293
- single_space
294
-
295
- print_header_footer
296
-
297
- single_space
298
- else
299
- lines_pretty_print Rainbow('NOT SEARCHING FOR FORBIDDEN WORDS, PER USER INPUT.').red
300
- single_space
301
- end
302
-
303
- @files_changed_file.close
304
-
305
- results(found_forbidden)
306
- end
307
-
308
- def results(found_forbidden)
309
- if found_forbidden
310
- single_space
311
- lines_pretty_print 'Remove offending line(s) and re-run commit statement or run this '\
312
- 'app again with \'1\' as your second argument to force the commit.'
313
-
314
- single_space
315
- lines_pretty_print Rainbow('**ONLY FORCE THE COMMIT IF YOU ARE SURE YOU ARE 100% SURE YOU WANT '\
316
- 'TO COMMIT THE ABOVE LINES TO YOUR BRANCH!!**').red
317
- File.delete(@files_changed_file)
318
- abort
319
- else
320
- unless @force_commit
321
- lines_pretty_print Rainbow('Found 0 forbidden words!').green
322
-
323
- single_space
324
- end
325
-
326
- File.delete(@files_changed_file)
327
- commit if @commit_for_user
328
- end
329
- end
330
-
331
- def print_header_footer
332
- puts '***************************************************************************'
333
- end
334
-
335
- def commit
336
- if @force_commit
337
- lines_pretty_print 'Skipped checking for forbidden words. Ready to commit now?'
338
- lines_pretty_print Rainbow('**WARNING: YOU ARE FORCING THE COMMIT WITHOUT CHECKING FOR FORBIDDEN WORDS.**').red
339
-
340
- single_space
341
- else
342
- lines_pretty_print 'Okay to commit! Should I go ahead and run the actual commit now?'
343
- end
344
-
345
- lines_pretty_print 'Please type \'yes\' OR \'y\' to continue. Any other input will be treated as a \'no\'.'
346
-
347
- input = STDIN.gets.chomp.downcase
348
-
349
- single_space
350
-
351
- if input == 'yes' || input == 'y'
352
- bash(%Q[git commit -m "#{@commit_message}"])
353
- single_space
354
- lines_pretty_print 'Committed.'
355
- single_space
356
- end
357
- end
358
-
359
- def bash(command)
360
- # Dir.chdir ensures all bash commands are being run from the correct
361
- # directory.
362
- Dir.chdir(@current_directory) { system "#{command}" }
363
- end
364
-
365
- def set_app_directory
366
- @app_directory = File.expand_path(File.dirname(__FILE__)).chomp('/lib')
367
- end
368
-
369
- def lines_pretty_print(string)
370
- lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/)
371
-
372
- lines.each { |line| puts line }
373
- end
374
-
375
- def single_space
376
- puts ''
377
- end
378
-
379
- def double_space
380
- puts "\n\n"
381
- end
382
- end
1
+ require 'shellwords'
2
+ require 'yaml'
3
+ require 'rainbow'
4
+ require 'fileutils'
5
+
6
+ require_relative 'wielder_of_anor/version'
7
+
8
+ module WielderOfAnor
9
+ class WielderOfAnor
10
+ include WielderOfAnorVersion
11
+
12
+ def initialize
13
+ set_app_directory
14
+
15
+ @forbidden_words = []
16
+ end
17
+
18
+ ##############################################################################
19
+ ##############################################################################
20
+ ## ##
21
+ ## commit_message is the git commit message the user would like to send ##
22
+ ## once we have verified that there are no forbidden words present in their ##
23
+ ## code. ##
24
+ ## ##
25
+ ## force_commit is either '1' or nil. If it's 1, we will commit later even ##
26
+ ## if there are forbidden words present. ##
27
+ ## ##
28
+ ##############################################################################
29
+ ##############################################################################
30
+
31
+ def prepare(commit_message, force_commit)
32
+ # If there's just one, it's the current version. Don't run if the current config is present.
33
+ restore_settings if Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*").length > 1 &&
34
+ !(File.exists?("#{@app_directory}/lib/config.yaml"))
35
+ first_run unless File.exists?("#{@app_directory}/lib/config.yaml")
36
+
37
+ config = YAML.load_file("#{@app_directory}/lib/config.yaml")
38
+ @commit_message = commit_message
39
+ @force_commit = force_commit
40
+ @current_directory = Dir.pwd
41
+ @files_changed_file_location = config['files_changed_file_location']
42
+ @commit_for_user = config['commit_for_user']
43
+
44
+ # Don't want to use a previous version.
45
+ File.delete(@files_changed_file_location) if File.exists?(@files_changed_file_location)
46
+
47
+ git_diff
48
+
49
+ @files_changed_file = File.open(@files_changed_file_location, "r")
50
+ @forbidden_words = config['forbidden_words']
51
+ end
52
+
53
+ def help
54
+ lines_pretty_print 'Wielder of Anor can accept up to two parameters on run. The first parameter can be:'
55
+
56
+ single_space
57
+
58
+ lines_pretty_print '- Your eventual commit message (in quotes). This is ignored if you have not allowed '\
59
+ 'Wielder of Anor to commit for you.'
60
+ lines_pretty_print '- help - You should already know what this does :).'
61
+ lines_pretty_print '- config - Re-runs the initial set up.'
62
+
63
+ single_space
64
+
65
+ lines_pretty_print 'And your second parameter can only be \'1\', and it\'ll be ignored unless all of the '\
66
+ 'following is true:'
67
+
68
+ single_space
69
+
70
+ lines_pretty_print '- You have allowed Wielder of Anor to run commits for you.'
71
+ lines_pretty_print '- Your first parameter is your commit message.'
72
+
73
+ abort
74
+ end
75
+
76
+ def output_forbidden_words
77
+ set_app_directory
78
+ config = YAML.load_file("#{@app_directory}/lib/config.yaml")
79
+
80
+ unless config && config['forbidden_words']
81
+ lines_pretty_print Rainbow('You have yet to set your forbidden words! Please run the app with the parameter '\
82
+ '\'config\' to set up your configurations and forbidden words.').red
83
+
84
+ abort
85
+ end
86
+
87
+ lines_pretty_print Rainbow('Your forbidden words are:').yellow
88
+
89
+ single_space
90
+
91
+ config['forbidden_words'].each do |word|
92
+ lines_pretty_print Rainbow(word).yellow
93
+ end
94
+
95
+ single_space
96
+
97
+ abort
98
+ end
99
+
100
+ # Attempt to restore settings from previous version.
101
+ def restore_settings
102
+ lines_pretty_print 'I see that you have a previous wielder_of_anor installation on this machine.'
103
+ lines_pretty_print Rainbow('Would you like to restore its settings?').yellow
104
+
105
+ answered = false
106
+
107
+ until answered
108
+ answer = STDIN.gets.strip!
109
+
110
+ single_space
111
+
112
+ if answer == 'yes' || answer == 'y' || answer == 'no' || answer == 'n'
113
+ answered = true
114
+ else
115
+ lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow
116
+ end
117
+ end
118
+
119
+ return if answer == 'no' || answer == 'n'
120
+
121
+ lines_pretty_print 'One moment, please.'
122
+
123
+ single_space
124
+
125
+ all_gems = Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*")
126
+
127
+ # glob orders things in the array alphabetically, so the second-to-last one in the array is the
128
+ # most recent version that is not the current version.
129
+ previous_config_file = "#{all_gems[-2]}/lib/config.yaml"
130
+ config = YAML.load_file(previous_config_file)
131
+ new_config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
132
+
133
+ YAML.dump(config, new_config_file)
134
+ new_config_file.close
135
+
136
+ lines_pretty_print 'Done! Please run me again when you\'re ready.'
137
+
138
+ abort
139
+ end
140
+
141
+ def first_run
142
+ lines_pretty_print 'Thanks for downloading Wielder of Anor! Let\'s run through the '\
143
+ 'initial setup!'
144
+
145
+ STDIN.gets
146
+
147
+ files_changed_file_location = "#{@app_directory}/lib/files_changed"
148
+
149
+ commit_for_user = set_commit_for_user
150
+
151
+ single_space
152
+
153
+ forbidden_words = set_forbidden_words
154
+
155
+ set_configs(files_changed_file_location, forbidden_words, commit_for_user)
156
+ end
157
+
158
+ def set_commit_for_user
159
+ lines_pretty_print 'Would you like Wielder of Anor to run your commits for you once you'\
160
+ ' have verified that your code is free of forbidden words?'
161
+ lines_pretty_print Rainbow('(Type \'yes\' or \'no\'. Just hitting enter defaults to no.)').yellow
162
+
163
+ commit_for_user = STDIN.gets.strip!.downcase
164
+ commit_for_user = 'no' if commit_for_user == ''
165
+
166
+ until commit_for_user == 'yes' || commit_for_user =='y' || commit_for_user == 'no' || commit_for_user == 'n' do
167
+ lines_pretty_print Rainbow('Please type either \'yes\' or \'no\'.').yellow
168
+ commit_for_user = STDIN.gets.strip!.downcase
169
+ end
170
+
171
+ commit_for_user
172
+ end
173
+
174
+ def set_configs(files_changed_file_location, forbidden_words, commit_for_user)
175
+ config = {}
176
+ config['files_changed_file_location'] = files_changed_file_location
177
+
178
+ if commit_for_user == 'yes' || commit_for_user == 'y'
179
+ config['commit_for_user'] = true
180
+ else
181
+ config['commit_for_user'] = false
182
+ end
183
+
184
+ config['forbidden_words'] = forbidden_words
185
+
186
+ file = File.open("#{@app_directory}/lib/config.yaml", 'w')
187
+ YAML.dump(config, file)
188
+ file.close
189
+
190
+ lines_pretty_print 'And with that, we\'re done! Feel free to run Wielder of Anor again if'\
191
+ ' you\'d like to check your code now!'
192
+
193
+ abort
194
+ end
195
+
196
+ def set_forbidden_words
197
+ forbidden_words = []
198
+
199
+ done = false
200
+
201
+ lines_pretty_print 'Great! Now that we\'re done with the files, let\'s add your forbidden '\
202
+ 'words from here!'
203
+ single_space
204
+
205
+ until done do
206
+ lines_pretty_print Rainbow('Enter a forbidden word and hit enter. If you are done entering '\
207
+ 'forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count > 0
208
+
209
+ lines_pretty_print Rainbow('Added! Enter another forbidden word and hit enter. If you are done '\
210
+ 'entering forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count == 0
211
+ word = STDIN.gets.strip!
212
+
213
+ single_space
214
+
215
+ if word == 'x211'
216
+ done = true
217
+ else
218
+ forbidden_words << word
219
+ end
220
+ end
221
+
222
+ forbidden_words
223
+ end
224
+
225
+ def git_diff
226
+ bash("git diff HEAD --name-only --staged > #{@files_changed_file_location}")
227
+ end
228
+
229
+ def add_forbidden_word(word)
230
+ set_app_directory
231
+ config_yaml = YAML.load_file("#{@app_directory}/lib/config.yaml")
232
+ config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
233
+
234
+ if word.nil?
235
+ lines_pretty_print Rainbow('Please submit your word as a second parameter.').red
236
+
237
+ abort
238
+ end
239
+
240
+ if config_yaml['forbidden_words'].include?(word)
241
+ lines_pretty_print Rainbow("''#{word}'' is already a forbidden word!").red
242
+
243
+ abort
244
+ end
245
+
246
+ config_yaml['forbidden_words'] << word
247
+
248
+ YAML.dump(config_yaml, config_file)
249
+
250
+ lines_pretty_print 'Added!'
251
+
252
+ abort
253
+ end
254
+
255
+ def wielder_of_anor
256
+ found_forbidden = false
257
+ count = File.foreach(@files_changed_file).inject(0) {|c, line| c+1}
258
+
259
+ if count == 0
260
+ single_space
261
+
262
+ lines_pretty_print Rainbow('No files have been added. Please use the git add command to add files to your '\
263
+ 'commit.').red
264
+
265
+ single_space
266
+
267
+ abort
268
+ end
269
+
270
+ # If we're forcing the commit, don't bother checking for forbidden words.
271
+ unless @force_commit
272
+ single_space
273
+
274
+ print_header_footer
275
+
276
+ single_space
277
+
278
+ @files_changed_file.each_line do |files_changed_line|
279
+ file_path = "#{@current_directory}/#{files_changed_line.strip}"
280
+ code_file = File.open(file_path, "r") if File.exists?(file_path)
281
+ index = 0
282
+ next unless code_file
283
+
284
+ code_file.each_line do |line|
285
+ index += 1
286
+ @forbidden_words.each do |word|
287
+ if line.include?(word)
288
+ found_forbidden = true
289
+ lines_pretty_print Rainbow("-- FORBIDDEN WORD FOUND ON LINE #{index} IN #{files_changed_line.strip}: --").red
290
+ lines_pretty_print Rainbow(" #{line}").yellow
291
+ double_space
292
+ end
293
+ end
294
+ end
295
+
296
+ code_file.close
297
+ end
298
+
299
+ single_space
300
+
301
+ print_header_footer
302
+
303
+ single_space
304
+ else
305
+ lines_pretty_print Rainbow('NOT SEARCHING FOR FORBIDDEN WORDS, PER USER INPUT.').red
306
+ single_space
307
+ end
308
+
309
+ @files_changed_file.close
310
+
311
+ results(found_forbidden)
312
+ end
313
+
314
+ def results(found_forbidden)
315
+ if found_forbidden
316
+ single_space
317
+ lines_pretty_print 'Remove offending line(s) and re-run commit statement or run this '\
318
+ 'app again with \'1\' as your second argument to force the commit.'
319
+
320
+ single_space
321
+ lines_pretty_print Rainbow('**ONLY FORCE THE COMMIT IF YOU ARE SURE YOU ARE 100% SURE YOU WANT '\
322
+ 'TO COMMIT THE ABOVE LINES TO YOUR BRANCH!!**').red
323
+ File.delete(@files_changed_file)
324
+ abort
325
+ else
326
+ unless @force_commit
327
+ lines_pretty_print Rainbow('Found 0 forbidden words!').green
328
+
329
+ single_space
330
+ end
331
+
332
+ File.delete(@files_changed_file)
333
+ commit if @commit_for_user
334
+ end
335
+ end
336
+
337
+ def print_header_footer
338
+ puts '***************************************************************************'
339
+ end
340
+
341
+ def commit
342
+ if @force_commit
343
+ lines_pretty_print 'Skipped checking for forbidden words. Ready to commit now?'
344
+ lines_pretty_print Rainbow('**WARNING: YOU ARE FORCING THE COMMIT WITHOUT CHECKING FOR FORBIDDEN WORDS.**').red
345
+
346
+ single_space
347
+ else
348
+ lines_pretty_print 'Okay to commit! Should I go ahead and run the actual commit now?'
349
+ end
350
+
351
+ lines_pretty_print 'Please type \'yes\' OR \'y\' to continue. Any other input will be treated as a \'no\'.'
352
+
353
+ input = STDIN.gets.chomp.downcase
354
+
355
+ single_space
356
+
357
+ if input == 'yes' || input == 'y'
358
+ bash(%Q[git commit -m "#{@commit_message}"])
359
+ single_space
360
+ lines_pretty_print 'Committed.'
361
+ single_space
362
+ end
363
+ end
364
+
365
+ def bash(command)
366
+ # Dir.chdir ensures all bash commands are being run from the correct
367
+ # directory.
368
+ Dir.chdir(@current_directory) { system "#{command}" }
369
+ end
370
+
371
+ def set_app_directory
372
+ @app_directory = File.expand_path(File.dirname(__FILE__)).chomp('/lib')
373
+ end
374
+
375
+ def lines_pretty_print(string)
376
+ lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/)
377
+
378
+ lines.each { |line| puts line }
379
+ end
380
+
381
+ def single_space
382
+ puts ''
383
+ end
384
+
385
+ def double_space
386
+ puts "\n\n"
387
+ end
388
+ end
383
389
  end
@@ -1,3 +1,3 @@
1
- module WielderOfAnorVersion
2
- VERSION = "0.3.2"
1
+ module WielderOfAnorVersion
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'wielder_of_anor/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'wielder_of_anor'
8
- spec.version = WielderOfAnorVersion::VERSION
9
- spec.authors = ['Chris Sellek']
10
- spec.email = ['iamsellek@gmail.com']
11
-
12
- spec.summary = 'Checks a user\'s staged files for \'forbidden\' words (as determined by the user) '\
13
- 'and, if any are found, alerts the user to the locations of said words.'
14
- spec.description = 'See GitHub page for longer description.'
15
- spec.homepage = 'https://github.com/iamsellek/wielder_of_anor'
16
- spec.license = 'MIT'
17
-
18
- spec.files = `git ls-files`.split($/)
19
- spec.executables = ['wielder_of_anor']
20
- spec.test_files = []
21
- spec.require_paths = ['lib']
22
-
23
- spec.add_dependency 'rainbow'
24
-
25
- spec.add_development_dependency 'bundler', '~> 1.12'
26
- spec.add_development_dependency 'rake', '~> 10.0'
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wielder_of_anor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wielder_of_anor'
8
+ spec.version = WielderOfAnorVersion::VERSION
9
+ spec.authors = ['Chris Sellek']
10
+ spec.email = ['iamsellek@gmail.com']
11
+
12
+ spec.summary = 'Checks a user\'s staged files for \'forbidden\' words (as determined by the user) '\
13
+ 'and, if any are found, alerts the user to the locations of said words.'
14
+ spec.description = 'See GitHub page for longer description.'
15
+ spec.homepage = 'https://github.com/iamsellek/wielder_of_anor'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = ['wielder_of_anor']
20
+ spec.test_files = []
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'rainbow'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wielder_of_anor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sellek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.0.14.1
94
+ rubygems_version: 2.5.2
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Checks a user's staged files for 'forbidden' words (as determined by the