Commit Graph
66 Commits
Author SHA1 Message Date
Leandro Pereira c760a5a4af Add :return_separator to OptionParser (#12499) 2023-03-28 18:12:33 +02:00
Maarten van Vliet 44d75edde1 Handle dashes in option error suggestion (#11133) 2021-07-22 10:06:23 +02:00
Maarten van Vliet fbb224467f Add did you mean to error for unfound CLI option (#11129)
I typed `mix test --fauled` repeatedly and found the error could
be improved. This change adds the `did you mean` suggestion with the
most likely match to the error message.

The `0.8` cutoff is pulled from the exceptions.ex file.
2021-07-21 13:33:03 +02:00
Wojtek Mach 94ac32962f OptionParser.parse/2: Validate switch types/modifiers (#11019) 2021-05-28 14:07:58 +02:00
Eksperimental 02c72c0f84 Standardize use of key-value pair (#10676) 2021-01-26 15:25:47 +01:00
José Valim 7a747694b4 Throughout reject aliases starting with numbers 2020-11-20 09:18:58 +01:00
José Valim 1a3a0a36e8 Properly expand option aliases followed by numbers 2020-11-20 09:00:51 +01:00
José Valim 97076019e4 Add async: true to tests using capture_io :stderr 2019-11-15 10:00:16 +01:00
José Valim cb236a3f06 Move some runtime deprecations to compile time
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2018-07-19 22:42:14 +02:00
José Valim 151e00390b Do not raise if switches option finds an undefined switch
Otherwise the code may fail or not depending on the modules
loaded. The current code simply ignores whatever it is not
listed.

This commit also refactored the docs and tests.
2018-02-20 12:22:12 +01:00
Unai Esteibar 971a869c7f Deprecate dynamic mode in OptionParser and promote strict (#7366)
Fixes #7278
2018-02-20 10:32:51 +01:00
José Valim dec9e6f0a8 Improvements to previously formatted files 2017-10-11 22:59:30 +02:00
Tobiasz Małecki 09e1d28804 Run code formatter on lib/elixir/test/elixir/option_parser_test.exs (#6913) 2017-10-11 22:31:40 +02:00
Aleksei Magusev 499a432ad6 Fix "floating-point" spelling 2017-05-21 13:01:56 +02:00
Eksperimental 5121ca2d1d Add test for OptionParser.parse/2 when it raises (#5838) 2017-03-05 11:08:16 +01:00
Andrew Dryga 0364610f73 Fix code style in tests for OptionParser (#5714) 2017-01-29 00:51:50 +01:00
Andrew Dryga 2e8f8ed6b4 Implement allow_inexistent_atoms for OptionParser (#5709) 2017-01-28 22:40:09 +01:00
Aleksei Magusev 13b609ac9b Minor grammar fixes 2016-12-11 13:12:09 +01:00
Aleksei Magusev 01fa419f01 Minor improvements around OptionParser.to_argv/2 2016-11-09 20:43:02 +01:00
Muaaz Saleem 26af1f7d72 Fixing :count support in OptionParser.to_argv (#5394) 2016-11-02 11:46:29 +01:00
Aleksei Magusev 5efd42cf28 Rename args -> argv in OptionParserTest 2016-08-13 14:08:37 +02:00
Aleksei Magusev 70f30c9df2 Use String.to_existing_atom/1 for option conversion (#5134) 2016-08-13 14:06:48 +02:00
Andrea Leopardi fea9f550b7 Expand multi-letter aliases in OptionParser (#5025)
Before this commit, -abc was processed by OptionParser as an alias.
With this commit, we deprecate this behaviour: if -abc still matches
an alias, we warn, otherwise, we split it into -a -b -c.
2016-07-20 10:39:52 +02:00
José Valim 150b93a3e5 InvalidOptionError becomes ParseError 2016-05-21 21:18:50 +02:00
Milton Mazzarri 518907d86e Add parse!/2 and parse_head!/2 to OptionParser
Improve OptionParser to have a bang alternative for `parse/2` and
`parse_head/2`, this new functions will raise an
`OptionParser.InvalidOptionError` exception if any invalid option were
encountered.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-05-21 19:49:07 +02:00
Mr C0B a432342449 improve option_parser.ex to support counter 🐝 (#4412) 2016-05-21 19:05:25 +02:00
Brandon Shroyer e88bd726a8 Allow OptionParser to parse negative numbers
* Correctly parse negative numbers as arguments in OptionParser

* Correctly parse negative integers as option values in OptionParser

* Add additional OptionParser tests for negative floating point numbers

* Add negative number tests for double-dash options in OptionParser
2016-04-03 09:24:53 +02:00
Aleksei Magusev 742e36c35d Make import with conflicting options to raise 2015-12-07 21:01:28 +01:00
Joe Yates f30f77714d Raise error for incompatible OptionParser options
* supplying :switch together with :strict raises an error.
* closes #4035.
2015-12-03 00:32:45 +01:00
Aleksei Magusev a92b6ee4a5 Move doctests from central place to the modules they describe 2015-11-25 00:26:07 +01:00
José Valim 8cfc67e5eb Add OptionParser.to_argv/1 2014-07-16 22:22:02 +02:00
José Valim 9326e4ea3a Add OptionParser.split/1 2014-07-10 17:58:19 +02:00
José Valim a1a3f0d42c Only accept --no-SWITCH for booleans
The previous behaviour was confusing and a special case.
This enables negated switches only for booleans, otherwise
it is considered as a regular switch (as the combination
of --no-SWITCH for any other type is an error anyway).
2014-07-10 14:05:49 +02:00
Alexei Sholik e942c07f34 Do not allow underscores in option names. Closes #2391 2014-06-12 19:26:47 +03:00
Alexei Sholik 4cc28c2e8c Return invalid options as strings 2014-05-22 00:05:41 +03:00
José Valim 927594bb14 Always return nil for undefined options (#2308) 2014-05-21 21:09:01 +02:00
Alexei Sholik a9375903ae Do not assume invalid options are of boolean type 2014-05-21 17:36:19 +03:00
Alexei Sholik fb2686fe37 Parse "-" as a plain argument 2014-05-21 13:55:28 +03:00
José Valim cb0c3d8a2a Support :strict option on parse and improve return types 2014-05-21 11:50:11 +02:00
Alexei Sholik 142ebc3ecd Fix handling of boolean options with bad values 2014-05-20 17:32:12 +03:00
Alexei Sholik 339c57f1c6 Fix value normalization in strict mode 2014-05-20 17:32:12 +03:00
Aleksei Magusev c0bc64fb19 Change OptionParser to remove the end of command options (--) 2014-05-20 12:49:10 +04:00
Alexei Sholik 24c17c350c Format OptionParser tests more nicely 2014-05-12 21:27:44 +03:00
Alexei Sholik 2187db5415 Don’t ignore values for ‘--no-*’ options 2014-05-12 21:24:31 +03:00
Alexei Sholik 84cdbe3562 Add more sanity-check tests for OptionParser 2014-05-12 21:24:31 +03:00
Alexei Sholik 95ed007b1c Properly handle non-boolean values for boolean options 2014-05-12 21:24:31 +03:00
Aleksei Magusev 698d1f6440 Fix handling of end of command options (--) in OptionParser 2014-05-10 20:10:23 +04:00
José Valim d53a6a3491 Ensure string switches are not treated as booleans, closes #2218 2014-04-30 12:48:39 +02:00
José Valim 56f15d9f4e Do not add spaces after { and before }
This makes the source code consistent with the result
returned by inspect/2.
2014-04-21 19:06:35 +02:00
José Valim fd8859abdd Do not recognize undefined aliases as switches 2014-02-17 15:52:44 +01:00