mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
UX nicety to make default-false boolean options into valueless CLI flags (#303).
This commit is contained in:
@@ -288,6 +288,24 @@ def parse_arguments_for_actions(unparsed_arguments, action_parsers, global_parse
|
||||
)
|
||||
|
||||
|
||||
# As a UX nicety, allow boolean options that have a default of false to have command-line flags
|
||||
# without values.
|
||||
DEFAULT_FALSE_FLAG_NAMES = {
|
||||
'one_file_system',
|
||||
'numeric_ids',
|
||||
'read_special',
|
||||
'exclude_caches',
|
||||
'keep_exclude_tags',
|
||||
'exclude_nodump',
|
||||
'source_directories_must_exist',
|
||||
'relocated_repo_access_is_ok',
|
||||
'unknown_unencrypted_repo_access_is_ok',
|
||||
'check_i_know_what_i_am_doing',
|
||||
'postgresql_databases[0].no_owner',
|
||||
'healthchecks.create_slug',
|
||||
}
|
||||
|
||||
|
||||
def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names=None):
|
||||
'''
|
||||
Given an argparse._ArgumentGroup instance, a configuration schema dict, and a sequence of
|
||||
@@ -377,13 +395,21 @@ def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names
|
||||
description = description.replace('%', '%%')
|
||||
|
||||
argument_type = borgmatic.config.schema.parse_type(schema_type)
|
||||
full_flag_name = f"--{flag_name.replace('_', '-')}"
|
||||
|
||||
arguments_group.add_argument(
|
||||
f"--{flag_name.replace('_', '-')}",
|
||||
type=argument_type,
|
||||
metavar=metavar,
|
||||
help=description,
|
||||
)
|
||||
if flag_name in DEFAULT_FALSE_FLAG_NAMES:
|
||||
arguments_group.add_argument(
|
||||
full_flag_name,
|
||||
action='store_true',
|
||||
help=description,
|
||||
)
|
||||
else:
|
||||
arguments_group.add_argument(
|
||||
full_flag_name,
|
||||
type=argument_type,
|
||||
metavar=metavar,
|
||||
help=description,
|
||||
)
|
||||
|
||||
# We want to support flags that can have arbitrary indices like:
|
||||
#
|
||||
|
||||
@@ -1983,8 +1983,8 @@ properties:
|
||||
type: boolean
|
||||
description: |
|
||||
Set to True to enable HTML parsing of the message.
|
||||
Set to False for plain text.
|
||||
example: True
|
||||
Set to false for plain text.
|
||||
example: true
|
||||
sound:
|
||||
type: string
|
||||
description: |
|
||||
@@ -2058,8 +2058,8 @@ properties:
|
||||
type: boolean
|
||||
description: |
|
||||
Set to True to enable HTML parsing of the message.
|
||||
Set to False for plain text.
|
||||
example: True
|
||||
Set to false for plain text.
|
||||
example: true
|
||||
sound:
|
||||
type: string
|
||||
description: |
|
||||
@@ -2133,8 +2133,8 @@ properties:
|
||||
type: boolean
|
||||
description: |
|
||||
Set to True to enable HTML parsing of the message.
|
||||
Set to False for plain text.
|
||||
example: True
|
||||
Set to false for plain text.
|
||||
example: true
|
||||
sound:
|
||||
type: string
|
||||
description: |
|
||||
|
||||
Reference in New Issue
Block a user