hscode 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ require 'hscode/pretty_print'
2
+
3
+ module Hscode
4
+ class InputParser
5
+ attr_reader :options
6
+
7
+ def initialize
8
+ @options = OpenStruct.new
9
+ end
10
+
11
+ def parse(args)
12
+ option_parser.parse!(args)
13
+ options
14
+ rescue OptionParser::InvalidOption,
15
+ OptionParser::InvalidArgument,
16
+ OptionParser::MissingArgument => e
17
+ puts e, "See 'hscode --help'."
18
+ exit 1
19
+ end
20
+
21
+ private
22
+
23
+ def option_parser
24
+ OptionParser.new do |opts|
25
+ opts.banner = 'Usage: hscode [options]'
26
+ opts.separator ''
27
+ opts.separator 'Specific options:'
28
+
29
+ run_verbosely(opts)
30
+ show_status_code(opts)
31
+ list_status_codes(opts)
32
+
33
+ opts.separator ''
34
+
35
+ display_help_message(opts)
36
+ display_version_number(opts)
37
+ end
38
+ end
39
+
40
+ def show_status_code(opts)
41
+ opts.on('-c', '--code CODE', Integer,
42
+ 'Show HTTP status code documentation') do |code|
43
+ options.status_code = code
44
+ end
45
+ end
46
+
47
+ def run_verbosely(opts)
48
+ opts.on('-v', '--verbose',
49
+ 'Show full HTTP status code documentation') do |v|
50
+ options.verbose = v
51
+ end
52
+ end
53
+
54
+ def list_status_codes(opts)
55
+ opts.on('-l', '--list', 'List all HTTP status codes') do
56
+ print_all_codes
57
+ end
58
+ end
59
+
60
+ def display_help_message(opts)
61
+ opts.on_tail('-h', '--help', 'Show this help message') do
62
+ puts opts, 'Examples:
63
+ hscode -c 200
64
+ hscode -c 200 -v
65
+ hscode -l
66
+ '
67
+ exit
68
+ end
69
+ end
70
+
71
+ def display_version_number(opts)
72
+ opts.on_tail('--version', 'Show version') do
73
+ puts Hscode::VERSION
74
+ exit
75
+ end
76
+ end
77
+
78
+ def print_all_codes
79
+ HTTP_STATUS_CODES.map do |code, info_hash|
80
+ colour_code = code.to_s[0]
81
+ PrettyPrint.print("#{code} - #{info_hash[:title]}", colour_code)
82
+ end
83
+ exit
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,22 @@
1
+ module Hscode
2
+ class PrettyPrint
3
+ COLORS = {
4
+ '0' => 255,
5
+ '1' => 6,
6
+ '2' => 2,
7
+ '3' => 3,
8
+ '4' => 9,
9
+ '5' => 1
10
+ }.freeze
11
+
12
+ def self.print(text, colour_code)
13
+ puts make_pretty(text, COLORS[colour_code])
14
+ end
15
+
16
+ private_class_method
17
+
18
+ def self.make_pretty(text, color_code)
19
+ "\x1b[38;5;#{color_code}m#{text}\n"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Hscode
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/hscode.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'hscode/version'
2
+ require 'hscode/input_parser'
3
+ require 'hscode/http_status_codes'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+
7
+ module Hscode
8
+ class CliController
9
+ def self.call(args)
10
+ options = Hscode::InputParser.new.parse(args)
11
+ print_code(options)
12
+ end
13
+
14
+ private_class_method
15
+
16
+ def self.print_code(options)
17
+ status_code = HTTP_STATUS_CODES[options.status_code.to_i]
18
+
19
+ unless status_code
20
+ puts "#{options.status_code} is not a valid code. See 'hscode --help'."
21
+ exit
22
+ end
23
+
24
+ PrettyPrint.print(
25
+ "#{options.status_code} - #{status_code[:title]}",
26
+ options.status_code.to_s[0]
27
+ )
28
+ print_description(status_code) if options.verbose
29
+ end
30
+
31
+ def self.print_description(status_code)
32
+ status_code[:description].each do |desc|
33
+ PrettyPrint.print("\n#{desc}", '0')
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,234 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hscode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Herbert Kagumba
8
+ - Austin Kabiru
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-11-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.12'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.12'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.14'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.14'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: coveralls
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.8'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.8'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.12'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.12'
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard-rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '4.7'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '4.7'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.9'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.9'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.42'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.42'
154
+ - !ruby/object:Gem::Dependency
155
+ name: brakeman
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.3'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.3'
168
+ - !ruby/object:Gem::Dependency
169
+ name: rubycritic
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '2.9'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '2.9'
182
+ description: Quickly look up any status code without leaving your terminal.
183
+ email:
184
+ - makabby@gmail.com
185
+ executables:
186
+ - hscode
187
+ extensions: []
188
+ extra_rdoc_files: []
189
+ files:
190
+ - ".gitignore"
191
+ - ".rspec"
192
+ - ".rubocop.yml"
193
+ - ".travis.yml"
194
+ - CODE_OF_CONDUCT.md
195
+ - Gemfile
196
+ - Guardfile
197
+ - LICENSE.txt
198
+ - README.md
199
+ - Rakefile
200
+ - bin/console
201
+ - bin/hscode
202
+ - bin/setup
203
+ - config/bootstrap.rb
204
+ - hscode.gemspec
205
+ - lib/hscode.rb
206
+ - lib/hscode/http_status_codes.rb
207
+ - lib/hscode/input_parser.rb
208
+ - lib/hscode/pretty_print.rb
209
+ - lib/hscode/version.rb
210
+ homepage: https://github.com/akabiru/hscode
211
+ licenses:
212
+ - MIT
213
+ metadata: {}
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.5.1
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: A HTTP status code lookup command line tool.
234
+ test_files: []