slop 4.8.2 → 4.9.2

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
  SHA256:
3
- metadata.gz: b79c8ecabc4f59e446e17b38a61381a4711e1da44918d5bfa3c459e3330fa7c5
4
- data.tar.gz: 6a5c4c2b6a0624a0f533ea86bc7855774a23d134d581f178d2d6fa476b01da59
3
+ metadata.gz: db594ae38cd4d8b8d078d3b3854e5dce764f4763107caacc02b0b270c33098d8
4
+ data.tar.gz: 6e1348ca3f3d642bff87411d33c78b2f3d1b654c11c079a228f327f82648cd5f
5
5
  SHA512:
6
- metadata.gz: 15ac86c2fe54c3c5dffb8d186e50341febfa6ed858eedae5347a416fc9261159262d68873645c7bb11d1cc2155473f6deb3a8740da2c4fcc1a78f0f477cccfc8
7
- data.tar.gz: d1a078ebc9c8ddd2b970e9cc39dcf72fc20b3e67a50abed4bf51a7d22bafe8ae7170c03930bf8d3073f487d167f6f27fe1475b5e5735b4bf2090efa446a0eff5
6
+ metadata.gz: b578d6d172adf2b9c88d482fe27798d97a821b83ef7ff4f8b6e8ed37d63cd7f7963b9634b9f734e80d744c0fc077f47bc2a08e00feed02af90452c6415383494
7
+ data.tar.gz: 8fc6007694ba5df48585ac6561c1ec68cf50141d92cb6f080d50b6de700a0244aefd3d3d647f7ccee197c57cfcd3ad4721b2c88039ab6f9667cb47d4dc705620
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ paths:
7
+ - "lib/**"
8
+ - "test/**"
9
+ - ".github/**"
10
+ - "Rakefile"
11
+ pull_request:
12
+ branches: ["**"]
13
+ paths:
14
+ - "lib/**"
15
+ - "test/**"
16
+ - ".github/**"
17
+ - "Rakefile"
18
+
19
+ jobs:
20
+ tests:
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ ruby: [ "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "3.0", "3.1", head, jruby, truffleruby ]
26
+ name: Ruby ${{ matrix.ruby }}
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ bundler: none
34
+ - name: Run tests
35
+ run: rake test
data/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.9.2 (2022-03-26)
5
+ -------------------
6
+
7
+ Bug fixes:
8
+ * Handle flag arguments that contain equals character [#275](https://github.com/leejarvis/slop/pull/275) (ConnorWGarvey)
9
+
10
+ v4.9.1 (2021-05-28)
11
+ -------------------
12
+
13
+ Bug fixes:
14
+ * Fixed a bug where `flag=arg` syntax would raise an error when an
15
+ empty value was passed. [#266](https://github.com/leejarvis/slop/issues/266)
16
+
17
+ v4.9.0 (2021-05-11)
18
+ -------------------
19
+
20
+ Features:
21
+ * Add SymbolOption [#263](https://github.com/leejarvis/slop/pull/263)
22
+
23
+ Bug fixes:
24
+ * Use `+=` over `<<` to handle frozen string literals. [255](https://github.com/leejarvis/slop/pull/255)
25
+
4
26
  v4.8.2 (2020-07-10)
5
27
  -------------------
6
28
 
data/README.md CHANGED
@@ -3,7 +3,7 @@ Slop
3
3
 
4
4
  Slop is a simple option parser with an easy to remember syntax and friendly API.
5
5
 
6
- [![Build Status](https://travis-ci.org/leejarvis/slop.svg?branch=master)](http://travis-ci.org/leejarvis/slop)
6
+ [![Build Status](https://github.com/leejarvis/slop/actions/workflows/ci.yml/badge.svg)](https://github.com/leejarvis/slop/actions/workflows/ci.yml)
7
7
 
8
8
  Installation
9
9
  ------------
@@ -18,6 +18,7 @@ opts = Slop.parse do |o|
18
18
  o.string '-h', '--host', 'a hostname'
19
19
  o.integer '--port', 'custom port', default: 80
20
20
  o.string '-l', '--login', required: true
21
+ o.symbol '-m', '--method', default: :get
21
22
  o.bool '-v', '--verbose', 'enable verbose mode'
22
23
  o.bool '-q', '--quiet', 'suppress output (quiet mode)'
23
24
  o.bool '-c', '--check-ssl-certificate', 'check SSL certificate for host'
@@ -27,15 +28,16 @@ opts = Slop.parse do |o|
27
28
  end
28
29
  end
29
30
 
30
- ARGV #=> -v --login alice --host 192.168.0.1 --check-ssl-certificate
31
+ ARGV #=> -v --login alice --host 192.168.0.1 -m post --check-ssl-certificate
31
32
 
32
33
  opts[:host] #=> 192.168.0.1
33
34
  opts[:login] #=> alice
35
+ opts[:method] #=> :post
34
36
  opts.verbose? #=> true
35
37
  opts.quiet? #=> false
36
38
  opts.check_ssl_certificate? #=> true
37
39
 
38
- opts.to_hash #=> { host: "192.168.0.1", login: "alice", port: 80, verbose: true, quiet: false, check_ssl_certificate: true }
40
+ opts.to_hash #=> { host: "192.168.0.1", port: 80, login: "alice", method: :post, verbose: true, quiet: false, check_ssl_certificate: true }
39
41
  ```
40
42
 
41
43
  Note that the block we've added to the `--version` flag will be executed
@@ -56,6 +58,7 @@ o.integer #=> Slop::IntegerOption, expects an argument, aliased to IntOption
56
58
  o.float #=> Slop::FloatOption, expects an argument
57
59
  o.array #=> Slop::ArrayOption, expects an argument
58
60
  o.regexp #=> Slop::RegexpOption, expects an argument
61
+ o.symbol #=> Slop::SymbolOption, expects an argument
59
62
  o.null #=> Slop::NullOption, no argument and ignored from `to_hash`
60
63
  o.on #=> alias for o.null
61
64
  ```
@@ -132,9 +135,11 @@ opts = Slop.parse do |o|
132
135
  o.array '--files', 'a list of files', delimiter: ','
133
136
  end
134
137
 
135
- # both of these will return o[:files] as ["foo.txt", "bar.rb"]:
138
+ # Both of these will return o[:files] as ["foo.txt", "bar.rb"]:
136
139
  # --files foo.txt,bar.rb
137
140
  # --files foo.txt --files bar.rb
141
+ # This will return o[:files] as []:
142
+ # --files ""
138
143
  ```
139
144
 
140
145
  If you want to disable the built-in string-splitting, set the delimiter to
data/lib/slop/options.rb CHANGED
@@ -105,14 +105,14 @@ module Slop
105
105
  options.select.each_with_index.sort_by{ |o,i| [o.tail, i] }.each do |opt, i|
106
106
  # use the index to fetch an associated separator
107
107
  if sep = separators[i]
108
- str << "#{sep}\n"
108
+ str += "#{sep}\n"
109
109
  end
110
110
 
111
- str << "#{prefix}#{opt.to_s(offset: len)}\n" if opt.help?
111
+ str += "#{prefix}#{opt.to_s(offset: len)}\n" if opt.help?
112
112
  end
113
113
 
114
114
  if sep = separators[options.size]
115
- str << "#{sep}\n"
115
+ str += "#{sep}\n"
116
116
  end
117
117
 
118
118
  str
data/lib/slop/parser.rb CHANGED
@@ -52,7 +52,7 @@ module Slop
52
52
 
53
53
  # support `foo=bar`
54
54
  orig_flag = flag.dup
55
- if match = flag.match(/([^=]+)=([^=]+)/)
55
+ if match = flag.match(/([^=]+)=(.*)/)
56
56
  flag, arg = match.captures
57
57
  end
58
58
 
data/lib/slop/types.rb CHANGED
@@ -6,6 +6,13 @@ module Slop
6
6
  end
7
7
  end
8
8
 
9
+ # Cast the option argument to a symbol.
10
+ class SymbolOption < Option
11
+ def call(value)
12
+ value.to_sym
13
+ end
14
+ end
15
+
9
16
  # Cast the option argument to true or false.
10
17
  # Override default_value to default to false instead of nil.
11
18
  # This option type does not expect an argument. However, the API
data/lib/slop.rb CHANGED
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.8.2'
9
+ VERSION = '4.9.2'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
data/test/parser_test.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'shellwords'
2
3
 
3
4
  describe Slop::Parser do
4
5
  before do
@@ -16,16 +17,34 @@ describe Slop::Parser do
16
17
  assert_equal ["-v", "--name", "lee"], @parser.arguments
17
18
  end
18
19
 
19
- it "parses flag=argument" do
20
- @options.integer "-p", "--port"
21
- @result.parser.parse %w(--name=bob -p=123)
22
- assert_equal "bob", @result[:name]
23
- assert_equal 123, @result[:port]
20
+ describe "for flag=argument" do
21
+ it "parses names and values" do
22
+ @options.integer "-p", "--port"
23
+ @result.parser.parse %w(--name=bob -p=123)
24
+ assert_equal "bob", @result[:name]
25
+ assert_equal 123, @result[:port]
26
+ end
27
+
28
+ it "treats an = separated by a space as a value" do
29
+ @options.string "--foo"
30
+ @result.parser.parse %w(--foo = =)
31
+ assert_equal "=", @result[:foo]
32
+ assert_equal %w(=), @result.args
33
+ end
34
+
35
+ it "includes = in strings" do
36
+ @result.parser.parse(%w(--name=b=b))
37
+ assert_equal "b=b", @result[:name]
38
+ end
39
+ end
40
+
41
+ it "parses flag=''" do
42
+ @options.string "--str"
43
+ @options.array "--arr", default: ["array"]
44
+ @result.parser.parse %(--str="" --arr="").shellsplit
24
45
 
25
- @options.string "--foo"
26
- @result.parser.parse %w(--foo = =)
27
- assert_equal "=", @result[:foo]
28
- assert_equal %w(=), @result.args
46
+ assert_equal "", @result[:str]
47
+ assert_equal [], @result[:arr]
29
48
  end
30
49
 
31
50
  it "parses arg with leading -" do
data/test/types_test.rb CHANGED
@@ -1,5 +1,33 @@
1
1
  require 'test_helper'
2
2
 
3
+ describe Slop::StringOption do
4
+ before do
5
+ @options = Slop::Options.new
6
+ @age = @options.string "--name"
7
+ @minus = @options.string "--zipcode"
8
+ @result = @options.parse %w(--name Foo --zipcode 12345)
9
+ end
10
+
11
+ it "returns the value as a string" do
12
+ assert_equal "Foo", @result[:name]
13
+ assert_equal "12345", @result[:zipcode]
14
+ end
15
+ end
16
+
17
+ describe Slop::SymbolOption do
18
+ before do
19
+ @options = Slop::Options.new
20
+ @age = @options.symbol "--name"
21
+ @minus = @options.symbol "--zipcode"
22
+ @result = @options.parse %w(--name Foo --zipcode 12345)
23
+ end
24
+
25
+ it "returns the value as a symbol" do
26
+ assert_equal :Foo, @result[:name]
27
+ assert_equal :'12345', @result[:zipcode]
28
+ end
29
+ end
30
+
3
31
  describe Slop::BoolOption do
4
32
  before do
5
33
  @options = Slop::Options.new
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.8.2
4
+ version: 4.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2022-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,8 +44,8 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - ".github/workflows/ci.yml"
47
48
  - ".gitignore"
48
- - ".travis.yml"
49
49
  - CHANGELOG.md
50
50
  - Gemfile
51
51
  - LICENSE
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.0.3
89
+ rubygems_version: 3.2.32
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Simple Lightweight Option Parsing
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- cache: bundler
2
- before_install:
3
- - |
4
- export RVM_CURRENT=`rvm current|cut -c6-8`
5
- if [ "${RVM_CURRENT}" = "2.0" ] || \
6
- [ "${RVM_CURRENT}" = "2.1" ] || \
7
- [ "${RVM_CURRENT}" = "2.2" ]; then
8
- gem install bundler -v '< 2'
9
- fi
10
-
11
- rvm:
12
- - 2.0.0
13
- - 2.1
14
- - 2.2
15
- - 2.3.4
16
- - 2.4.9
17
- - 2.5.7
18
- - 2.6.5
19
- - 2.7.0
20
- - jruby-9.2.9.0
21
- - jruby-head
22
- - ruby-head
23
- jdk:
24
- - openjdk8
25
- notifications:
26
- email:
27
- on_success: change
28
- on_failure: always