78 Commits
Author SHA1 Message Date
Nobuyoshi Nakada f76ce9fd28 [ruby/optparse] Use ~/.config only if $XDG_CONFIG_HOME is unset or empty
https://github.com/ruby/optparse/commit/2f9c7500a3
2025-08-08 10:39:20 +00:00
Nobuyoshi Nakada deb0240ea0 [ruby/optparse] Expand literal home paths only
Paths in environment variables should already be expanded.
The base name of the program is also not subject to expansion.

https://github.com/ruby/optparse/commit/181752391c
2025-08-03 13:53:27 +00:00
Nobuyoshi Nakada 1619afb350 [ruby/optparse] Fallback HOME
https://github.com/ruby/optparse/commit/e0fdabf946
2025-08-03 13:53:27 +00:00
Nobuyoshi Nakada 9598ed9d1c [ruby/optparse] JRuby does not have EXECUTABLE_EXTS in RbConfg::CONFIG
https://github.com/ruby/optparse/commit/15b2f00b6b
2025-06-29 07:52:46 +00:00
Nobuyoshi Nakada 259b0233d8 [ruby/optparse] Fix OptionParser#program_name not to strip suffix unexpectedly
https://github.com/ruby/optparse/commit/740ffa76c0
2025-06-29 07:52:45 +00:00
kwatchandNobuyoshi Nakada 9fd793e0bd [ruby/optparse] Enhance to support 'Set' object as an enum
(https://github.com/ruby/optparse/pull/76)

* Enhance to support 'Set' object as an enum

* Add test script for '#make_swithc()'

---------

https://github.com/ruby/optparse/commit/3869000e98

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-06-29 07:30:58 +00:00
Nobuyoshi Nakada 8f19f0aad5 [ruby/optparse] Fix completion of key-value pairs array
Enum array may be the list of pairs of key and value.  Check if only
key is completable, not pair.

Fix https://github.com/ruby/optparse/pull/93
Fix https://github.com/ruby/optparse/pull/94

https://github.com/ruby/optparse/commit/a8d0ba8dac
2025-03-17 10:18:49 +00:00
Koichi ITO f4c16c57aa [ruby/optparse] Make the result of tty? obtainable with flexible stdout
In mock testing for stdout, `StringIO.new` is sometimes used to redirect the output.
In such cases, the assignment is done with `$stdout = StringIO.new`, not the constant `STDOUT`.
e.g., https://github.com/rubocop/rubocop/blob/v1.71.1/lib/rubocop/rspec/shared_contexts.rb#L154-L164

After assigning `StringIO.new`, `$stdout.tty?` returns `false`,
allowing the standard output destination to be switched during test execution.

```ruby
STDOUT.tty?       # => true
StringIO.new.tty? # => false
```

However, since `STDOUT.tty?` returns `true`, a failure occurred in environments
where the environment variables `RUBY_PAGER` or `PAGER` are set.
e.g., https://github.com/rubocop/rubocop/pull/13784

To address this, `STDOUT` has been updated to `$stdout` so that the result of `tty?` can be flexibly overridden.

A potential concern is that `$stdout`, unlike `STDOUT`,
does not always represent the standard output at the time the Ruby process started.
However, no concrete examples of issues related to this have been identified.

`STDOUT.tty?` is the logic of optparse introduced in https://github.com/ruby/optparse/pull/70.

This PR replaces `STDOUT` with `$stdout` throughout, based on the assumption
that `$stdout` is sufficient for use with optparse.

https://github.com/ruby/optparse/commit/262cf6f9ac
2025-03-10 10:19:58 +00:00
Nobuyoshi Nakada 9e265b583b [ruby/optparse] Add post-check of value
Fix https://github.com/ruby/optparse/pull/80

https://github.com/ruby/optparse/commit/050a87d029
2025-03-10 09:55:29 +00:00
Nobuyoshi Nakada cdf36d6bfd [ruby/optparse] Allow non-string enum list #79
Command line arguments are strings, convert enum list elements to
strings to match.

https://github.com/ruby/optparse/commit/c5ec052efc
2025-03-09 14:32:17 +00:00
Nobuyoshi Nakada 213c27825a [ruby/optparse] Add test for enum arguments
https://github.com/ruby/optparse/commit/0a0e977b7c
2025-03-09 14:32:17 +00:00
fatkodima a35d324862 [ruby/optparse] Fix parsing array arguments with :into option
https://github.com/ruby/optparse/commit/19700e96d8
2024-08-05 02:28:12 +00:00
Nobuyoshi Nakada 5d76fe6b2a [ruby/optparse] Invoke pager for --help
https://github.com/ruby/optparse/commit/77dccce37c
2024-03-01 07:10:08 +00:00
Nobuyoshi Nakada 41c0fb6991 [ruby/optparse] Add exact: keyword argument
https://github.com/ruby/optparse/commit/07e83673a8
2024-02-23 21:16:59 +09:00
Nobuyoshi Nakada db73226bf6 [ruby/optparse] Adjust arguments for lambda-callbacks
Rake uses [lambda] as callbacks.
Calling it without omitted argument raises an `ArgumentError`.

lambda: https://github.com/ruby/rake/blob/master/lib/rake/application.rb#L543

https://github.com/ruby/optparse/commit/213cb03b59
2024-02-09 19:58:31 +09:00
Nobuyoshi Nakada 2c6767b71e [ruby/optparse] Respect default values in block parameters
Fix https://github.com/ruby/optparse/pull/55

https://github.com/ruby/optparse/commit/9d53e74aa4
2024-02-09 19:58:19 +09:00
fatkodima f7a407cabd [ruby/optparse] Fix require_exact to work with options defined as --[no]-something
https://github.com/ruby/optparse/commit/4e346ad337
2024-02-09 03:31:13 +00:00
Junichi Ito cea6951ecf [ruby/optparse] Add symbolize_names to getopts
https://github.com/ruby/optparse/commit/3e63d878f8
2022-12-26 15:09:21 +09:00
Nobuyoshi Nakada 502ca37dde [ruby/optparse] The encoding argument of Regexp.new has been ignored since 1.9
https://github.com/ruby/optparse/commit/766f567405
2022-12-21 14:09:12 +09:00
Yusuke Endoh f3ad68dd16 [ruby/optparse] Fix the test failure i ruby/ruby
```
$ make test-all TESTS=test/optparse/
...

[148/178] TestOptionParserDidYouMean#test_raise_unknown = 0.00 s
  1) Failure:
TestOptionParserDidYouMean#test_raise_unknown [/home/mame/work/ruby/test/optparse/test_optparse.rb:106]:
<["--bar"]> expected but was
<[]>.
```

In the old test/unit (bundled in ruby/ruby), when a test class inherits from
another test class, the child class runs all the tests defined in the parent
class.
However, it looks like the new test/unit does not do so. This is because the
test failure does not occur in ruby/optparse.

As a tentative solution, this changes the option names in TestOptionParser to
avoid the name conflict with TestOptionParserDidYouMean.

https://github.com/ruby/optparse/commit/fee86ef7a4
2022-11-28 16:20:40 +00:00
Nobuyoshi Nakada 0bfb185654 [ruby/optparse] Add raise_unknown flag
(https://github.com/ruby/optparse/pull/38)

https://github.com/ruby/optparse/commit/12529653cd
2022-11-28 14:24:06 +00:00
Nobuyoshi Nakada d5fb76a6c8 [ruby/optparse] Add tests for load(into:)
https://github.com/ruby/optparse/commit/51f7e060ee
2022-10-29 13:47:23 +00:00
Nobuyoshi Nakada 4dac53f0a4 [ruby/optparse] Add tests for OptionParser#load
https://github.com/ruby/optparse/commit/fb34a1d3a3
2022-10-29 13:40:19 +00:00
Maciek Rząsa 0f231f2bab [ruby/optparse] Don't treat empty string as an option description
https://github.com/ruby/optparse/commit/078638ee6d
2022-10-08 19:30:34 +09:00
konsolebox 419ad1e13e [ruby/optparse] Also accept '-' as an optional argument (https://github.com/ruby/optparse/pull/35)
https://github.com/ruby/optparse/commit/f2b8318631
2022-07-29 19:10:10 +09:00
Jeremy Evans ab3cb29bd9 Avoid defining the same test class in multiple files
Should fix issues with parallel testing sometimes not running all
tests.

This should be viewed skipping whitespace changes.

Fixes [Bug #18731]
2022-04-22 15:00:16 -07:00
Nobuyoshi Nakada e28dbd0f3d [ruby/optparse] Fix for ruby 3.0 or earlier
https://github.com/ruby/optparse/commit/9e29d86c12
2022-01-12 21:16:02 +09:00
Nobuyoshi Nakada 743a41f7e3 [ruby/optparse] DidYouMean::PlainFormatter is deprecated
https://github.com/ruby/optparse/commit/0ac9957696
2022-01-12 21:16:02 +09:00
Yuki Nishijima 03c54a09ec Revert "Revert "Replace an deprecated constant with a new one in did_you_mean""
This reverts commit 1527f7569b.
2021-12-24 23:21:55 +09:00
Yuki Nishijima 1527f7569b Revert "Replace an deprecated constant with a new one in did_you_mean"
This reverts commit 573d9d3a4a.
2021-12-23 10:48:27 +09:00
Yuki Nishijima 573d9d3a4a Replace an deprecated constant with a new one in did_you_mean 2021-12-22 21:21:27 +09:00
Nobuyoshi Nakada b5d9c44267 [ruby/optparse] Fix typo [ci skip]
https://github.com/ruby/optparse/commit/0aa18752cf
2021-11-03 19:55:24 +09:00
Yuki Nishijima 905be49bf6 Remove the test for DYM's verbose formatter 2021-10-22 21:14:01 -04:00
Alexander Popov 2afbe7113a [ruby/optparse] Add EditorConfig file
More info here: https://editorconfig.org/

For example, `ruby/ruby` has it: https://github.com/ruby/ruby/blob/05ebaee/.editorconfig

Also fix some offenses.

https://github.com/ruby/optparse/commit/29402e7e0e
2021-04-28 11:56:15 +09:00
Nobuyoshi Nakada e8317d90b0 [ruby/optparse] Fixed error message of unparsed non-option
Close https://github.com/ruby/optparse/issues/3

https://github.com/ruby/optparse/commit/94c5cf4032
2021-03-29 19:37:24 +09:00
Jeremy Evans eca8ffaa0b [ruby/optparse] Add OptionParser#require_exact accessor
This allows you to disable allowing abbreviations of long options
and using short options for long options.

Implements Ruby Feature #11523

https://github.com/ruby/optparse/commit/dfefb2d2e2
2021-03-29 15:55:41 +09:00
Nobuyoshi Nakada 5ad32d5504 LoadError is not a subclass of StandardError 2019-11-29 11:25:23 +09:00
MSP-Greg 71ffe40a44 test/optparse/test_did_you_mean.rb - fix suggestion order 2019-10-21 09:53:56 +09:00
Nobuyoshi Nakada e2b719bed6 Support DidYouMean by AmbiguousOption too 2019-10-18 17:46:53 +09:00
Nobuyoshi Nakada e29e49abf0 Default DidYouMean.formatter to PlainFormatter 2019-10-18 16:43:40 +09:00
Nobuyoshi Nakada d4e52f672c Added no suggestion test case 2019-10-18 15:19:26 +09:00
Nobuyoshi Nakada 46fa301e82 Use DidYouMean.formatter
Instead of building messages separately.
2019-10-18 15:18:36 +09:00
Yusuke Endoh c3b64a86bc lib/optparse.rb: Show a did_you_mean hint for unknown option
```
require 'optparse'

OptionParser.new do |opts|
  opts.on("-f", "--foo", "foo") {|v| }
  opts.on("-b", "--bar", "bar") {|v| }
  opts.on("-c", "--baz", "baz") {|v| }
end.parse!
```

```
$ ruby test.rb --baa
Traceback (most recent call last):
test.rb:7:in `<main>': invalid option: --baa (OptionParser::InvalidOption)
Did you mean?  baz
               bar
```
2019-10-18 12:20:58 +09:00
Nobuyoshi Nakada ef45fd53e4 Fixed the test-case class name for zsh 2019-06-28 14:09:17 +09:00
Nobuyoshi Nakada c9b28fd7ae Allow --enable/--disable options to take an argument
[Bug #15850]
2019-05-15 17:31:11 +09:00
nobu 2ad7fb6dc1 optparse: Suppress warnings
Ruby warns "instance variable `@version` not initialized" for optparse when it receives `--version` option.

`test.rb`

```ruby
require 'optparse'
Version = '1'
OptionParser.new.parse(ARGV)
```

```
$ ruby -w test.rb --version
/home/pocke/.rbenv/versions/2.5.1/lib/ruby/2.5.0/optparse.rb:1168: warning: instance variable @version not initialized
/home/pocke/.rbenv/versions/2.5.1/lib/ruby/2.5.0/optparse.rb:1175: warning: instance variable @release not initialized
test 1
```

This change will suppress the warnings.

[Fix GH-1871]

From: Masataka Pocke Kuwabara <kuwabara@pocke.me>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-06 09:53:33 +00:00
nobu db1de35a31 optparse.rb: froze string literals
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-26 03:41:04 +00:00
nobu 30d23ec903 multiple arguments to write
Make write methods of IO-like objects accept multiple arguments,
as well as IO#write.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 14:05:07 +00:00
nobu 3fe5d355a8 optparse.rb: case-sensitive candidate
* lib/optparse.rb (candidate): short options are case-sensitive by
  the default, should not match case-different options..
  https://github.com/mernen/completion-ruby/pull/9#issuecomment-317287946

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-24 01:56:04 +00:00
nobu 89bf90a370 optparse.rb: get rid of eval
* lib/optparse.rb: try Float() and Integer() instead of eval,
  which does too much things.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-12 02:49:53 +00:00