cli_helper 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +222 -11
- data/cli_helper.gemspec +17 -14
- data/example/cli_stub.rb +64 -11
- data/lib/cli_helper.rb +251 -277
- data/tests/README.txt +18 -0
- data/tests/cli_helper_test.rb +217 -0
- data/tests/config/sample.ini +6 -0
- data/tests/config/sample.ini.erb +9 -0
- data/tests/config/sample.rb +15 -0
- data/tests/config/sample.rb.erb +20 -0
- data/tests/config/sample.txt +12 -0
- data/tests/config/sample.txt.erb +16 -0
- data/tests/config/sample.xyzzy +1 -0
- data/tests/config/sample.yml +16 -0
- data/tests/config/sample.yml.erb +17 -0
- metadata +61 -23
@@ -0,0 +1,217 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
################################################
|
3
|
+
## Here is how it works
|
4
|
+
|
5
|
+
require_relative '../lib/cli_helper'
|
6
|
+
include CliHelper
|
7
|
+
|
8
|
+
|
9
|
+
# can not use minitest because it requires pry which
|
10
|
+
# requires an older version of slop
|
11
|
+
#require 'minitest/autorun'
|
12
|
+
require 'kick_the_tires'
|
13
|
+
include KickTheTires
|
14
|
+
|
15
|
+
require 'debug_me'
|
16
|
+
include DebugMe
|
17
|
+
|
18
|
+
|
19
|
+
configatron.support_config_files = true
|
20
|
+
|
21
|
+
#describe 'how it works' do
|
22
|
+
|
23
|
+
#it '000 supports basic common parameters' do
|
24
|
+
params = cli_helper
|
25
|
+
assert params.is_a? Slop::Options
|
26
|
+
assert usage.include?('--help')
|
27
|
+
assert usage.include?('--debug')
|
28
|
+
assert usage.include?('--verbose')
|
29
|
+
assert usage.include?('--version')
|
30
|
+
refute usage.include?('--xyzzy')
|
31
|
+
|
32
|
+
if configatron.support_config_files
|
33
|
+
assert usage.include?('--config')
|
34
|
+
else
|
35
|
+
refute usage.include?('--config')
|
36
|
+
end
|
37
|
+
|
38
|
+
#end
|
39
|
+
|
40
|
+
=begin
|
41
|
+
# NOTE: The Test construct creates a dynamic class which
|
42
|
+
# does not incorporate 'define_method' This Test results
|
43
|
+
# in errors that are a consequence of the testing framework
|
44
|
+
# not the object under test.
|
45
|
+
it '002 creates accessor methods to boolean options' do
|
46
|
+
cli_helper
|
47
|
+
all_methods = methods
|
48
|
+
%w[ help? debug? verbose? version?
|
49
|
+
help! debug! verbose! version!].each do |m|
|
50
|
+
assert all_methods.include?(m)
|
51
|
+
end
|
52
|
+
refute all_methods.include?('xyzzy?')
|
53
|
+
refute all_methods.include?('xyzzy!')
|
54
|
+
end
|
55
|
+
=end
|
56
|
+
|
57
|
+
#it '005 block inclusion' do
|
58
|
+
cli_helper do |param|
|
59
|
+
param.string '-x', '--xyxxy', 'example MAGIC parameter', default: 'IamDefault'
|
60
|
+
end
|
61
|
+
assert usage.include?('MAGIC')
|
62
|
+
#end
|
63
|
+
|
64
|
+
#it '010 supports banner' do
|
65
|
+
refute usage().include?('BANNER')
|
66
|
+
cli_helper('This is my BANNER')
|
67
|
+
assert usage().include?('BANNER')
|
68
|
+
#end
|
69
|
+
|
70
|
+
#it '015 supports additional help in usage' do
|
71
|
+
refute usage.include?('HELP')
|
72
|
+
HELP = "Do you need some HELP?"
|
73
|
+
assert usage.include?('HELP')
|
74
|
+
#end
|
75
|
+
|
76
|
+
#it '020 put it all together' do
|
77
|
+
cli_helper('This is my BANNER') do |o|
|
78
|
+
o.string '-x', '--xyxxy', 'example MAGIC parameter', default: 'IamDefault'
|
79
|
+
end
|
80
|
+
HELP = "Do you need some HELP?"
|
81
|
+
assert usage.include?('BANNER')
|
82
|
+
assert usage.include?('MAGIC')
|
83
|
+
assert usage.include?('HELP')
|
84
|
+
#end
|
85
|
+
|
86
|
+
#it '025 Add to options.errors' do
|
87
|
+
assert configatron.errors.empty?
|
88
|
+
a_message = 'There is a serious problem here'
|
89
|
+
error a_message
|
90
|
+
refute configatron.errors.empty?
|
91
|
+
assert_equal 1, configatron.errors.size
|
92
|
+
assert_equal a_message, configatron.errors.first
|
93
|
+
#end
|
94
|
+
|
95
|
+
#it '030 Add to options.warnings' do
|
96
|
+
assert configatron.warnings.empty?
|
97
|
+
a_message = 'There is a minor problem here'
|
98
|
+
warning a_message
|
99
|
+
refute configatron.warnings.empty?
|
100
|
+
assert_equal 1, configatron.warnings.size
|
101
|
+
assert_equal a_message, configatron.warnings.first
|
102
|
+
#end
|
103
|
+
|
104
|
+
#it '035 Add to options.errors' do
|
105
|
+
refute configatron.errors.empty?
|
106
|
+
a_message = 'There is another serious problem here'
|
107
|
+
error a_message
|
108
|
+
assert_equal 2, configatron.errors.size
|
109
|
+
assert_equal a_message, configatron.errors.last
|
110
|
+
#end
|
111
|
+
|
112
|
+
#it '040 Add to options.warnings' do
|
113
|
+
refute configatron.warnings.empty?
|
114
|
+
a_message = 'There is a another minor problem here'
|
115
|
+
warning a_message
|
116
|
+
assert_equal 2, configatron.warnings.size
|
117
|
+
assert_equal a_message, configatron.warnings.last
|
118
|
+
#end
|
119
|
+
|
120
|
+
#it '050 support erb config files' do
|
121
|
+
unless configatron.config.nil?
|
122
|
+
configatron.config.each do |c|
|
123
|
+
case c.basename.extname.to_s.downcase
|
124
|
+
when '.erb'
|
125
|
+
file_type = c.basename.to_s.downcase.gsub('.erb','').split('.').last
|
126
|
+
case file_type
|
127
|
+
when 'ini'
|
128
|
+
# FIXME: ParseConfig gem has problem
|
129
|
+
refute Time == configatron.wall_clock.the_mouse_says.class
|
130
|
+
when 'txt'
|
131
|
+
# FIXME: ParseConfig gem has problem
|
132
|
+
refute Time == configatron.wrist.watch_time.class
|
133
|
+
when 'yml'
|
134
|
+
assert_equal Time, configatron.production.watch_time.class
|
135
|
+
else
|
136
|
+
end
|
137
|
+
when '.rb'
|
138
|
+
assert_equal 'devhost', configatron.development.host
|
139
|
+
when '.txt'
|
140
|
+
assert_equal 6, configatron.fingers.right_hand
|
141
|
+
when '.ini'
|
142
|
+
assert_equal 'wedding ring', configatron.hands.left_hand
|
143
|
+
when '.yml'
|
144
|
+
assert_equal 'go fish', configatron.production.threes
|
145
|
+
assert configatron.production.watch_time.nil?
|
146
|
+
when '.xyzzy'
|
147
|
+
else
|
148
|
+
end
|
149
|
+
end
|
150
|
+
else
|
151
|
+
# means test did not include config files
|
152
|
+
end
|
153
|
+
#end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
#it '888 prints usage()' do
|
160
|
+
puts
|
161
|
+
puts "="*45
|
162
|
+
show_usage
|
163
|
+
puts "="*45
|
164
|
+
puts
|
165
|
+
a_string = <<EOS
|
166
|
+
This is my BANNER
|
167
|
+
|
168
|
+
Usage: cli_helper_test.rb [options] ...
|
169
|
+
|
170
|
+
Where:
|
171
|
+
|
172
|
+
Common Options Are:
|
173
|
+
-h, --help show this message
|
174
|
+
-v, --verbose enable verbose mode
|
175
|
+
-d, --debug enable debug mode
|
176
|
+
--version print the version: 0.0.1
|
177
|
+
|
178
|
+
Program Options Are:
|
179
|
+
-x, --xyxxy example MAGIC parameter
|
180
|
+
|
181
|
+
Do you need some HELP?
|
182
|
+
EOS
|
183
|
+
|
184
|
+
|
185
|
+
a_string_with_config = <<EOS
|
186
|
+
This is my BANNER
|
187
|
+
|
188
|
+
Usage: cli_helper_test.rb [options] ...
|
189
|
+
|
190
|
+
Where:
|
191
|
+
|
192
|
+
Common Options Are:
|
193
|
+
-h, --help show this message
|
194
|
+
-v, --verbose enable verbose mode
|
195
|
+
-d, --debug enable debug mode
|
196
|
+
--version print the version: 0.0.1
|
197
|
+
|
198
|
+
Program Options Are:
|
199
|
+
-x, --xyxxy example MAGIC parameter
|
200
|
+
--config read config file(s) [*.rb, *.yml, *.ini]
|
201
|
+
|
202
|
+
Do you need some HELP?
|
203
|
+
EOS
|
204
|
+
|
205
|
+
if configatron.support_config_files
|
206
|
+
assert_equal a_string_with_config, usage
|
207
|
+
else
|
208
|
+
assert_equal a_string, usage
|
209
|
+
end
|
210
|
+
#end
|
211
|
+
|
212
|
+
#it '999 Show the options structure' do
|
213
|
+
puts '*'*45
|
214
|
+
ap configatron.to_h
|
215
|
+
#end
|
216
|
+
|
217
|
+
#end # decribe 'how it works'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
configatron.test do |test|
|
3
|
+
test.host = 'localhost'
|
4
|
+
test.ip = '127.0.0.1'
|
5
|
+
end
|
6
|
+
|
7
|
+
configatron.development do |dev|
|
8
|
+
dev.host = 'devhost'
|
9
|
+
dev.ip = '127.0.0.1'
|
10
|
+
end
|
11
|
+
|
12
|
+
configatron.production do |prod|
|
13
|
+
prod.host = 'prodhost'
|
14
|
+
prod.ip = '0.0.0.0'
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
configatron.test do |test|
|
3
|
+
test.host = 'localhost'
|
4
|
+
test.ip = '127.0.0.1'
|
5
|
+
end
|
6
|
+
|
7
|
+
configatron.development do |dev|
|
8
|
+
dev.host = 'devhost'
|
9
|
+
dev.ip = '127.0.0.1'
|
10
|
+
end
|
11
|
+
|
12
|
+
configatron.production do |prod|
|
13
|
+
prod.host = 'prodhost'
|
14
|
+
prod.ip = '0.0.0.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
if <%= true =>
|
18
|
+
puts "Why would you ever want ERB stuff in a ruby-based config file?"
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
This is an unknown config file format
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: configatron
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nenv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: parseconfig
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: slop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '4.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '4.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,35 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '10.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: kick_the_tires
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: debug_me
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - ">="
|
@@ -108,14 +136,12 @@ dependencies:
|
|
108
136
|
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
|
-
description:
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
You might even wrap not only slop but some of those other ARGV parsers.
|
118
|
-
I only did this much after being shamed into it by rubycritic.
|
139
|
+
description: "\n An encapsulation of a convention I have been using\n with
|
140
|
+
the slop, nenv, parseconfig and configatron gems for quick and dirty\n development
|
141
|
+
of\n command-line based utility programs. Slop parses ARGV; Nenv parses ENV;\n
|
142
|
+
\ ParseConfig parses INI; Configatron keeps it all together. YAML and ERB\n
|
143
|
+
\ preprocessing is also available. Ruby configuration files are also supported.\n
|
144
|
+
\ and you can specify multiple config files of mixed types at once.\n "
|
119
145
|
email:
|
120
146
|
- dvanhoozer@gmail.com
|
121
147
|
executables: []
|
@@ -129,6 +155,17 @@ files:
|
|
129
155
|
- cli_helper.gemspec
|
130
156
|
- example/cli_stub.rb
|
131
157
|
- lib/cli_helper.rb
|
158
|
+
- tests/README.txt
|
159
|
+
- tests/cli_helper_test.rb
|
160
|
+
- tests/config/sample.ini
|
161
|
+
- tests/config/sample.ini.erb
|
162
|
+
- tests/config/sample.rb
|
163
|
+
- tests/config/sample.rb.erb
|
164
|
+
- tests/config/sample.txt
|
165
|
+
- tests/config/sample.txt.erb
|
166
|
+
- tests/config/sample.xyzzy
|
167
|
+
- tests/config/sample.yml
|
168
|
+
- tests/config/sample.yml.erb
|
132
169
|
homepage: http://github.com/MadBomber/cli_helper
|
133
170
|
licenses:
|
134
171
|
- You want it? It's yours.
|
@@ -153,5 +190,6 @@ rubyforge_project:
|
|
153
190
|
rubygems_version: 2.4.6
|
154
191
|
signing_key:
|
155
192
|
specification_version: 4
|
156
|
-
summary: An
|
193
|
+
summary: An encapsulation of an integration of slop, nenv, parseconfig and configatron.
|
157
194
|
test_files: []
|
195
|
+
has_rdoc:
|