cli_helper 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 +4 -4
- data/README.md +15 -6
- data/cli_helper.gemspec +5 -4
- data/lib/cli_helper.rb +14 -7
- data/tests/cli_helper_test.rb +10 -4
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826db70a0f7333baf6e7814633564ca37e54e576
|
4
|
+
data.tar.gz: be186dc883bd3bec850ea5571ef2066fcd6c6a44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8928b5d6fb0bd41573a7bd44bdcfecf30a0423c3b9e78ff45405715ea5714147faabfddcfe0b9999a5e0933554f22678835ff40b87518a8336f8dc09591660e
|
7
|
+
data.tar.gz: 6d3a8826de788ed038bc21dd0d953b8a9d56106408d12d32a1de60f53d11ec9db7224aae2a5eb1b08ff97b4c9713c3846908bf20625e04bf37b640cd4bbd5ec3
|
data/README.md
CHANGED
@@ -15,9 +15,9 @@ Here are the gems used and what they do:
|
|
15
15
|
* parses ENV for friendly use
|
16
16
|
* http://github.com/e2/nenv
|
17
17
|
|
18
|
-
*
|
19
|
-
* parses INI files
|
20
|
-
* http://github.com/
|
18
|
+
* inifile
|
19
|
+
* parses INI files (or *.txt if you want to avoid windoze terms)
|
20
|
+
* http://github.com/twp/inifile
|
21
21
|
|
22
22
|
* slop
|
23
23
|
* parses ARGV
|
@@ -77,11 +77,11 @@ cli_helper supports multiple types of configuration files:
|
|
77
77
|
```text
|
78
78
|
*.rb
|
79
79
|
*.yml
|
80
|
-
*.yml.erb
|
81
80
|
*.ini
|
82
81
|
*.txt (in the INI format)
|
83
|
-
*.ini.erb
|
84
|
-
*.txt.erb
|
82
|
+
*.ini.erb
|
83
|
+
*.txt.erb
|
84
|
+
*.yml.erb
|
85
85
|
```
|
86
86
|
|
87
87
|
All values obtained from config files and command line parameters are
|
@@ -150,6 +150,15 @@ my_program.rb -v *.txt
|
|
150
150
|
The file names matching the '*.txt' glob will be put into the configatron.arguments
|
151
151
|
array.
|
152
152
|
|
153
|
+
When process INI or TXT config files the following options can
|
154
|
+
be useful:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
configatron.ini_comment # default: '#'
|
158
|
+
configatron.ini_encoding # default: 'UTF-8'
|
159
|
+
configatron.ini_seperator # default: '='
|
160
|
+
```
|
161
|
+
|
153
162
|
|
154
163
|
## Boolean options auto-generate methods
|
155
164
|
|
data/cli_helper.gemspec
CHANGED
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "cli_helper"
|
7
|
-
spec.version = '0.1.
|
7
|
+
spec.version = '0.1.1'
|
8
8
|
spec.authors = ["Dewayne VanHoozer"]
|
9
9
|
spec.email = ["dvanhoozer@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = %q{An encapsulation of an integration of slop, nenv,
|
11
|
+
spec.summary = %q{An encapsulation of an integration of slop, nenv, inifile and configatron.}
|
12
12
|
spec.description = %q{
|
13
13
|
An encapsulation of a convention I have been using
|
14
|
-
with the slop, nenv,
|
14
|
+
with the slop, nenv, inifile and configatron gems for quick and dirty
|
15
15
|
development of
|
16
16
|
command-line based utility programs. Slop parses ARGV; Nenv parses ENV;
|
17
17
|
ParseConfig parses INI; Configatron keeps it all together. YAML and ERB
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_dependency 'configatron'
|
32
32
|
spec.add_dependency 'nenv'
|
33
|
-
spec.add_dependency '
|
33
|
+
spec.add_dependency 'inifile'
|
34
34
|
spec.add_dependency 'slop', "~> 4.0"
|
35
35
|
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.9"
|
@@ -38,5 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'kick_the_tires'
|
39
39
|
spec.add_development_dependency 'awesome_print'
|
40
40
|
spec.add_development_dependency 'debug_me'
|
41
|
+
spec.add_development_dependency 'timecop'
|
41
42
|
|
42
43
|
end
|
data/lib/cli_helper.rb
CHANGED
@@ -14,7 +14,7 @@ require 'yaml'
|
|
14
14
|
# Third-party gems
|
15
15
|
require 'configatron'
|
16
16
|
require 'nenv'
|
17
|
-
require '
|
17
|
+
require 'inifile'
|
18
18
|
require 'slop'
|
19
19
|
|
20
20
|
# Example Custom Type for Slop
|
@@ -55,6 +55,9 @@ module CliHelper
|
|
55
55
|
disable_verbose: false,
|
56
56
|
disable_version: false,
|
57
57
|
suppress_errors: false,
|
58
|
+
ini_comment: '#',
|
59
|
+
ini_seperator: '=',
|
60
|
+
ini_encoding: 'UTF-8',
|
58
61
|
user_name: Nenv.user || Nenv.user_name || Nenv.logname || 'The Unknown Programmer',
|
59
62
|
home_path: Pathname.new(Nenv.home),
|
60
63
|
cli: 'a place holder for the Slop object',
|
@@ -95,10 +98,14 @@ module CliHelper
|
|
95
98
|
return a_hash
|
96
99
|
end
|
97
100
|
|
98
|
-
def cli_helper_process_ini(
|
99
|
-
|
100
|
-
|
101
|
-
|
101
|
+
def cli_helper_process_ini(file_contents='')
|
102
|
+
an_ini_object = IniFile.new(
|
103
|
+
content: file_contents,
|
104
|
+
comment: configatron.ini_comment,
|
105
|
+
parameter: configatron.ini_seperator,
|
106
|
+
encoding: configatron.ini_encoding
|
107
|
+
)
|
108
|
+
return an_ini_object.to_h
|
102
109
|
end
|
103
110
|
|
104
111
|
# Invoke Slop with common CLI parameters and custom
|
@@ -199,8 +206,8 @@ module CliHelper
|
|
199
206
|
when :ini
|
200
207
|
configatron.configure_from_hash(
|
201
208
|
configatron.configure_from_hash(
|
202
|
-
cli_helper_process_ini(
|
203
|
-
|
209
|
+
cli_helper_process_ini(
|
210
|
+
cli_helper_process_erb(cf.read)
|
204
211
|
)
|
205
212
|
)
|
206
213
|
)
|
data/tests/cli_helper_test.rb
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
################################################
|
3
3
|
## Here is how it works
|
4
4
|
|
5
|
+
require 'timecop'
|
6
|
+
|
7
|
+
# Freeze time for the erb tests
|
8
|
+
Timecop.freeze(Time.now)
|
9
|
+
|
5
10
|
require_relative '../lib/cli_helper'
|
6
11
|
include CliHelper
|
7
12
|
|
@@ -125,13 +130,14 @@ end
|
|
125
130
|
file_type = c.basename.to_s.downcase.gsub('.erb','').split('.').last
|
126
131
|
case file_type
|
127
132
|
when 'ini'
|
128
|
-
|
129
|
-
|
133
|
+
assert_equal String, configatron.wall_clock.the_mouse_says.class
|
134
|
+
assert_equal Time.now, configatron.wall_clock.the_mouse_says
|
130
135
|
when 'txt'
|
131
|
-
|
132
|
-
|
136
|
+
assert_equal String, configatron.wrist.watch_time.class
|
137
|
+
assert_equal Time.now, configatron.wrist.watch_time
|
133
138
|
when 'yml'
|
134
139
|
assert_equal Time, configatron.production.watch_time.class
|
140
|
+
assert_equal Time.now, configatron.production.watch_time
|
135
141
|
else
|
136
142
|
end
|
137
143
|
when '.rb'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: configatron
|
@@ -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: inifile
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -136,8 +136,22 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: "\n An encapsulation of a convention I have been using\n with
|
140
|
-
the slop, nenv,
|
154
|
+
the slop, nenv, inifile and configatron gems for quick and dirty\n development
|
141
155
|
of\n command-line based utility programs. Slop parses ARGV; Nenv parses ENV;\n
|
142
156
|
\ ParseConfig parses INI; Configatron keeps it all together. YAML and ERB\n
|
143
157
|
\ preprocessing is also available. Ruby configuration files are also supported.\n
|
@@ -190,6 +204,6 @@ rubyforge_project:
|
|
190
204
|
rubygems_version: 2.4.6
|
191
205
|
signing_key:
|
192
206
|
specification_version: 4
|
193
|
-
summary: An encapsulation of an integration of slop, nenv,
|
207
|
+
summary: An encapsulation of an integration of slop, nenv, inifile and configatron.
|
194
208
|
test_files: []
|
195
209
|
has_rdoc:
|