Commit Graph

92 Commits

Author SHA1 Message Date
Etan Kissling 3c7c1cfc76
fail on error while processing `secondarySources` (#82)
The way how `secondarySources` are used in `status-im/nimbus-eth2`,
they call `addConfigFile` again which may raise `ConfigurationError`.
When that happened, loading the primary config file didn't result in
`fail`, which differs in error handling from errors within itself
as opposed to within `secondarySources`. To keep callers concise,
apply same error handling behaviour regardless of whether the error
occurred during primary or secondary sources processing.
2023-08-17 13:32:47 +02:00
Etan Kissling dbe8d61f7f
require `secondarySources` to be `gcsafe` (#86)
Avoid Nim 2.0 warning in callers of `confutils.load`.

```
Warning: 'loadImpl' is not GC-safe as it performs an indirect call via 'secondarySources' [GcUnsafe2]
```
2023-07-31 14:56:44 +02:00
Etan Kissling 7f17285d4e
restrict `parseCmdArgAux` to `ValueError` (#83)
Value parsers are currently allowed to raise `CatchableError`, but in
practice only `ValueError` is raised. Restrict to `ValueError`, and also
properly convert them to `fail` / `ConfigurationError` if applicable.
2023-06-12 16:25:39 +02:00
Etan Kissling b30f22da26
suppress unreachable string format errors (#81)
* suppress unreachable string format errors

We use `%` and `&` to format some strings, which may raise `ValueError`
if the format string is weird. As we are using them in ways that should
always succeed, catch those `ValueError` and convert to asserts.

* add `{.raises: [].}`
2023-06-09 19:16:55 +00:00
Etan Kissling 6c3566850d
catch exceptions in `appInvocation` (#78)
The `appInvocation` template in `confutils` is used while showing help,
e.g., before quitting. To ensure that `quit` actually happens, it can't
raise exceptions. Fix that by falling back to `""` on `OSError`.
2023-06-08 13:30:46 +00:00
Etan Kissling 50f744d821
handle `terminalWidth` exception (#80)
`terminalWidth()` may fail with a `ValueError` on out of range widths
from environment variables. Provide a suitable fallback.
2023-06-08 13:28:44 +00:00
Etan Kissling 4dbd23af3b
ignore exceptions while writing to stdout/stderr (#79)
`writeLine` can fail with `IOError`, and `styledWrite` when using colors
also with `ValueError`. To ensure that the control flow is unaffected,
simply ignore those errors while writing human-readable output to fds.
2023-06-08 13:26:06 +00:00
Etan Kissling 8522393cec
annotate `parseCmdArg` with `{.raises.}` (#84)
For the `parseCmdArg` that may fail with `ValueError`, add annotations.
2023-06-08 13:25:05 +00:00
tersec 1f3acaf6e9
remove support for Nim v1.2 and v1.4 (#75) 2023-05-31 15:37:01 +00:00
Adam Uhlíř 2028b41602
feat: integrate env. variable support natively (#70) 2023-04-19 12:54:48 +03:00
tersec c8063eb814
use correct check for Nim versions with BareExcept warning 2023-03-20 19:06:25 +00:00
Zahary Karadjov c4c11c52ce
Add a simple helper for writing tests involving config file contents 2023-03-14 17:24:38 +02:00
jangko 38dfeaaabd
reduce compiler warnings 2023-02-15 15:26:53 +07:00
Kim De Mey f6acc5e3da
Add custom Enum parser proc to keep Nim 1.2 behaviour for configs (#63) 2023-01-26 10:42:14 +01:00
tersec fc03a0c4e1
rm TaintedString for string; some proc -> func (#53)
* rm TaintedString for string; some proc -> func

* procs which interact with macros in certain ways can't be funcs in Nim 1.2
2022-06-03 18:24:59 +00:00
tersec a4f51237fc
add parseCmdArg tests; fix 64-bit int parsing on 32-bit platforms (#44) 2022-03-23 14:30:29 +02:00
Zahary Karadjov 585059d2fb
Remap serialization errors to ConfigurationError 2022-03-09 17:21:56 +02:00
Zahary Karadjov 0a88d30e00
Clean up the obsolete config loading code; Fix the tests 2022-03-05 15:07:57 +02:00
Zahary Karadjov 0fc26c5b25
Bugfixes for the config file support
- The config files processing was not taking into account the `name`
  pragma of the configuration object fields.

- The required fields were not searched within config files before
  reporting an error that they are missing.

- Fields with the same names were not supported in different case branches

- The loaded config file path can now depend on the configuration
  supplied through the command-line.
2022-03-04 23:24:58 +02:00
Kim De Mey 05a438414a
Enable --styleCheck:usages (#41) 2022-02-24 21:43:04 +01:00
jangko 6a56d01381 feature: add `ignore` property in addition to `hidden`
you can still set the value of a hidden option,
it just dont show up in the help text.

but using `ignore`, the is no chance you can set the value from cli.
2021-12-01 13:59:38 +02:00
jangko 0f4961822d feature: multiple lines long description
line break char: '\n', '\r'
example:
 -x, --name   regular description [=defVal].
              longdesc line one.
              longdesc line two.
              longdesc line three.

why additional pragma?
- to keep the default value not too far away from the 'name'.
2021-11-30 20:09:45 +02:00
jangko aa0ff5b0dc feature: separator text when displaying help
SEPARATOR:
-abbr, --name desc
-abbr, --name desc

---------
-abbr, --name desc
-abbr, --name desc
-abbr, --name desc
2021-09-08 15:56:51 +03:00
jangko 0cd09d75c8 add compile time check to detect duplicate abbr and duplicate name 2021-09-08 15:53:44 +03:00
Zahary Karadjov 6036a47000
Bugfix: parameters having empty strings as default values were treated as mandatory 2021-05-18 11:01:11 +03:00
Zahary Karadjov 4c19475a01
Bugfix: allow multiple positional arguments in sub-commands 2021-05-17 23:08:18 +03:00
Zahary Karadjov 5f7cfa8d98
Allow defaultValueDesc even without defaultValue; Cosmetic changes 2021-05-17 20:40:57 +03:00
Zahary Karadjov 5f2f882151
Print the values of invalid parameters in error messages 2021-05-17 19:52:35 +03:00
Zahary Karadjov bb6cbf6e0d
Display the default values of parameter in the help messages 2021-05-16 21:42:12 +03:00
Zahary Karadjov d1a45cfa9a
Some steps towards fixing #19 2021-05-16 19:13:06 +03:00
Zahary Karadjov c222804b3b
Support default values for seq[T] parameters 2021-05-16 17:49:56 +03:00
Zahary Karadjov cfa9566191
Allow setting hidden parameters from the command-line 2021-01-29 23:17:15 +02:00
Hanno Cornelius 282c7b1d9a
Added exporting of std/options 2020-11-18 09:15:48 +02:00
jangko f3a048f9ea config file integration into confutils 2020-11-02 16:17:51 +02:00
Ștefan Talpalaru 2e8040ec5e
allow repeating an option to override its value (#22)
./tests/cli_example --foo:1 --bar:a --withBaz --foo:2 --bar:boo --bar:hoo --withBaz:false
foo = 2
bar = hoo
baz = false
2020-09-30 14:13:44 +02:00
Zahary Karadjov 39456fa3d5
Hidden configuration fields (initial faux version) 2020-07-02 18:27:50 +03:00
Zahary Karadjov f9415621f8
Cosmetic improvement 2020-07-02 17:17:21 +03:00
Zahary Karadjov 686b22de48
Fix #16 2020-07-02 16:33:00 +03:00
Zahary Karadjov a76faa5eec
Wrap the help descriptions at line 80 (configurable) 2020-06-23 17:37:03 +03:00
Zahary Karadjov bea0769db0
Handle fully-qualified enum names used as Config branch values 2020-06-23 17:11:22 +03:00
Zahary Karadjov aac25d1610
Fix #18; Fix parsing of sub-commands with descriptions 2020-06-16 18:22:41 +03:00
Zahary Karadjov 6e5d570490
Another fix for Nim 1.2 2020-03-24 22:51:54 +02:00
Zahary Karadjov 24c73359b0
Add a helper module for handing IP addresses and ports 2020-03-16 23:47:48 +02:00
Zahary Karadjov f354a3ef61
Allow specifying a description for sub-commands 2020-03-10 13:38:29 +02:00
Zahary Karadjov 0bdfb3786c
Remove warnings with Nim 1.0 2019-12-02 23:31:29 +02:00
Zahary Karadjov 7a607bfd3d
Bugfix: help on errors was not produced for NimScript invocations 2019-11-12 12:07:29 +00:00
Zahary Karadjov 4e487bedf1
Tenative fix for yet another yearly binding problem 2019-11-12 00:33:20 +00:00
Zahary Karadjov b42717a73a
More renames for consistency 2019-11-11 16:10:28 +00:00
Zahary Karadjov 4ad95ce154
Cosmetic improvements 2019-11-11 15:05:22 +00:00
Zahary Karadjov 9863f80e96
Rename variables to match the renamed pragmas 2019-11-11 15:00:18 +00:00