dreck 0.0.7 → 0.2.3

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
- SHA1:
3
- metadata.gz: c92ebc35034ec54b87f763e6d2f080232cc5a4e1
4
- data.tar.gz: '00601982073b1ac4bd08e734c38967236773d167'
2
+ SHA256:
3
+ metadata.gz: 51998a10bedf410ff5cd4cb7804f83606b1528b0859ff2854f3dd0736f4044e1
4
+ data.tar.gz: f684c1fd95269a7c95fb4b8c5a741f434b27e075e7f470f9859bd3f23ebf81a2
5
5
  SHA512:
6
- metadata.gz: c86759e00c6a8ad1bdfdfd414ed5bdc14303542994d2a47d813c00b2902e90f4eb8fc5158d7b08d94530037c287d9df86888386b4fe77242d507602bf9392710
7
- data.tar.gz: c7a2b7d64a0ddc6ac9fe8b39ff00fac601dde294e4e537fe1d208cfbeb01577bf000a6d5e86487c729ae7d6afd9d0984681e2e519e55db598fc8976f5d61993a
6
+ metadata.gz: c4a03799968c92e09e4e0055fb6038864b8f54c0c8856916a08d7e150da951943dde55e8131f7677be08c52b0ad624ae4f14fcef6465dbe007927d8fc2add533
7
+ data.tar.gz: 4c1ceadc4ca21f3c4b7c2051c08e8925bde885ff46be348895e6b7752412b6fbe2ae7397e996dcdf945f9f6c119609f8f11f429b0d30dff28f8c4a0742b6c081
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ The MIT License (MIT) with restrictions
2
2
 
3
- Copyright (c) 2017 William Woodruff <william @ yossarian.net>
3
+ Copyright (c) 2020 William Woodruff <william @ yossarian.net>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
22
+
23
+ The following terms additionally apply and override any above terms for
24
+ applicable parties:
25
+
26
+ You may not use, copy, modify, merge, publish, distribute, sublicense,
27
+ and/or sell copies of the Software in a military or law enforcement context,
28
+ defined as follows:
29
+
30
+ 1. A military context is a professional context where the intended application
31
+ of the Software is integration or use with or by military software, tools
32
+ (software or hardware), or personnel. This includes contractors and
33
+ subcontractors as well as research affiliates of any military organization.
34
+
35
+ 2. A law enforcement context is a professional context where the intended
36
+ application of the Software is integration or use with or by law enforcement
37
+ software, tools (software or hardware), or personnel. This includes
38
+ contractors and subcontractors as well as research affiliates of any law
39
+ enforcement organization.
40
+
41
+ Entities that sell or license to military or law enforcement organizations
42
+ may use the Software under the original terms, but only in contexts that do
43
+ not assist or supplement the sold or licensed product.
44
+
45
+ Students and academics who are affiliated with research institutions may use
46
+ the Software under the original terms, but only in contexts that do not assist
47
+ or supplement collaboration or affiliation with any military or law
48
+ enforcement organization.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  dreck
2
2
  =====
3
3
 
4
+ ![license](https://raster.shields.io/badge/license-MIT%20with%20restrictions-green.png)
5
+ [![Build Status](https://img.shields.io/github/workflow/status/woodruffw/dreck/CI/master)](https://github.com/woodruffw/dreck/actions?query=workflow%3ACI)
4
6
  [![Gem Version](https://badge.fury.io/rb/dreck.svg)](https://badge.fury.io/rb/dreck)
5
7
 
6
8
  A stupid parser for trailing arguments.
@@ -5,7 +5,7 @@ require_relative "dreck/result"
5
5
  # The primary namespace for {Dreck}.
6
6
  module Dreck
7
7
  # {Dreck}'s current version.
8
- VERSION = "0.0.7"
8
+ VERSION = "0.2.3"
9
9
 
10
10
  # Parse the given arguments and produce a result.
11
11
  # @param args [Array<String>] the arguments to parse
@@ -5,17 +5,29 @@ module Dreck
5
5
  class DreckError < RuntimeError
6
6
  end
7
7
 
8
+ # Raised during list specification if a non-positive number of arguments
9
+ # are requested.
10
+ class BadCountError < DreckError
11
+ end
12
+
8
13
  # Raised during argument absorption if arguments are either left over
9
14
  # or are insufficient to populate the expected results.
10
15
  class AbsorptionError < DreckError
11
- # @param actual [Integer] the actual number of arguments given
12
- # @param expected [Integer] the expected number of arguments
13
- # @param greedy [Boolean] whether or not a list that absorbs the tail is present
14
- def initialize(actual, expected, greedy = false)
15
- nmany = actual > expected ? "too few" : "too many"
16
- act = greedy && actual > expected ? expected : actual
17
- exp = greedy ? ">=#{actual}" : expected
18
- super "#{nmany} arguments given (#{act}, expected #{exp})"
16
+ # @param specified [Integer] the number of arguments specified
17
+ # @param supplied [Integer] the number of arguments supplied
18
+ def initialize(specified, supplied)
19
+ nmany = specified < supplied ? "too many" : "too few"
20
+ super "#{nmany} arguments given (#{supplied}, expected #{specified})"
21
+ end
22
+ end
23
+
24
+ # Raised during argument absorption if a greedy list was expected but all arguments
25
+ # have already been absorbed.
26
+ class GreedyAbsorptionError < DreckError
27
+ # @param specified [Integer] the number of arguments specified
28
+ # @param supplied [Integer] the number of arguments supplied
29
+ def initialize(specified, supplied)
30
+ super "too few arguments given (#{specified}, expected >#{supplied})"
19
31
  end
20
32
  end
21
33
 
@@ -27,6 +27,7 @@ module Dreck
27
27
  # @raise [ParserError] if the string is not a valid path on disk
28
28
  def parse_path(path)
29
29
  raise ParserError, "#{path}: no such path" unless File.exist?(path)
30
+
30
31
  path
31
32
  end
32
33
 
@@ -35,6 +36,7 @@ module Dreck
35
36
  # @raise [ParserError] if the string is not a valid regular file on disk
36
37
  def parse_file(file)
37
38
  raise ParserError, "#{file}: no such file" unless File.file?(file)
39
+
38
40
  file
39
41
  end
40
42
 
@@ -43,6 +45,7 @@ module Dreck
43
45
  # @raise [ParserError] if the string is not a valid directory on disk
44
46
  def parse_directory(dir)
45
47
  raise ParserError, "#{dir}: no such directory" unless File.directory?(dir)
48
+
46
49
  dir
47
50
  end
48
51
 
@@ -43,6 +43,10 @@ module Dreck
43
43
  # @param sym [Symbol] the name of the argument in {results}
44
44
  # @param count [Integer] the number of arguments in the list
45
45
  def list(type, sym, count: nil)
46
+ if count
47
+ raise BadCountError unless count.positive?
48
+ end
49
+
46
50
  @expected << [:list, type, sym, count]
47
51
  end
48
52
 
@@ -70,10 +74,10 @@ module Dreck
70
74
  def check_absorption!
71
75
  count, greedy = count_expected
72
76
 
73
- return if greedy && @args.size >= count
74
77
  return unless strict?
75
78
 
76
- raise AbsorptionError.new(count, @args.size, greedy) if count != @args.size
79
+ raise GreedyAbsorptionError.new(count, @args.size) if count >= @args.size && greedy
80
+ raise AbsorptionError.new(count, @args.size) if count != @args.size && !greedy
77
81
  end
78
82
 
79
83
  # Count the number of arguments expected to be supplied.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dreck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Typechecks and coerces non-option arguments.
14
14
  email: william@tuffbizz.com
@@ -25,7 +25,7 @@ files:
25
25
  - lib/dreck/result.rb
26
26
  homepage: https://github.com/woodruffw/dreck
27
27
  licenses:
28
- - MIT
28
+ - Nonstandard
29
29
  metadata: {}
30
30
  post_install_message:
31
31
  rdoc_options: []
@@ -42,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  requirements: []
45
- rubyforge_project:
46
- rubygems_version: 2.6.11
45
+ rubygems_version: 3.1.2
47
46
  signing_key:
48
47
  specification_version: 4
49
48
  summary: dreck - A stupid parser for trailing arguments.