slop 4.4.3 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c63fac368765194fd91613b7972278df8ae6640
4
- data.tar.gz: 2090a28f3ad52ac3d7f053237d31bf4b0c1af732
3
+ metadata.gz: 63095938a88e1994b174a29d9c1bcca25fa84562
4
+ data.tar.gz: 4df7ece6ed84e45245081a7b6617372cd386385e
5
5
  SHA512:
6
- metadata.gz: 706aae3b6e32a0d93f26f1e0ffc6ebbc60df899d1ce60fcb68fcb85fa4c5fa0242e581ea24fb8947c43efe7d88753062a05d4ec8d2896681028d5ec003070662
7
- data.tar.gz: 3d81629d6cb5183e19b1a26f7bc582035bc4c7513775d9406a21e7f1783240a0bfbc4e10a2a87bc3c40fc6f282576490a588b9aa275eaec708023df86b6ec825
6
+ metadata.gz: abd18392e43a5413199e6b7ab482afdb4c5782c5eeb65c298d916279df060df614b7875e3ad836a803064d5aa0c04c093eb682753397ddb6b65bfa26550be9d6
7
+ data.tar.gz: 0f03c20ff5e6d240d57586a133cc531a6a68ac2fcf4f4aea4ac931726cdf7420f92ea736fadec0f0c715e91c395ccc1ca73f3e683da42b89f5544f5afe3d02eb
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.5.0 (2017-05-22)
5
+ -------------------
6
+
7
+ Features:
8
+ * Added config option to avoid translating flags-with-dashes into
9
+ underscores. #206 (@lbriais)
10
+
4
11
  v4.4.3 (2017-05-02)
5
12
  -------------------
6
13
 
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.4.3'
9
+ VERSION = '4.5.0'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
@@ -3,6 +3,7 @@ module Slop
3
3
  DEFAULT_CONFIG = {
4
4
  help: true,
5
5
  tail: false,
6
+ underscore_flags: true,
6
7
  }
7
8
 
8
9
  # An Array of flags this option matches.
@@ -107,7 +108,14 @@ module Slop
107
108
 
108
109
  # Returns the last key as a symbol. Used in Options.to_hash.
109
110
  def key
110
- (config[:key] || flags.last.sub(/\A--?/, '')).tr("-", "_").to_sym
111
+ key = config[:key] || flags.last.sub(/\A--?/, '')
112
+ key = key.tr '-', '_' if underscore_flags?
113
+ key.to_sym
114
+ end
115
+
116
+ # Returns true if this option should be displayed with dashes transformed into underscores.
117
+ def underscore_flags?
118
+ config[:underscore_flags]
111
119
  end
112
120
 
113
121
  # Returns true if this option should be displayed in help text.
@@ -3,9 +3,10 @@ module Slop
3
3
  include Enumerable
4
4
 
5
5
  DEFAULT_CONFIG = {
6
- suppress_errors: false,
7
- type: "null",
8
- banner: true,
6
+ suppress_errors: false,
7
+ type: "null",
8
+ banner: true,
9
+ underscore_flags: true,
9
10
  }
10
11
 
11
12
  # The Array of Option instances we've created.
@@ -33,7 +33,11 @@ module Slop
33
33
 
34
34
  # Returns an Option if it exists. Ignores any prefixed hyphens.
35
35
  def option(flag)
36
- cleaned = -> (f) { f.to_s.sub(/\A--?/, '').tr('_', '-') }
36
+ cleaned = -> (f) do
37
+ key = f.to_s.sub(/\A--?/, '')
38
+ key = key.tr '-', '_' if parser.config[:underscore_flags]
39
+ key.to_sym
40
+ end
37
41
  options.find do |o|
38
42
  o.flags.any? { |f| cleaned.(f) == cleaned.(flag) }
39
43
  end
@@ -21,6 +21,10 @@ describe Slop::Option do
21
21
  assert_equal :foo_bar, option(%w(-f --foo-bar), nil).key
22
22
  end
23
23
 
24
+ it "when specified, it won't convert dashes to underscores to make multi-word options symbol-friendly" do
25
+ assert_equal :'foo-bar', option(%w(-f --foo-bar), nil, underscore_flags: false).key
26
+ end
27
+
24
28
  it "can be overridden" do
25
29
  assert_equal :bar, option(%w(-f --foo), nil, key: "bar").key
26
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.3
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake