shellopts 2.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shellopts/analyzer.rb +5 -2
- data/lib/shellopts/args.rb +10 -3
- data/lib/shellopts/grammar.rb +8 -0
- data/lib/shellopts/interpreter.rb +1 -1
- data/lib/shellopts/lexer.rb +2 -2
- data/lib/shellopts/parser.rb +2 -1
- data/lib/shellopts/version.rb +1 -1
- data/shellopts.gemspec +7 -6
- metadata +6 -8
- data/.gitignore +0 -30
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c52f313fee54283e1d5e704dd8b75a96239db6cff70584eefe747cf56270c1
|
4
|
+
data.tar.gz: 67b50b7b3a993bf77533246c9634ce7850d765891381244fedf2b1ecf3f6bc76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf5cd91d92bce24b1d04a3a526d6f43f8fe761f760319bf60191e2e638c3301fdbf9c63aa9f465aa8755cd18aa56293f0ae68e01870d6a877928bc1c0eebf5c
|
7
|
+
data.tar.gz: 0e1fa649cff6a072d676a33dab6a3cbb038cb6799b59088f7ebff1144e6983843fe16658c80fa75308f057caf24e5b232aea15c92f80290d0969d868e653159e
|
data/lib/shellopts/analyzer.rb
CHANGED
@@ -28,10 +28,13 @@ module ShellOpts
|
|
28
28
|
@options = option_groups.map(&:options).flatten
|
29
29
|
end
|
30
30
|
|
31
|
-
# Move options before first command
|
31
|
+
# Move options before first command or before explicit COMMAND section
|
32
32
|
def reorder_options
|
33
33
|
if commands.any?
|
34
|
-
|
34
|
+
i = children.find_index { |child|
|
35
|
+
child.is_a?(Command) || child.is_a?(Section) && child.name == "COMMAND"
|
36
|
+
}
|
37
|
+
if i
|
35
38
|
options, rest = children[i+1..-1].partition { |child| child.is_a?(OptionGroup) }
|
36
39
|
@children = children[0, i] + options + children[i..i] + rest
|
37
40
|
end
|
data/lib/shellopts/args.rb
CHANGED
@@ -5,6 +5,11 @@ module ShellOpts
|
|
5
5
|
# methods raise a ShellOpts::Error exception in case of errors
|
6
6
|
#
|
7
7
|
class Args < Array
|
8
|
+
def initialize(*args, exception: false)
|
9
|
+
super(*args)
|
10
|
+
@exception = exception
|
11
|
+
end
|
12
|
+
|
8
13
|
# :call-seq:
|
9
14
|
# extract(count, message = nil)
|
10
15
|
# extract(range, message = nil)
|
@@ -21,7 +26,7 @@ module ShellOpts
|
|
21
26
|
# #extract raise a ShellOpts::Error exception if there's is not enough
|
22
27
|
# elements in the array to satisfy the request
|
23
28
|
#
|
24
|
-
def extract(count_or_range, message = nil)
|
29
|
+
def extract(count_or_range, message = nil)
|
25
30
|
case count_or_range
|
26
31
|
when Range
|
27
32
|
range = count_or_range
|
@@ -59,8 +64,10 @@ module ShellOpts
|
|
59
64
|
end
|
60
65
|
|
61
66
|
private
|
62
|
-
def inoa(message = nil)
|
63
|
-
|
67
|
+
def inoa(message = nil)
|
68
|
+
message ||= "Illegal number of arguments"
|
69
|
+
raise Error, message if @exception
|
70
|
+
::ShellOpts.error(message)
|
64
71
|
end
|
65
72
|
end
|
66
73
|
end
|
data/lib/shellopts/grammar.rb
CHANGED
@@ -151,6 +151,10 @@ module ShellOpts
|
|
151
151
|
class OptionGroup < Node
|
152
152
|
alias_method :command, :parent
|
153
153
|
|
154
|
+
# Duck typing for compatibility with IdrNode (TODO: maybe just make
|
155
|
+
# OptionGroup an IdrNode and be over with it)
|
156
|
+
def name() options.first&.name end
|
157
|
+
|
154
158
|
# Array of options in declaration order
|
155
159
|
attr_reader :options
|
156
160
|
|
@@ -352,6 +356,10 @@ module ShellOpts
|
|
352
356
|
end
|
353
357
|
|
354
358
|
class Section < Node
|
359
|
+
def initialize(parent, token)
|
360
|
+
constrain token.source, *%w(DESCRIPTION OPTION COMMAND)
|
361
|
+
super
|
362
|
+
end
|
355
363
|
def name() token.source end
|
356
364
|
end
|
357
365
|
|
data/lib/shellopts/lexer.rb
CHANGED
@@ -45,7 +45,7 @@ module ShellOpts
|
|
45
45
|
# Match ArgDescr words (should be at least two characters long)
|
46
46
|
DESCR_RE = /^[^a-z]{2,}$/
|
47
47
|
|
48
|
-
SECTIONS = %w(DESCRIPTION OPTIONS COMMANDS)
|
48
|
+
SECTIONS = %w(DESCRIPTION OPTION OPTIONS COMMAND COMMANDS)
|
49
49
|
|
50
50
|
using Ext::Array::ShiftWhile
|
51
51
|
|
@@ -109,7 +109,7 @@ module ShellOpts
|
|
109
109
|
|
110
110
|
# Sections
|
111
111
|
elsif SECTIONS.include?(line.text)
|
112
|
-
@tokens << Token.new(:section, line.lineno, line.charno, line.text)
|
112
|
+
@tokens << Token.new(:section, line.lineno, line.charno, line.text.sub(/S$/, ""))
|
113
113
|
|
114
114
|
# Options, commands, usage, arguments, and briefs
|
115
115
|
elsif line =~ DECL_RE
|
data/lib/shellopts/parser.rb
CHANGED
@@ -132,7 +132,8 @@ module ShellOpts
|
|
132
132
|
|
133
133
|
option_token = Token.new(:option, 1, 1, "-h,help")
|
134
134
|
brief_token = Token.new(:brief, 1, 1, "Write help text and exit")
|
135
|
-
paragraph_token = Token.new(:text, 1, 1,
|
135
|
+
paragraph_token = Token.new(:text, 1, 1,
|
136
|
+
"-h prints a brief help text, --help prints a longer man-style description of the command")
|
136
137
|
group = OptionGroup.new(self, option_token)
|
137
138
|
option = Option.parse(group, option_token)
|
138
139
|
brief = Brief.parse(group, brief_token)
|
data/lib/shellopts/version.rb
CHANGED
data/shellopts.gemspec
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "shellopts/version"
|
2
|
+
require_relative "lib/shellopts/version"
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
5
|
spec.name = "shellopts"
|
@@ -15,15 +13,18 @@ Gem::Specification.new do |spec|
|
|
15
13
|
and has built-in help and error messages}
|
16
14
|
spec.homepage = "http://github.com/clrgit/shellopts"
|
17
15
|
|
18
|
-
spec.files
|
19
|
-
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
19
|
+
end
|
20
20
|
end
|
21
|
+
|
21
22
|
spec.bindir = "exe"
|
22
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
24
|
spec.require_paths = ["lib"]
|
24
25
|
|
25
26
|
spec.add_dependency "forward_to"
|
26
|
-
spec.add_dependency "constrain"
|
27
|
+
spec.add_dependency "constrain", "~> 0.5.1"
|
27
28
|
spec.add_dependency "ruby-terminfo"
|
28
29
|
spec.add_dependency "indented_io"
|
29
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellopts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forward_to
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: constrain
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.5.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-terminfo
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,10 +132,8 @@ executables: []
|
|
132
132
|
extensions: []
|
133
133
|
extra_rdoc_files: []
|
134
134
|
files:
|
135
|
-
- ".gitignore"
|
136
135
|
- ".rspec"
|
137
136
|
- ".ruby-version"
|
138
|
-
- ".travis.yml"
|
139
137
|
- Gemfile
|
140
138
|
- README.md
|
141
139
|
- Rakefile
|
data/.gitignore
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/rdoc/
|
5
|
-
/pkg/
|
6
|
-
/spec/reports/
|
7
|
-
/tmp/
|
8
|
-
|
9
|
-
# rspec failure tracking
|
10
|
-
.rspec_status
|
11
|
-
|
12
|
-
# simplecov
|
13
|
-
/coverage/
|
14
|
-
|
15
|
-
# Ignore Gemfile.lock. See https://stackoverflow.com/questions/4151495/should-gemfile-lock-be-included-in-gitignore
|
16
|
-
/Gemfile.lock
|
17
|
-
|
18
|
-
# Ignore vim files
|
19
|
-
.*.swp
|
20
|
-
|
21
|
-
# Ignore t.* files
|
22
|
-
t
|
23
|
-
t.*
|
24
|
-
tt
|
25
|
-
tt.*
|
26
|
-
s
|
27
|
-
s.*
|
28
|
-
|
29
|
-
# Ignore temporary directory
|
30
|
-
/spec/tmpdir/
|