shellopts 2.4.1 → 2.4.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
2
  SHA256:
3
- metadata.gz: 53f85a46df1cf2280e591fbf996781c73e3ddb3dfe88ede023f6ef29f26995a4
4
- data.tar.gz: 0ffb37c5f3843e92676004994600687dec0db89afccd20dea984998692e160a8
3
+ metadata.gz: 4620f77a96e0e880d03301d91100824186c02ec20b68ffa22ff7032bb3b269d2
4
+ data.tar.gz: 628d2c0653ac9d565a860bb5941bc1ca9cf4c13c6d5709e78b355d4183c4d48b
5
5
  SHA512:
6
- metadata.gz: e67de152c69ae86557ec6898e7b0402d4188b8ca57a53128cfd7b3521655e80aadbc6114bcf943101f1a4012216604703dba54ae2a6921019d228b0b343b1837
7
- data.tar.gz: bfe12de981b2504514cd42c81f64511d01fe7948d1d8a563b2f34473d30fa8cd7e5cc22f550e9e81bd3a31ff3da863adbc60dd33ffd9fed53ea69d0bc8907a62
6
+ metadata.gz: 691e8376f9b28bfdce08cbaf64fb2cf871d09417992433f4e48b77288e1b5ccf2cc049328607e8b94e35222e631fd29c01b96bb71602bc053ab4ce1ab1b435db
7
+ data.tar.gz: 44fe34f706f91a8cee7df43a48032a97ed31fd315e04edf7c5f6a2842a61bcb010663fc63ad78da38607342b90d8617c266f0b9e56e2c70fa6d3c7befcf9f10d
data/README.md CHANGED
@@ -193,7 +193,6 @@ indicate that the option can be repeated
193
193
  --gamma=ARG? @ --gamma, takes an optional argument
194
194
  ```
195
195
 
196
-
197
196
  An option argument has a name and a type. The type can be specified as '#'
198
197
  (integer), '$' (float), or as a comma-separated list of allowed values. It can
199
198
  also be defined by a keyword that expects a file or directory argument:
@@ -202,15 +201,17 @@ also be defined by a keyword that expects a file or directory argument:
202
201
  | --------- | ---- |
203
202
  | FILE | A file if present or in an existing directory if not |
204
203
  | DIR | A directory if present or in an existing directory if not |
205
- | PATH | Either a FILE or DIR |
204
+ | PATH | FILE or DIR |
206
205
  | EFILE | An existing file |
207
206
  | EDIR | An existing directory |
208
- | EPATH | Either an EFILE or EDIR |
207
+ | EPATH | EFILE or EDIR |
209
208
  | NFILE | A new file |
210
209
  | NDIR | A new directory |
211
- | NPATH | A new file or directory |
210
+ | NPATH | NFILE or NDIR |
211
+
212
212
 
213
- By default the option name is inferred from the type but it can be specified explicitly by separating it from the type with a ':'. Examples:
213
+ By default the option name is inferred from the type but it can be specified
214
+ explicitly by separating it from the type with a ':'. Examples:
214
215
 
215
216
  ```
216
217
  -a=# @ -a takes an integer argument
@@ -244,7 +245,7 @@ In single-line format, subcommands are specified by prefixing the supercommand's
244
245
 
245
246
  ## Example
246
247
 
247
- The rm(1) command could be specified like this:
248
+ The standard rm(1) command could be specified like this:
248
249
 
249
250
  ```ruby
250
251
 
data/TODO CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ o Remove IFILE and OFILE. Alternatively document them
3
+ o Document special-case file argument '-'
4
+ o Accept both strings and symbols for commands (maybe... ruins the global namespace in #[])
5
+ o ShellOpts#command -> Full path. Eg. ':command.subcommand!'
6
+ ShellOpts#commands -> Array of commands. Eg. [:command!, :subcommand!]
7
+ o Exclude -h, -v, and -q from short description and only include them in the
8
+ detailed option description
9
+ o Output handling: mesg, verb, ... should record eols. error and failure should
10
+ use that to end the current line with a newline if necessary
11
+ o Strings from ShellOpts are frozen. Is that what we want?
2
12
  o Assigner methods for options
3
13
  o Make opts[] point at the main object
4
14
  opts[].subcommand is the direct subcommand of main
@@ -26,7 +26,7 @@ module ShellOpts
26
26
  def to_s() name end
27
27
 
28
28
  protected
29
- # it is important that #set_message return false
29
+ # Note that it is important that #set_message return false
30
30
  def set_message(msg)
31
31
  @message = msg
32
32
  false
@@ -63,7 +63,8 @@ module ShellOpts
63
63
  def subject # Used in error messages
64
64
  @subject ||=
65
65
  case kind
66
- when :file, :efile, :nfile, :ifile, :ofile; "file"
66
+ when :file, :efile; "regular file"
67
+ when :nfile, :ifile, :ofile; "file"
67
68
  when :dir, :edir, :ndir; "directory"
68
69
  when :path, :epath, :npath; "path"
69
70
  else
@@ -81,19 +82,18 @@ module ShellOpts
81
82
  if literal == '-' && [:ifile, :ofile].include?(kind)
82
83
  true
83
84
 
84
- # Special-case standard I/O files
85
+ # Special-case standard I/O files. These files have read-write (rw)
86
+ # filesystem permissions so they need to be handled individually
85
87
  elsif %w(/dev/stdin /dev/stdout /dev/stderr /dev/null).include?(literal)
86
88
  case kind
87
89
  when :file, :path, :efile, :epath, :nfile, :npath
88
90
  true
89
91
  when :ifile
90
- %w(/dev/stdin /dev/null).include? literal or
91
- set_message "Can't read #{literal}"
92
+ %w(/dev/stdin /dev/null).include? literal or set_message "Can't read #{literal}"
92
93
  when :ofile
93
- %w(/dev/stdout /dev/stderr /dev/null).include?(literal) or
94
- set_message "Can't write to #{literal}"
94
+ %w(/dev/stdout /dev/stderr /dev/null).include?(literal) or set_message "Can't write to #{literal}"
95
95
  when :dir, :edir, :ndir
96
- set_message "Expected file, got directory #{literal}"
96
+ set_message "#{literal} is not a directory"
97
97
  else
98
98
  raise ArgumentError, "Unhandled kind: #{kind.inspect}"
99
99
  end
@@ -139,44 +139,47 @@ module ShellOpts
139
139
 
140
140
  protected
141
141
  def match_path(name, literal, kind, method, mode)
142
- # file exists and is the rigth type?
142
+ # file exists and the method returned true
143
143
  if File.send(method, literal)
144
144
  if mode == :new
145
- set_message "#{subject.capitalize} already exists in #{name}: #{literal}"
145
+ set_message "Won't overwrite #{literal}"
146
146
  elsif kind == :path || kind == :epath
147
147
  if File.file?(literal) || File.directory?(literal)
148
148
  true
149
149
  else
150
- set_message "Expected file or directory as #{name} argument: #{literal}"
150
+ set_message "#{literal} is not a file or a directory"
151
151
  end
152
152
  elsif (kind == :ifile || kind == :ofile) && File.directory?(literal)
153
- set_message "File expected, got directory: #{literal}"
153
+ set_message "#{literal} is not a device file"
154
154
  else
155
155
  true
156
156
  end
157
157
 
158
- # file exists but not the right type?
158
+ # file exists but the method returned false
159
159
  elsif File.exist?(literal)
160
160
  if kind == :ifile
161
161
  set_message "Can't read #{literal}"
162
162
  elsif kind == :ofile
163
163
  set_message "Can't write to #{literal}"
164
164
  elsif mode == :new
165
- set_message "#{subject.capitalize} already exists - #{literal}"
165
+ set_message "Won't overwrite #{literal}"
166
166
  else
167
- set_message "Expected #{subject} as #{name} argument: #{literal}"
167
+ set_message "#{literal} is not a #{subject}"
168
168
  end
169
169
 
170
170
  # file does not exist
171
171
  else
172
172
  if [:default, :new].include? mode
173
- if File.exist?(File.dirname(literal)) || kind == :ofile
174
- true
173
+ dir = File.dirname(literal)
174
+ if !File.directory?(dir)
175
+ set_message "Illegal path - #{literal}"
176
+ elsif !File.writable?(dir)
177
+ set_message "Can't create #{subject} #{literal}"
175
178
  else
176
- set_message "Illegal path in #{name}: #{literal}"
179
+ true
177
180
  end
178
181
  else
179
- set_message "Can't find #{subject} #{literal}"
182
+ set_message "Can't find #{literal}"
180
183
  end
181
184
  end
182
185
  end
@@ -185,7 +188,7 @@ module ShellOpts
185
188
  class EnumArgument < ArgumentType
186
189
  attr_reader :values
187
190
  def initialize(values) @values = values.dup end
188
- def match?(name, literal) value?(literal) or set_message "Illegal value in #{name}: '#{literal}'" end
191
+ def match?(name, literal) value?(literal) or set_message "Illegal value - #{literal}" end
189
192
  def value?(value) @values.include?(value) end
190
193
  end
191
194
  end
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.3"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -448,24 +448,36 @@ module ShellOpts
448
448
  # Emit a message on standard error. The --silent option suppresses these messages
449
449
  def self.notice(message, newline: true)
450
450
  method = newline ? :puts : :print
451
- $stderr.send(method, message) if !silent?
451
+ if !silent?
452
+ $stderr.send(method, message)
453
+ $stderr.flush
454
+ end
452
455
  end
453
456
 
454
457
  # Emit a message on standard output. The --quiet option suppresses these messages
455
458
  def self.mesg(message, newline: true)
456
459
  method = newline ? :puts : :print
457
- $stdout.send(method, message) if !quiet?
460
+ if !quiet?
461
+ $stdout.send(method, message)
462
+ $stdout.flush
463
+ end
458
464
  end
459
465
 
460
466
  # Emit a message on standard output. The --verbose option controls these messages
461
467
  def self.verb(level = 1, message, newline: true)
462
468
  method = newline ? :puts : :print
463
- $stdout.send(method, message) if verbose?(level)
469
+ if verbose?(level)
470
+ $stdout.send(method, message)
471
+ $stdout.flush
472
+ end
464
473
  end
465
474
 
466
475
  def self.debug(message, newline: true)
467
476
  method = newline ? :puts : :print
468
- $stdout.send(method, message) if debug?
477
+ if debug?
478
+ $stdout.send(method, message)
479
+ $stdout.flush
480
+ end
469
481
  end
470
482
 
471
483
  module Message
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.4.1
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-10 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forward_to
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
- rubygems_version: 3.3.18
176
+ rubygems_version: 3.3.7
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Parse command line options and arguments