shellopts 2.0.0.pre.1 → 2.0.0.pre.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: e60db3cf5de50dcd106cb0fca007d064e18354278a65207bb167bf8aa63d3433
4
- data.tar.gz: 85b0108262357d6e5654e725ab12293f51fd2579beb13fa0d910be2200c32310
3
+ metadata.gz: 79a36712cf9c41a500726cd042d9932f1c6ed7f7e7a334d5d245e0ad31185c75
4
+ data.tar.gz: ddeec0f65a4d8e4250cbc9d1332626395c135d0c4e34d879fafcfb89b492699a
5
5
  SHA512:
6
- metadata.gz: 375fe97651622560d786b288217e1a8581d12bbc497dee55b36848597d9410d393a127e86088cfe4ac8f949270d9f6797d6f135f65492f15bb9d4a84bff1ffbc
7
- data.tar.gz: c69a813e4672d87c6a4da69e0e8086d8acfe54c8506cda64ce6dc36dbc12669cc79c29ffd480c6871937d87491139f4e7448fd35a6d6a7d333451addd6c634a6
6
+ metadata.gz: 2890ba5f277385eb8cc30a9e168d618f3633278cc41066c302ed82d7be46eeefb5a30f41a2471947bc78a0e55e8219cc472887a91b9d753a6687dfda605231e6
7
+ data.tar.gz: a02ecb6e6613163f2915125ea0cd71cab30c7fd3c11f840a99bad0cb27b6a14dad0b3c806d55f8ab752e4f7921731cab0753c562499b7c88eeb8e5e8400efaab
data/TODO CHANGED
@@ -1,5 +1,8 @@
1
1
 
2
2
  TODO
3
+ o Remove ! from OptionStruct#subcommand return value. We know we're
4
+ processing commands so there is no need to have a distinct name and it
5
+ feels a lot more intuitive without it
3
6
  o Add validation block to ShellOpts class methods
4
7
  o Get rid of key_name. Define #name on Grammar::Node instead
5
8
  o Define #name to the string name of the option/command without prefixed '--'
@@ -40,6 +40,9 @@ PROGRAM = File.basename($PROGRAM_NAME)
40
40
  # hash, args = ShellOpts.as_hash(USAGE, ARGV)
41
41
  # struct, args = ShellOpts.as_struct(USAGE, ARGV)
42
42
  #
43
+ # +args+ is a ShellOpts::Argv object containing the the remaning command line
44
+ # arguments. Argv is derived from Array
45
+ #
43
46
  # ShellOpts can raise the exception CompilerError is there is an error in the
44
47
  # USAGE string. If there is an error in the user supplied command line, #error
45
48
  # is called instead and the program terminates with exit code 1. ShellOpts
@@ -0,0 +1,36 @@
1
+
2
+ module ShellOpts
3
+ class Args < Array
4
+ def initialize(shellopts, *args)
5
+ @shellopts = shellopts
6
+ super(*args)
7
+ end
8
+
9
+ # Remove and return +count+ elements from the beginning of the array.
10
+ # Elements are removed from the end of the array if +count+ is less than 0.
11
+ # Expects at least +count.abs+ elements in the array
12
+ def extract(count, message = nil)
13
+ self.size >= count.abs or inoa(message)
14
+ start = count >= 0 ? 0 : size + count
15
+ slice!(start, count.abs)
16
+ end
17
+
18
+ # Shifts +count+ elements from the array. Expects exactly +count+ elements
19
+ # in the array
20
+ def expect(count, message = nil)
21
+ self.size == count or inoa(message)
22
+ self
23
+ end
24
+
25
+ # Eats rest of the elements. Expects at least +min+ elements
26
+ def consume(count, message = nil)
27
+ self.size >= count or inoa(message)
28
+ self
29
+ end
30
+
31
+ private
32
+ def inoa(message = nil)
33
+ @shellopts.messenger.error(message || "Illegal number of arguments")
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,8 @@
1
1
 
2
2
  require "shellopts"
3
3
 
4
+ require "shellopts/args.rb"
5
+
4
6
  # TODO
5
7
  #
6
8
  # PROCESSING
@@ -78,8 +80,8 @@ module ShellOpts
78
80
  # Return a struct representation of the options. See {ShellOpts::OptionStruct}
79
81
  def to_struct(use: :key, aliases: {}) @idr.to_struct(use: use, aliases: aliases) end
80
82
 
81
- # List of remaining non-option command line arguments. Shorthand for +ast&.arguments+
82
- def args() @ast&.arguments end
83
+ # List of remaining non-option command line arguments. Returns a Argv object
84
+ def args() Args.new(self, ast&.arguments) end
83
85
 
84
86
  # Iterate options and commands as name/value pairs. Same as +to_a.each+
85
87
  def each(&block) to_a.each(&block) end
@@ -1,3 +1,3 @@
1
1
  module Shellopts
2
- VERSION = "2.0.0-1"
2
+ VERSION = "2.0.0-2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.1
4
+ version: 2.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
@@ -106,6 +106,7 @@ files:
106
106
  - doc/stylesheet.css
107
107
  - lib/ext/array.rb
108
108
  - lib/shellopts.rb
109
+ - lib/shellopts/args.rb
109
110
  - lib/shellopts/ast/command.rb
110
111
  - lib/shellopts/ast/node.rb
111
112
  - lib/shellopts/ast/option.rb