How to use the jsonargparse.ArgumentParser function in jsonargparse

To help you get started, we’ve selected a few jsonargparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Solvik / netbox_agent / netbox_agent / config.py View on Github external
def get_config():
    p = jsonargparse.ArgumentParser(
        default_config_files=[
            '/etc/netbox_agent.yaml',
            '~/.config/netbox_agent.yaml',
            '~/.netbox_agent.yaml',
        ],
        prog='netbox_agent',
        description="Netbox agent to run on your infrastructure's servers",
        env_prefix='NETBOX_AGENT_',
        default_env=True
    )
    p.add_argument('-c', '--config', action=jsonargparse.ActionConfigFile)

    p.add_argument('-r', '--register', action='store_true', help='Register server to Netbox')
    p.add_argument('-u', '--update-all', action='store_true', help='Update all infos in Netbox')
    p.add_argument('-d', '--debug', action='store_true', help='Print debug infos')
    p.add_argument('--update-network', action='store_true', help='Update network')
github omni-us / jsonargparse / jsonargparse.py View on Github external
def merge_config(cfg_from:SimpleNamespace, cfg_to:SimpleNamespace) -> SimpleNamespace:
        """Merges the first configuration into the second configuration.

        Args:
            cfg_from (types.SimpleNamespace): The configuration from which to merge.
            cfg_to (types.SimpleNamespace): The configuration into which to merge.

        Returns:
            types.SimpleNamespace: The merged configuration.
        """
        return dict_to_namespace(ArgumentParser._merge_config(cfg_from, cfg_to))
github omni-us / jsonargparse / jsonargparse.py View on Github external
def __init__(self, **kwargs):
        """Initializer for ActionParser instance.

        Args:
            parser (ArgumentParser): A parser to parse the option with.

        Raises:
            ValueError: If the parser parameter is invalid.
        """
        if 'parser' in kwargs:
            ## Runs when first initializing class by external user ##
            _check_unknown_kwargs(kwargs, {'parser'})
            self._parser = kwargs['parser']
            if not isinstance(self._parser, ArgumentParser):
                raise ValueError('Expected parser keyword argument to be an ArgumentParser.')
        elif '_parser' not in kwargs:
            raise ValueError('Expected parser keyword argument.')
        else:
            ## Runs when initialied from the __call__ method below ##
            self._parser = kwargs.pop('_parser')
            kwargs['type'] = str
            super().__init__(**kwargs)