slop 4.5.0 → 4.6.0
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.
- checksums.yaml +4 -4
 - data/.travis.yml +1 -1
 - data/CHANGELOG.md +6 -0
 - data/README.md +8 -0
 - data/lib/slop.rb +1 -1
 - data/lib/slop/error.rb +5 -0
 - data/lib/slop/option.rb +6 -0
 - data/lib/slop/parser.rb +10 -0
 - data/test/error_test.rb +20 -0
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 66456d3c9b1836976bf1db77744397d30ed6eddd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 615f7a217ab9668b2eab4234230f67b7bad76ffc
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5976dae0692f77d98ef26995737385da682592ddd4631209543f1604130c607f6f584a787a036595d668914245b17cc0141050e8fe36843f288bda93f5bcd74a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a5ed147ed93952f3d3d3e38abd8ece30bb6131e43d085281c91c0c12bd4490473fc0f3169e6f82cc6b8a1aa494d1d77188eeba63ec622794614f586bcf1fccbe
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -20,6 +20,7 @@ Usage 
     | 
|
| 
       20 
20 
     | 
    
         
             
            opts = Slop.parse do |o|
         
     | 
| 
       21 
21 
     | 
    
         
             
              o.string '-h', '--host', 'a hostname'
         
     | 
| 
       22 
22 
     | 
    
         
             
              o.integer '--port', 'custom port', default: 80
         
     | 
| 
      
 23 
     | 
    
         
            +
              o.string '-l', '--login', required: true
         
     | 
| 
       23 
24 
     | 
    
         
             
              o.bool '-v', '--verbose', 'enable verbose mode'
         
     | 
| 
       24 
25 
     | 
    
         
             
              o.bool '-q', '--quiet', 'suppress output (quiet mode)'
         
     | 
| 
       25 
26 
     | 
    
         
             
              o.bool '-c', '--check-ssl-certificate', 'check SSL certificate for host'
         
     | 
| 
         @@ -39,6 +40,12 @@ opts.check_ssl_certificate? #=> true 
     | 
|
| 
       39 
40 
     | 
    
         
             
            opts.to_hash  #=> { host: "192.168.0.1", port: 80, verbose: true, quiet: false, check_ssl_certificate: true }
         
     | 
| 
       40 
41 
     | 
    
         
             
            ```
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
            Note that the block we've added to the `--version` flag will be executed
         
     | 
| 
      
 44 
     | 
    
         
            +
            during parse time. Therefore these blocks should be reserved
         
     | 
| 
      
 45 
     | 
    
         
            +
            for immediately reacting to the presence of a flag. If you want to
         
     | 
| 
      
 46 
     | 
    
         
            +
            access other options or mutate values, check out the "Custom option types"
         
     | 
| 
      
 47 
     | 
    
         
            +
            section below and implement the `#finish` method.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       42 
49 
     | 
    
         
             
            Option types
         
     | 
| 
       43 
50 
     | 
    
         
             
            ------------
         
     | 
| 
       44 
51 
     | 
    
         | 
| 
         @@ -191,6 +198,7 @@ Slop will raise errors for the following: 
     | 
|
| 
       191 
198 
     | 
    
         | 
| 
       192 
199 
     | 
    
         
             
            * An option used without an argument when it expects one: `Slop::MissingArgument`
         
     | 
| 
       193 
200 
     | 
    
         
             
            * An option used that Slop doesn't know about: `Slop::UnknownOption`
         
     | 
| 
      
 201 
     | 
    
         
            +
            * An option marked as `required` when not provided: `Slop::MissingRequiredOption`
         
     | 
| 
       194 
202 
     | 
    
         | 
| 
       195 
203 
     | 
    
         
             
            These errors inherit from `Slop::Error`, so you can rescue them all.
         
     | 
| 
       196 
204 
     | 
    
         
             
            Alternatively you can suppress these errors with the `suppress_errors` config
         
     | 
    
        data/lib/slop.rb
    CHANGED
    
    
    
        data/lib/slop/error.rb
    CHANGED
    
    
    
        data/lib/slop/option.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ module Slop 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  help: true,
         
     | 
| 
       5 
5 
     | 
    
         
             
                  tail: false,
         
     | 
| 
       6 
6 
     | 
    
         
             
                  underscore_flags: true,
         
     | 
| 
      
 7 
     | 
    
         
            +
                  required: false,
         
     | 
| 
       7 
8 
     | 
    
         
             
                }
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                # An Array of flags this option matches.
         
     | 
| 
         @@ -101,6 +102,11 @@ module Slop 
     | 
|
| 
       101 
102 
     | 
    
         
             
                  config[:suppress_errors]
         
     | 
| 
       102 
103 
     | 
    
         
             
                end
         
     | 
| 
       103 
104 
     | 
    
         | 
| 
      
 105 
     | 
    
         
            +
                # Returns true if an exception should be raised when this option isn't supplied.
         
     | 
| 
      
 106 
     | 
    
         
            +
                def required?
         
     | 
| 
      
 107 
     | 
    
         
            +
                  config[:required]
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
       104 
110 
     | 
    
         
             
                # Returns all flags joined by a comma. Used by the help string.
         
     | 
| 
       105 
111 
     | 
    
         
             
                def flag
         
     | 
| 
       106 
112 
     | 
    
         
             
                  flags.join(", ")
         
     | 
    
        data/lib/slop/parser.rb
    CHANGED
    
    | 
         @@ -80,6 +80,15 @@ module Slop 
     | 
|
| 
       80 
80 
     | 
    
         | 
| 
       81 
81 
     | 
    
         
             
                  @arguments += ignored_args
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
      
 83 
     | 
    
         
            +
                  if !suppress_errors?
         
     | 
| 
      
 84 
     | 
    
         
            +
                    unused_options.each do |o|
         
     | 
| 
      
 85 
     | 
    
         
            +
                      if o.config[:required]
         
     | 
| 
      
 86 
     | 
    
         
            +
                        pretty_flags = o.flags.map { |f| "`#{f}'" }.join(", ")
         
     | 
| 
      
 87 
     | 
    
         
            +
                        raise MissingRequiredOption, "missing required option #{pretty_flags}"
         
     | 
| 
      
 88 
     | 
    
         
            +
                      end
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
       83 
92 
     | 
    
         
             
                  Result.new(self).tap do |result|
         
     | 
| 
       84 
93 
     | 
    
         
             
                    used_options.each { |o| o.finish(result) }
         
     | 
| 
       85 
94 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -148,6 +157,7 @@ module Slop 
     | 
|
| 
       148 
157 
     | 
    
         
             
                def partition(strings)
         
     | 
| 
       149 
158 
     | 
    
         
             
                  if strings.include?("--")
         
     | 
| 
       150 
159 
     | 
    
         
             
                    partition_idx = strings.index("--")
         
     | 
| 
      
 160 
     | 
    
         
            +
                    return [[], strings[1..-1]] if partition_idx.zero?
         
     | 
| 
       151 
161 
     | 
    
         
             
                    [strings[0..partition_idx-1], strings[partition_idx+1..-1]]
         
     | 
| 
       152 
162 
     | 
    
         
             
                  else
         
     | 
| 
       153 
163 
     | 
    
         
             
                    [strings, []]
         
     | 
    
        data/test/error_test.rb
    CHANGED
    
    | 
         @@ -21,6 +21,12 @@ describe Slop::MissingArgument do 
     | 
|
| 
       21 
21 
     | 
    
         
             
                opts.string "-n", "--name"
         
     | 
| 
       22 
22 
     | 
    
         
             
                opts.parse %w(--name)
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              it "does not raise if '--' appears as the first argument" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                opts = Slop::Options.new
         
     | 
| 
      
 27 
     | 
    
         
            +
                opts.string "-n", "--name"
         
     | 
| 
      
 28 
     | 
    
         
            +
                opts.parse %w(-- --name)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       24 
30 
     | 
    
         
             
            end
         
     | 
| 
       25 
31 
     | 
    
         | 
| 
       26 
32 
     | 
    
         
             
            describe Slop::UnknownOption do
         
     | 
| 
         @@ -43,3 +49,17 @@ describe Slop::UnknownOption do 
     | 
|
| 
       43 
49 
     | 
    
         
             
                opts.parse %w(--foo)
         
     | 
| 
       44 
50 
     | 
    
         
             
              end
         
     | 
| 
       45 
51 
     | 
    
         
             
            end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            describe Slop::MissingRequiredOption do
         
     | 
| 
      
 54 
     | 
    
         
            +
              it "raises when a required option is missing" do
         
     | 
| 
      
 55 
     | 
    
         
            +
                opts = Slop::Options.new
         
     | 
| 
      
 56 
     | 
    
         
            +
                opts.string "-n", "--name", required: true
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_raises(Slop::MissingRequiredOption) { opts.parse [] }
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              it "does not raise when errors are suppressed" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                opts = Slop::Options.new(suppress_errors: true)
         
     | 
| 
      
 62 
     | 
    
         
            +
                opts.string "-n", "--name", required: true
         
     | 
| 
      
 63 
     | 
    
         
            +
                opts.parse []
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
            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 
     | 
    
         
            +
              version: 4.6.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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-10-06 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rake
         
     | 
| 
         @@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       87 
87 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       88 
88 
     | 
    
         
             
            requirements: []
         
     | 
| 
       89 
89 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       90 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 90 
     | 
    
         
            +
            rubygems_version: 2.6.13
         
     | 
| 
       91 
91 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       92 
92 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       93 
93 
     | 
    
         
             
            summary: Simple Lightweight Option Parsing
         
     |