diff --git a/CHANGELOG.md b/CHANGELOG.md index 6db30ab388b11eea62c1b7df6272252a0ecd0336..ced5fc670133e578c795e68ca4d02d1c5cdbaf63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,12 @@ This changelog follows the specifications detailed in: [Keep a Changelog](https: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), although we have not yet reached a `1.0.0` release. -## Version 0.7.14 - Unreleased +## Version 0.7.15 - Unreleased + +### Added +* Allow special options to be passed to cli + +## Version 0.7.14 - Released 2024-04-15 ### Changed * Better error messages when parsing argv diff --git a/scriptconfig/__init__.py b/scriptconfig/__init__.py index f2918436733aee27ec04115de2e0eb13033b92c9..1ac34f0ee4b24f03ae79a7607e794c9c83a63bb9 100644 --- a/scriptconfig/__init__.py +++ b/scriptconfig/__init__.py @@ -151,7 +151,7 @@ Ignore: mkinit ~/code/scriptconfig/scriptconfig/__init__.py --nomods --relative -w """ -__version__ = '0.7.14' +__version__ = '0.7.15' __submodules__ = { 'modal': None, diff --git a/scriptconfig/config.py b/scriptconfig/config.py index c07169ec0b798720212cc3094f90b5551b9ee39d..56c78618f4f7f479589470323e726f6f0850ed57 100644 --- a/scriptconfig/config.py +++ b/scriptconfig/config.py @@ -341,7 +341,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): @classmethod def cli(cls, data=None, default=None, argv=None, strict=True, - cmdline=True, autocomplete='auto'): + cmdline=True, autocomplete='auto', special_options=True): """ Create a commandline aware config instance. @@ -377,6 +377,10 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): autocomplete (bool | str): if True try to enable argcomplete. + + special_options (bool, default=True): + adds special scriptconfig options, namely: --config, --dumps, + and --dump. In the future this default will change to False. """ if cmdline and argv is not None: cmdline = argv @@ -390,7 +394,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): # prevents adding clean options for control flow. self = cls(_dont_call_post_init=True) self.load(data, cmdline=cmdline, default=default, strict=strict, - autocomplete=autocomplete) + autocomplete=autocomplete, special_options=special_options) return self @classmethod @@ -564,7 +568,8 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): self._alias_map = None def load(self, data=None, cmdline=False, mode=None, default=None, - strict=False, autocomplete=False, _dont_call_post_init=False): + strict=False, autocomplete=False, _dont_call_post_init=False, + special_options=True): """ Updates the configuration from a given data source. @@ -581,6 +586,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): If a list of strings that used instead of sys.argv. If a string, then that is parsed using shlex and used instead of sys.argv. + DO NOT USE dictionary form. It is deprecated. If a dictionary grants fine grained controls over the args passed to :func:`Config._read_argv`. Can contain: * strict (bool): defaults to False @@ -606,6 +612,10 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): if True, attempts to use the autocomplete package if it is available if reading from sys.argv. Defaults to False. + special_options (bool, default=False): + adds special scriptconfig options, namely: --config, --dumps, + and --dump. Prefer using this over cmdline. + Note: if cmdline=True, this will create an argument parser. @@ -738,12 +748,15 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig): # should override them IF they exist on in sys.argv, but not if # they don't? read_argv_kwargs = { - 'special_options': True, + 'special_options': special_options, 'strict': strict, 'autocomplete': autocomplete, 'argv': None, } if isinstance(cmdline, dict): + ub.schedule_deprecation('scriptconfig', 'cmdline', 'parameter as a dictionary', + migration='The API should expose any special params explicitly', + deprecate='0.7.15', error='0.8.0', remove='0.9.0') read_argv_kwargs.update(cmdline) elif ub.iterable(cmdline) or isinstance(cmdline, str): read_argv_kwargs['argv'] = cmdline diff --git a/scriptconfig/value.py b/scriptconfig/value.py index 7b8c42e185dc8c8d235e5b4cbe0a670695a4e75f..3ddf5353fd1b9a1f1f923b70e6980a4645889152 100644 --- a/scriptconfig/value.py +++ b/scriptconfig/value.py @@ -56,7 +56,7 @@ class Value(ub.NiceRepr): short_alias (List[str] | None): other short names (that will be prefixed with '-') that will be - accepted by the argparse CLI. + accepted by the argparse CLI. e.g. ``short_alias=['n']`` group (str | None): Impacts display of underlying argparse object by grouping values