shellopts 2.0.5 → 2.0.6
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/lib/shellopts/formatter.rb +2 -2
- data/lib/shellopts/parser.rb +24 -0
- data/lib/shellopts/version.rb +1 -1
- data/lib/shellopts.rb +2 -5
- data/main +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52971494b88f77b6b66a95e8409de7cbebcbf030588089c395424b7e86f5e372
|
4
|
+
data.tar.gz: e00e482a0db690c2b7bd0861589a5179a67d7cec9b285ebcc1d2b5a7b6f73ff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2206c1e56c4239472bf5b697854fc4d7ba06bd9dedfe4eb2f86c2e115f4ddd52f66e9b4f47cbba41b1b4eafb08b8666b2115df7f70d769465dcb3e4a344d322a
|
7
|
+
data.tar.gz: f9bc90bdba87159a2821afb3c719ba4c4fbc7077601266d9e61c5f83273924bc23e9fa2208bf727855fc99b6acac09a97ec3dc58be179f649c9ed6dbb4fcc259
|
data/lib/shellopts/formatter.rb
CHANGED
@@ -200,8 +200,8 @@ module ShellOpts
|
|
200
200
|
# Number of characters between columns in brief output
|
201
201
|
BRIEF_COL_SEP = 2
|
202
202
|
|
203
|
-
#
|
204
|
-
BRIEF_COL1_MIN_WIDTH =
|
203
|
+
# Minimum width of first column in brief option and command lists
|
204
|
+
BRIEF_COL1_MIN_WIDTH = 20
|
205
205
|
|
206
206
|
# Maximum width of first column in brief option and command lists
|
207
207
|
BRIEF_COL1_MAX_WIDTH = 40
|
data/lib/shellopts/parser.rb
CHANGED
@@ -122,6 +122,22 @@ module ShellOpts
|
|
122
122
|
def self.parse(token)
|
123
123
|
super(nil, token)
|
124
124
|
end
|
125
|
+
|
126
|
+
def add_stdopts
|
127
|
+
option_token = Token.new(:option, 1, 1, "--version")
|
128
|
+
brief_token = Token.new(:brief, 1, 1, "Write version number and exit")
|
129
|
+
group = OptionGroup.new(self, option_token)
|
130
|
+
option = Option.parse(group, option_token)
|
131
|
+
brief = Brief.parse(group, brief_token)
|
132
|
+
|
133
|
+
option_token = Token.new(:option, 1, 1, "-h,help")
|
134
|
+
brief_token = Token.new(:brief, 1, 1, "Write help text and exit")
|
135
|
+
paragraph_token = Token.new(:text, 1, 1, "-h prints a brief help text, --help prints a longer man-style description of the command")
|
136
|
+
group = OptionGroup.new(self, option_token)
|
137
|
+
option = Option.parse(group, option_token)
|
138
|
+
brief = Brief.parse(group, brief_token)
|
139
|
+
paragraph = Paragraph.parse(group, paragraph_token)
|
140
|
+
end
|
125
141
|
end
|
126
142
|
|
127
143
|
class ArgSpec
|
@@ -146,6 +162,14 @@ module ShellOpts
|
|
146
162
|
@nodes = {}
|
147
163
|
end
|
148
164
|
|
165
|
+
# def add_stdopts
|
166
|
+
# version_token = Token.new(:option, 1, 1, "--version")
|
167
|
+
# version_brief = Token.new(:brief, 1, 1, "Gryf gryf")
|
168
|
+
# group = Grammar::OptionGroup.new(@program, version_token)
|
169
|
+
# option = Grammar::Option.parse(group, version_token)
|
170
|
+
# brief = Grammr::Brief.parse(option, version_brief)
|
171
|
+
# end
|
172
|
+
|
149
173
|
def parse()
|
150
174
|
@program = Grammar::Program.parse(@tokens.shift)
|
151
175
|
oneline = @tokens.first.lineno == @tokens.last.lineno
|
data/lib/shellopts/version.rb
CHANGED
data/lib/shellopts.rb
CHANGED
@@ -127,16 +127,13 @@ module ShellOpts
|
|
127
127
|
# Compile source and return grammar object. Also sets #spec and #grammar.
|
128
128
|
# Returns the grammar
|
129
129
|
def compile(spec)
|
130
|
-
if stdopts
|
131
|
-
spec += "\n--version\n Write version number and exit\n-h,help @ Write help text and exit\n Write help text. -h prints a brief text, --help prints a longer man-style description of the command"
|
132
|
-
end
|
133
130
|
handle_exceptions {
|
134
131
|
@oneline = spec.index("\n").nil?
|
135
132
|
@spec = spec.sub(/^\s*\n/, "")
|
136
133
|
@file = find_caller_file
|
137
134
|
@tokens = Lexer.lex(name, @spec, @oneline)
|
138
135
|
ast = Parser.parse(tokens)
|
139
|
-
|
136
|
+
ast.add_stdopts if stdopts
|
140
137
|
@grammar = Analyzer.analyze(ast)
|
141
138
|
}
|
142
139
|
self
|
@@ -197,7 +194,7 @@ module ShellOpts
|
|
197
194
|
saved = $stdout
|
198
195
|
$stdout = $stderr
|
199
196
|
$stderr.puts "#{name}: #{message}"
|
200
|
-
Formatter.usage(
|
197
|
+
Formatter.usage(grammar)
|
201
198
|
exit 1
|
202
199
|
ensure
|
203
200
|
$stdout = saved
|
data/main
CHANGED