dotopts 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.index CHANGED
@@ -49,7 +49,7 @@ paths:
49
49
  created: '2013-01-23'
50
50
  summary: Automatic Arguments for Ruby
51
51
  title: DotOpts
52
- version: 0.1.2
52
+ version: 0.1.3
53
53
  name: dotopts
54
54
  description: DotOpts is an automatic commandline argument augmenter for Ruby tools.
55
55
  date: '2013-01-29'
data/Gemfile.lock CHANGED
@@ -1,16 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotopts (0.1.0)
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
- [![Gem Version](https://badge.fury.io/rb/dotopts.png)](http://badge.fury.io/rb/dotopts)
2
- [![Build Status](https://secure.travis-ci.org/rubyworks/dotopts.png)](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
+ [![Build Status](https://secure.travis-ci.org/rubyworks/dotopts.png)](http://travis-ci.org/rubyworks/dotopts) /
9
+ [![Gem Version](https://badge.fury.io/rb/dotopts.png)](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 `.opts` configuration file and applies the appropriate
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 `.opts` file:
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 `.opts` configuration file support profiles via the square brackets.
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 an .opts file:
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 an .opts file with a number of profiles:
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 an .opts file with a number of commands:
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 an .opts file:
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 an .opts file with a leading profile:
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 an .opts file with a number of profiles:
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 an .opts file with a number of profiles:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
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 an .opts file:
17
+ Given a `.option` file:
18
18
 
19
19
  [a=$b]
20
20
  yard
@@ -1,4 +1,4 @@
1
- When 'Given an .opts file' do |text|
1
+ When "Given a `.option` file" do |text|
2
2
  ENV.replace({})
3
3
  ARGV.replace([])
4
4
 
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 = '.opts'
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 = File.read(file)
16
+ text = File.read(file)
17
17
  parser = Parser.parse(text)
18
- apply(parser.arguments, parser.environment)
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
@@ -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
- # @todo Note sure the cmd environment variable override is a good idea.
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.2
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-01-29 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: qed