dotopts 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.index +1 -1
- data/Gemfile.lock +4 -7
- data/HISTORY.md +18 -0
- data/README.md +6 -10
- data/demo/09_battery/commands_only.md +3 -3
- data/demo/09_battery/profiles_basic.md +4 -4
- data/demo/09_battery/profiles_complex.md +4 -4
- data/demo/09_battery/profiles_regex.md +3 -3
- data/demo/09_battery/substitution.md +2 -2
- data/demo/applique/battery.rb +1 -1
- data/lib/dotopts/api.rb +29 -5
- data/lib/dotopts/parser.rb +26 -14
- metadata +2 -2
data/.index
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dotopts (0.1.
|
5
|
-
|
6
|
-
PATH
|
7
|
-
remote: ../ae
|
8
|
-
specs:
|
9
|
-
ae (1.8.1)
|
4
|
+
dotopts (0.1.3)
|
10
5
|
|
11
6
|
GEM
|
12
7
|
remote: http://rubygems.org/
|
13
8
|
specs:
|
9
|
+
ae (1.8.1)
|
10
|
+
ansi
|
14
11
|
ansi (1.4.3)
|
15
12
|
brass (1.2.1)
|
16
13
|
facets (2.9.3)
|
@@ -27,7 +24,7 @@ PLATFORMS
|
|
27
24
|
ruby
|
28
25
|
|
29
26
|
DEPENDENCIES
|
30
|
-
ae
|
27
|
+
ae
|
31
28
|
dotopts!
|
32
29
|
qed
|
33
30
|
spectroscope
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# RELEASE HISTORY
|
2
2
|
|
3
|
+
## 0.1.3 / 2013-01-30
|
4
|
+
|
5
|
+
Environment settings were not being applied. This release improves the code
|
6
|
+
that handles application of options and fixes the environment setting issue.
|
7
|
+
This release also adds a debug log option, so one can see what DotOpts is doing
|
8
|
+
by setting `dotopts_debug`.
|
9
|
+
|
10
|
+
Changes:
|
11
|
+
|
12
|
+
* Fix environment setting, ensuring their application.
|
13
|
+
* Add debug log when `doptopts_debug` is set.
|
14
|
+
|
15
|
+
|
16
|
+
## 0.1.2 / 2013-01-29
|
17
|
+
|
18
|
+
Accidental release. Yanked.
|
19
|
+
|
20
|
+
|
3
21
|
## 0.1.1 / 2013-01-29
|
4
22
|
|
5
23
|
This release simply fixes the missing optional argument on the
|
data/README.md
CHANGED
@@ -1,21 +1,17 @@
|
|
1
|
-
[](http://badge.fury.io/rb/dotopts)
|
2
|
-
[](http://travis-ci.org/rubyworks/dotopts)
|
3
|
-
|
4
|
-
<br/>
|
5
|
-
|
6
1
|
# DotOpts
|
7
2
|
|
8
3
|
**Automated Commandline Options (for Ruby Executables)**
|
9
4
|
|
10
5
|
[Website](http://rubyworks.github.com/dotopts) /
|
11
6
|
[Report Issue](http://github.com/rubyworks/dotopts/issues) /
|
12
|
-
[Source Code](http://github.com/rubyworks/dotopts)
|
13
|
-
|
7
|
+
[Source Code](http://github.com/rubyworks/dotopts) /
|
8
|
+
[](http://travis-ci.org/rubyworks/dotopts) /
|
9
|
+
[](http://badge.fury.io/rb/dotopts)
|
14
10
|
|
15
11
|
## About
|
16
12
|
|
17
13
|
DotOpts is an automatic commandline argument augmenter. It looks for a
|
18
|
-
project's local `.
|
14
|
+
project's local `.option` configuration file and applies the appropriate
|
19
15
|
arguments when a matching command is invoked.
|
20
16
|
|
21
17
|
|
@@ -53,7 +49,7 @@ This will allow dotopts to run whenever using `bundle exec`.
|
|
53
49
|
|
54
50
|
### Setting Arguments
|
55
51
|
|
56
|
-
A simple example of a projects `.
|
52
|
+
A simple example of a projects `.option` file:
|
57
53
|
|
58
54
|
yardoc
|
59
55
|
yard doc
|
@@ -80,7 +76,7 @@ as a variable substitution.
|
|
80
76
|
|
81
77
|
### Conditional Profiles
|
82
78
|
|
83
|
-
The `.
|
79
|
+
The `.option` configuration file support profiles via the square brackets.
|
84
80
|
Profiles are chosen via the `$profile` or `$p` environment variable.
|
85
81
|
|
86
82
|
```
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Most basic example
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given a `.option` file:
|
6
6
|
|
7
7
|
yard
|
8
8
|
--title "Big Title"
|
@@ -14,7 +14,7 @@ When we run `yard`, we should get the arguments:
|
|
14
14
|
|
15
15
|
## Example with later matching commande
|
16
16
|
|
17
|
-
Given
|
17
|
+
Given a `.option` file with a number of profiles:
|
18
18
|
|
19
19
|
something
|
20
20
|
--title "Little Title"
|
@@ -29,7 +29,7 @@ When we run `yard` we should get the arguments:
|
|
29
29
|
|
30
30
|
## Example with multiple matching commands
|
31
31
|
|
32
|
-
Given
|
32
|
+
Given a `.option` file with a number of commands:
|
33
33
|
|
34
34
|
yard
|
35
35
|
--title "First Title"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Basic example with multiple profiles
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given a `.option` file:
|
6
6
|
|
7
7
|
yard
|
8
8
|
--title "Cool Title"
|
@@ -18,7 +18,7 @@ When we run `yard`, we should get the arguments:
|
|
18
18
|
|
19
19
|
## Example with single profile
|
20
20
|
|
21
|
-
Given
|
21
|
+
Given a `.option` file with a leading profile:
|
22
22
|
|
23
23
|
[example]
|
24
24
|
yard
|
@@ -31,7 +31,7 @@ When we run `p=example yard`, we should get the arguments:
|
|
31
31
|
|
32
32
|
## Example with later matching profile
|
33
33
|
|
34
|
-
Given
|
34
|
+
Given a `.option` file with a number of profiles:
|
35
35
|
|
36
36
|
[something]
|
37
37
|
yard
|
@@ -48,7 +48,7 @@ When we run `p=example yard` we should get the arguments:
|
|
48
48
|
|
49
49
|
## Example with multiple matching profiles
|
50
50
|
|
51
|
-
Given
|
51
|
+
Given a `.option` file with a number of profiles:
|
52
52
|
|
53
53
|
[example]
|
54
54
|
yard
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Basic environment profile
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given a `.option` file:
|
6
6
|
|
7
7
|
[a=1]
|
8
8
|
yard
|
@@ -15,7 +15,7 @@ When we run `a=1 yard`, we should get the arguments:
|
|
15
15
|
|
16
16
|
## Multi-matching profile
|
17
17
|
|
18
|
-
Given
|
18
|
+
Given a `.option` file:
|
19
19
|
|
20
20
|
[a=1 b=2]
|
21
21
|
yard
|
@@ -28,7 +28,7 @@ When we run `a=1 b=2 yard`, we should get the arguments:
|
|
28
28
|
|
29
29
|
## Multiple multi-matching profiles
|
30
30
|
|
31
|
-
Given
|
31
|
+
Given a `.option` file:
|
32
32
|
|
33
33
|
[a=1 b=1]
|
34
34
|
yard
|
@@ -45,7 +45,7 @@ When we run `a=1 b=3 yard`, we should get the arguments:
|
|
45
45
|
|
46
46
|
## Multiple matching multi-matching profiles
|
47
47
|
|
48
|
-
Given
|
48
|
+
Given a `.option` file:
|
49
49
|
|
50
50
|
[a=1 b=1]
|
51
51
|
yard
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Basic profile regex
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given a `.option` file:
|
6
6
|
|
7
7
|
[~"q(x)?"]
|
8
8
|
yard
|
@@ -20,7 +20,7 @@ And when we run `p=qx yard`, we should get the arguments:
|
|
20
20
|
|
21
21
|
## Basic environment profile regex
|
22
22
|
|
23
|
-
Given
|
23
|
+
Given a `.option` file:
|
24
24
|
|
25
25
|
[a=~"x|y"]
|
26
26
|
yard
|
@@ -38,7 +38,7 @@ And when we run `a=y yard`, we should get the arguments:
|
|
38
38
|
|
39
39
|
## Complex profile
|
40
40
|
|
41
|
-
Given
|
41
|
+
Given a `.option` file:
|
42
42
|
|
43
43
|
[~"q(x)?" a=~"x|y"]
|
44
44
|
yard
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Most basic example
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given a `.option` file:
|
6
6
|
|
7
7
|
yard
|
8
8
|
--title $title
|
@@ -14,7 +14,7 @@ When we run `title=Title yard`, we should get the arguments:
|
|
14
14
|
|
15
15
|
## Environment profile substitutions
|
16
16
|
|
17
|
-
Given
|
17
|
+
Given a `.option` file:
|
18
18
|
|
19
19
|
[a=$b]
|
20
20
|
yard
|
data/demo/applique/battery.rb
CHANGED
data/lib/dotopts/api.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module DotOpts
|
2
2
|
require 'dotopts/parser'
|
3
3
|
|
4
|
-
#
|
5
|
-
OPTIONS_FILE = '.
|
4
|
+
# Configuration file name.
|
5
|
+
OPTIONS_FILE = '.option'
|
6
6
|
|
7
7
|
# Configure
|
8
8
|
#
|
@@ -13,9 +13,14 @@ module DotOpts
|
|
13
13
|
def self.configure!(file=nil)
|
14
14
|
file = options_file unless file
|
15
15
|
if file
|
16
|
-
text
|
16
|
+
text = File.read(file)
|
17
17
|
parser = Parser.parse(text)
|
18
|
-
|
18
|
+
|
19
|
+
argv = parser.arguments
|
20
|
+
env = parser.environment
|
21
|
+
|
22
|
+
debug(file, argv, env)
|
23
|
+
apply(argv, env)
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -48,10 +53,29 @@ module DotOpts
|
|
48
53
|
#
|
49
54
|
# TODO: Support argument prepending in future version?
|
50
55
|
#
|
56
|
+
# @return nothing
|
51
57
|
def self.apply(argv, env={})
|
52
|
-
puts argv.join(' ') if ENV['dotopts_debug']
|
53
58
|
env.each{ |k,v| ENV[k.to_s] = v.to_s }
|
54
59
|
ARGV.concat(argv)
|
55
60
|
end
|
56
61
|
|
62
|
+
# Print message to stderr if dopts_debug flag it set.
|
63
|
+
#
|
64
|
+
# @return nothing
|
65
|
+
def self.debug(file, argv, env)
|
66
|
+
return unless ENV['dotopts_debug']
|
67
|
+
|
68
|
+
$stderr.puts "dotopts file: #{file}"
|
69
|
+
|
70
|
+
unless argv.empty?
|
71
|
+
msg = argv.join(' ')
|
72
|
+
$stderr.puts "dotopts argv: " + msg
|
73
|
+
end
|
74
|
+
|
75
|
+
unless env.empty?
|
76
|
+
msg = env.map{ |k,v| "#{k}=#{v.inspect}" }.join(' ')
|
77
|
+
$stderr.puts "dotopts env: " + msg
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
57
81
|
end
|
data/lib/dotopts/parser.rb
CHANGED
@@ -3,39 +3,44 @@ module DotOpts
|
|
3
3
|
class Parser
|
4
4
|
require 'shellwords'
|
5
5
|
|
6
|
-
#
|
6
|
+
# Regular expression to match profile headers.
|
7
7
|
RE_PROFILE_HEADER = /^\[/
|
8
8
|
|
9
|
-
#
|
9
|
+
# Regular expression to match command headers.
|
10
10
|
RE_COMMAND_HEADER = /^\w/
|
11
11
|
|
12
|
-
#
|
12
|
+
# Regular expression to match blank strings.
|
13
13
|
RE_BLANK_STRING = /^\s*$/
|
14
14
|
|
15
|
+
# Convenience constructor for `new(text).parse`.
|
15
16
|
#
|
17
|
+
# @return [Parser]
|
16
18
|
def self.parse(text)
|
17
19
|
parser = new(text)
|
18
20
|
parser.parse
|
19
21
|
parser
|
20
22
|
end
|
21
23
|
|
24
|
+
# Initialize new instance.
|
25
|
+
#
|
26
|
+
# @param [#to_s] text
|
22
27
|
#
|
23
28
|
def initialize(text)
|
24
|
-
@text = text
|
29
|
+
@text = text.to_s
|
25
30
|
@arguments = []
|
26
31
|
@environment = {}
|
27
32
|
end
|
28
33
|
|
29
|
-
#
|
34
|
+
# The configuration document text.
|
30
35
|
attr :text
|
31
36
|
|
32
|
-
#
|
37
|
+
# The applicable arguments parsed from the config text.
|
33
38
|
attr :arguments
|
34
39
|
|
35
|
-
#
|
40
|
+
# The applicable environment parsed from the config text.
|
36
41
|
attr :environment
|
37
42
|
|
38
|
-
#
|
43
|
+
# Parse the configuration text.
|
39
44
|
def parse
|
40
45
|
lines = @text.lines.to_a
|
41
46
|
|
@@ -54,7 +59,7 @@ module DotOpts
|
|
54
59
|
parse_profiles(lines)
|
55
60
|
end
|
56
61
|
|
57
|
-
#
|
62
|
+
# Parse profiles.
|
58
63
|
def parse_profiles(lines)
|
59
64
|
until lines.empty?
|
60
65
|
line = lines.first.rstrip
|
@@ -87,7 +92,7 @@ module DotOpts
|
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
90
|
-
#
|
95
|
+
# Parse commands.
|
91
96
|
def parse_commands(lines)
|
92
97
|
while line = lines.first
|
93
98
|
line = line.strip
|
@@ -106,7 +111,7 @@ module DotOpts
|
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
109
|
-
#
|
114
|
+
# Parse environment.
|
110
115
|
def parse_environment(lines)
|
111
116
|
while line = lines.first
|
112
117
|
line = line.strip
|
@@ -121,7 +126,7 @@ module DotOpts
|
|
121
126
|
end
|
122
127
|
end
|
123
128
|
|
124
|
-
#
|
129
|
+
# Parse arguments.
|
125
130
|
def parse_arguments(lines)
|
126
131
|
while line = lines.first
|
127
132
|
line = line.rstrip
|
@@ -134,9 +139,10 @@ module DotOpts
|
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
142
|
+
# The current command comes from the basename of `$0`.
|
143
|
+
# But it can be overriddne by setting the `cmd` environment variable.
|
137
144
|
#
|
138
|
-
# @
|
139
|
-
#
|
145
|
+
# @return [String]
|
140
146
|
def current_command
|
141
147
|
ENV['cmd'] || File.basename($0)
|
142
148
|
end
|
@@ -148,12 +154,18 @@ module DotOpts
|
|
148
154
|
value.gsub(/\$(\w+)/){ |m| ENV[$1] }
|
149
155
|
end
|
150
156
|
|
157
|
+
# Split a string up into shellwords.
|
151
158
|
#
|
159
|
+
# @return [Array]
|
152
160
|
def shellwords(value)
|
153
161
|
Shellwords.shellwords(value)
|
154
162
|
end
|
155
163
|
|
164
|
+
# Remove intialize blank lines for an array of strings.
|
165
|
+
#
|
166
|
+
# @param [Array<String>] lines
|
156
167
|
#
|
168
|
+
# @return [Array<String>]
|
157
169
|
def remove_initial_blank_lines(lines)
|
158
170
|
lines.shift while RE_BLANK_STRING =~ lines.first
|
159
171
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotopts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: qed
|