Add a display_name attribute to Setting

This commit is contained in:
Timmy Welch 2023-02-19 18:34:12 -08:00
parent d07cf9949b
commit fe7c821605
No known key found for this signature in database
2 changed files with 32 additions and 0 deletions

View File

@ -93,11 +93,35 @@ class Setting:
metavar: str | None = None, metavar: str | None = None,
dest: str | None = None, dest: str | None = None,
# ComicTagger # ComicTagger
display_name: str = '',
cmdline: bool = True, cmdline: bool = True,
file: bool = True, file: bool = True,
group: str = '', group: str = '',
exclusive: bool = False, exclusive: bool = False,
): ):
"""
Args:
*names: Passed directly to argparse
action: Passed directly to argparse
nargs: Passed directly to argparse
const: Passed directly to argparse
default: Passed directly to argparse
type: Passed directly to argparse
choices: Passed directly to argparse
required: Passed directly to argparse
help: Passed directly to argparse
metavar: Passed directly to argparse, defaults to `dest` uppercased
dest: This is the name used to retrieve the value from a `Config` object as a dictionary
display_name: This is not used by settngs. This is a human-readable name to be used when generating a GUI.
Defaults to `dest`.
cmdline: If this setting can be set via the commandline
file: If this setting can be set via a file
group: The group this option is in.
This is an internal argument and should only be set by settngs
exclusive: If this setting is exclusive to other settings in this group.
This is an internal argument and should only be set by settngs
"""
if not names: if not names:
raise ValueError('names must be specified') raise ValueError('names must be specified')
# We prefix the destination name used by argparse so that there are no conflicts # We prefix the destination name used by argparse so that there are no conflicts
@ -130,6 +154,7 @@ class Setting:
self.argparse_args = args self.argparse_args = args
self.group = group self.group = group
self.exclusive = exclusive self.exclusive = exclusive
self.display_name = display_name or dest
self.argparse_kwargs = { self.argparse_kwargs = {
'action': action, 'action': action,

View File

@ -78,6 +78,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test_setting', # dest is calculated by Setting and is not used by argparse 'dest': 'test_setting', # dest is calculated by Setting and is not used by argparse
'display_name': 'test_setting', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -117,6 +118,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'testing', # dest is calculated by Setting and is not used by argparse 'dest': 'testing', # dest is calculated by Setting and is not used by argparse
'display_name': 'testing', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -155,6 +157,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test', # dest is calculated by Setting and is not used by argparse 'dest': 'test', # dest is calculated by Setting and is not used by argparse
'display_name': 'test', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -194,6 +197,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test', # dest is calculated by Setting and is not used by argparse 'dest': 'test', # dest is calculated by Setting and is not used by argparse
'display_name': 'test', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -232,6 +236,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test', 'dest': 'test',
'display_name': 'test', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -270,6 +275,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test', 'dest': 'test',
'display_name': 'test', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': 'tst', 'group': 'tst',
@ -306,6 +312,7 @@ success = [
'const': None, 'const': None,
'default': None, 'default': None,
'dest': 'test', 'dest': 'test',
'display_name': 'test', # defaults to dest
'exclusive': False, 'exclusive': False,
'file': True, 'file': True,
'group': '', 'group': '',