shellopts 2.0.5 → 2.0.6

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: a3a8b18b0a610c14ac4a85f80cd70ff5f85ca7dc868b25615a67a3ad71f737b5
4
- data.tar.gz: 2b0442868d8ddf102a5f8ee1b3d3307ecbea17a95512f5164d4a64a9d3fa9ec7
3
+ metadata.gz: 52971494b88f77b6b66a95e8409de7cbebcbf030588089c395424b7e86f5e372
4
+ data.tar.gz: e00e482a0db690c2b7bd0861589a5179a67d7cec9b285ebcc1d2b5a7b6f73ff7
5
5
  SHA512:
6
- metadata.gz: c90ab9e0049ba64e21c2b0fd408b438df84c0265fced52b84d221bdb2b96f92e75624c00ab59526c9caa80f67e2e7d55c5bcf0cb8138b803722b424e08ea9202
7
- data.tar.gz: 372e29956c8f3e27f8f5617215cf610403d40a307257c0c63605e94bd39fffaa8bf9cb165e82fe61497fcc8f0519c4298c1bf4480fa26735f5bf5c01e12fe8e2
6
+ metadata.gz: 2206c1e56c4239472bf5b697854fc4d7ba06bd9dedfe4eb2f86c2e115f4ddd52f66e9b4f47cbba41b1b4eafb08b8666b2115df7f70d769465dcb3e4a344d322a
7
+ data.tar.gz: f9bc90bdba87159a2821afb3c719ba4c4fbc7077601266d9e61c5f83273924bc23e9fa2208bf727855fc99b6acac09a97ec3dc58be179f649c9ed6dbb4fcc259
@@ -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
- # Maximum width of first column in brief option and command lists
204
- BRIEF_COL1_MIN_WIDTH = 6
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  end
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
- # TODO: Add standard and message options and their handlers
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(program)
197
+ Formatter.usage(grammar)
201
198
  exit 1
202
199
  ensure
203
200
  $stdout = saved
data/main CHANGED
@@ -9,7 +9,9 @@ include ShellOpts
9
9
 
10
10
  VERSION = "1.2.3"
11
11
 
12
- SPEC = "-a"
12
+ SPEC = %(
13
+ -a @ An option
14
+ )
13
15
  opts, args = ShellOpts::process(SPEC, ARGV, version: VERSION)
14
16
  #ShellOpts::ShellOpts.help
15
17
 
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.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen