瀏覽代碼

Use schema defaults instead of a flag name whitelist to make valueless boolean flags (#303).

Dan Helfman 5 月之前
父節點
當前提交
d02d31f445
共有 2 個文件被更改,包括 36 次插入28 次删除
  1. 3 22
      borgmatic/commands/arguments.py
  2. 33 6
      borgmatic/config/schema.yaml

+ 3 - 22
borgmatic/commands/arguments.py

@@ -288,27 +288,6 @@ 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',
-    'repositories[0].append_only',
-    'repositories[0].make_parent_dirs',
-    'progress',
-}
-
-
 def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names=None):
 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
     Given an argparse._ArgumentGroup instance, a configuration schema dict, and a sequence of
@@ -400,7 +379,9 @@ def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names
     argument_type = borgmatic.config.schema.parse_type(schema_type)
     argument_type = borgmatic.config.schema.parse_type(schema_type)
     full_flag_name = f"--{flag_name.replace('_', '-')}"
     full_flag_name = f"--{flag_name.replace('_', '-')}"
 
 
-    if flag_name in DEFAULT_FALSE_FLAG_NAMES:
+    # As a UX nicety, allow boolean options that have a default of false to have command-line flags
+    # without values.
+    if schema_type == 'boolean' and schema.get('default') == False:
         arguments_group.add_argument(
         arguments_group.add_argument(
             full_flag_name,
             full_flag_name,
             action='store_true',
             action='store_true',

+ 33 - 6
borgmatic/config/schema.yaml

@@ -58,7 +58,8 @@ properties:
                     description: |
                     description: |
                         Whether the repository should be created append-only,
                         Whether the repository should be created append-only,
                         only used for the repo-create action. Defaults to false.
                         only used for the repo-create action. Defaults to false.
-                    example: false
+                    default: false
+                    example: true
                 storage_quota:
                 storage_quota:
                     type: string
                     type: string
                     description: |
                     description: |
@@ -72,6 +73,7 @@ properties:
                         Whether any missing parent directories of the repository
                         Whether any missing parent directories of the repository
                         path should be created, only used for the repo-create
                         path should be created, only used for the repo-create
                         action. Defaults to false.
                         action. Defaults to false.
+                    default: false
                     example: true
                     example: true
         description: |
         description: |
             A required list of local or remote repositories with paths and
             A required list of local or remote repositories with paths and
@@ -101,12 +103,14 @@ properties:
         description: |
         description: |
             Stay in same file system; do not cross mount points beyond the given
             Stay in same file system; do not cross mount points beyond the given
             source directories. Defaults to false.
             source directories. Defaults to false.
+        default: false
         example: true
         example: true
     numeric_ids:
     numeric_ids:
         type: boolean
         type: boolean
         description: |
         description: |
             Only store/extract numeric user and group identifiers. Defaults to
             Only store/extract numeric user and group identifiers. Defaults to
             false.
             false.
+        default: false
         example: true
         example: true
     atime:
     atime:
         type: boolean
         type: boolean
@@ -117,11 +121,13 @@ properties:
     ctime:
     ctime:
         type: boolean
         type: boolean
         description: Store ctime into archive. Defaults to true.
         description: Store ctime into archive. Defaults to true.
+        default: true
         example: false
         example: false
     birthtime:
     birthtime:
         type: boolean
         type: boolean
         description: |
         description: |
             Store birthtime (creation date) into archive. Defaults to true.
             Store birthtime (creation date) into archive. Defaults to true.
+        default: true
         example: false
         example: false
     read_special:
     read_special:
         type: boolean
         type: boolean
@@ -131,13 +137,15 @@ properties:
             used when backing up special devices such as /dev/zero. Defaults to
             used when backing up special devices such as /dev/zero. Defaults to
             false. But when a database hook is used, the setting here is ignored
             false. But when a database hook is used, the setting here is ignored
             and read_special is considered true.
             and read_special is considered true.
-        example: false
+        default: false
+        example: true
     flags:
     flags:
         type: boolean
         type: boolean
         description: |
         description: |
             Record filesystem flags (e.g. NODUMP, IMMUTABLE) in archive.
             Record filesystem flags (e.g. NODUMP, IMMUTABLE) in archive.
             Defaults to true.
             Defaults to true.
-        example: true
+        default: true
+        example: false
     files_cache:
     files_cache:
         type: string
         type: string
         description: |
         description: |
@@ -210,6 +218,7 @@ properties:
             Exclude directories that contain a CACHEDIR.TAG file. See
             Exclude directories that contain a CACHEDIR.TAG file. See
             http://www.brynosaurus.com/cachedir/spec.html for details. Defaults
             http://www.brynosaurus.com/cachedir/spec.html for details. Defaults
             to false.
             to false.
+        default: false
         example: true
         example: true
     exclude_if_present:
     exclude_if_present:
         type: array
         type: array
@@ -226,11 +235,13 @@ properties:
             If true, the exclude_if_present filename is included in backups.
             If true, the exclude_if_present filename is included in backups.
             Defaults to false, meaning that the exclude_if_present filename is
             Defaults to false, meaning that the exclude_if_present filename is
             omitted from backups.
             omitted from backups.
+        default: false
         example: true
         example: true
     exclude_nodump:
     exclude_nodump:
         type: boolean
         type: boolean
         description: |
         description: |
             Exclude files with the NODUMP flag. Defaults to false.
             Exclude files with the NODUMP flag. Defaults to false.
+        default: false
         example: true
         example: true
     borgmatic_source_directory:
     borgmatic_source_directory:
         type: string
         type: string
@@ -262,6 +273,7 @@ properties:
         description: |
         description: |
             If true, then source directories (and root pattern paths) must
             If true, then source directories (and root pattern paths) must
             exist. If they don't, an error is raised. Defaults to false.
             exist. If they don't, an error is raised. Defaults to false.
+        default: false
         example: true
         example: true
     encryption_passcommand:
     encryption_passcommand:
         type: string
         type: string
@@ -458,19 +470,22 @@ properties:
         type: boolean
         type: boolean
         description: |
         description: |
             Bypass Borg error about a repository that has been moved. Defaults
             Bypass Borg error about a repository that has been moved. Defaults
-            to not bypassing.
+            to false.
+        default: false
         example: true
         example: true
     unknown_unencrypted_repo_access_is_ok:
     unknown_unencrypted_repo_access_is_ok:
         type: boolean
         type: boolean
         description: |
         description: |
             Bypass Borg error about a previously unknown unencrypted repository.
             Bypass Borg error about a previously unknown unencrypted repository.
-            Defaults to not bypassing.
+            Defaults to false.
+        default: false
         example: true
         example: true
     check_i_know_what_i_am_doing:
     check_i_know_what_i_am_doing:
         type: boolean
         type: boolean
         description: |
         description: |
             Bypass Borg confirmation about check with repair option. Defaults to
             Bypass Borg confirmation about check with repair option. Defaults to
-            an interactive prompt from Borg.
+            false and an interactive prompt from Borg.
+        default: false
         example: true
         example: true
     extra_borg_options:
     extra_borg_options:
         type: object
         type: object
@@ -792,12 +807,14 @@ properties:
         description: |
         description: |
             Apply color to console output. Can be overridden with --no-color
             Apply color to console output. Can be overridden with --no-color
             command-line flag. Defaults to true.
             command-line flag. Defaults to true.
+        default: true
         example: false
         example: false
     progress:
     progress:
         type: boolean
         type: boolean
         description: |
         description: |
             Display progress as each file or archive is processed. Defaults to
             Display progress as each file or archive is processed. Defaults to
             false.
             false.
+        default: false
         example: true
         example: true
     skip_actions:
     skip_actions:
         type: array
         type: array
@@ -1166,6 +1183,7 @@ properties:
                     backup itself. Defaults to true. Changing this to false
                     backup itself. Defaults to true. Changing this to false
                     prevents "borgmatic bootstrap" from extracting configuration
                     prevents "borgmatic bootstrap" from extracting configuration
                     files from the backup.
                     files from the backup.
+                default: true
                 example: false
                 example: false
         description: |
         description: |
             Support for the "borgmatic bootstrap" action, used to extract
             Support for the "borgmatic bootstrap" action, used to extract
@@ -1250,6 +1268,7 @@ properties:
                         schema elements. These statements will fail unless the
                         schema elements. These statements will fail unless the
                         initial connection to the database is made by a
                         initial connection to the database is made by a
                         superuser.
                         superuser.
+                    default: false
                     example: true
                     example: true
                 format:
                 format:
                     type: string
                     type: string
@@ -1488,6 +1507,7 @@ properties:
                         Use the "--add-drop-database" flag with mariadb-dump,
                         Use the "--add-drop-database" flag with mariadb-dump,
                         causing the database to be dropped right before restore.
                         causing the database to be dropped right before restore.
                         Defaults to true.
                         Defaults to true.
+                    default: true
                     example: false
                     example: false
                 options:
                 options:
                     type: string
                     type: string
@@ -1635,6 +1655,7 @@ properties:
                         Use the "--add-drop-database" flag with mysqldump,
                         Use the "--add-drop-database" flag with mysqldump,
                         causing the database to be dropped right before restore.
                         causing the database to be dropped right before restore.
                         Defaults to true.
                         Defaults to true.
+                    default: true
                     example: false
                     example: false
                 options:
                 options:
                     type: string
                     type: string
@@ -2335,6 +2356,7 @@ properties:
                 description: |
                 description: |
                     Send borgmatic logs to Apprise services as part the
                     Send borgmatic logs to Apprise services as part the
                     "finish", "fail", and "log" states. Defaults to true.
                     "finish", "fail", and "log" states. Defaults to true.
+                default: true
                 example: false
                 example: false
             logs_size_limit:
             logs_size_limit:
                 type: integer
                 type: integer
@@ -2440,12 +2462,14 @@ properties:
                 description: |
                 description: |
                     Verify the TLS certificate of the ping URL host. Defaults to
                     Verify the TLS certificate of the ping URL host. Defaults to
                     true.
                     true.
+                default: true
                 example: false
                 example: false
             send_logs:
             send_logs:
                 type: boolean
                 type: boolean
                 description: |
                 description: |
                     Send borgmatic logs to Healthchecks as part the "finish",
                     Send borgmatic logs to Healthchecks as part the "finish",
                     "fail", and "log" states. Defaults to true.
                     "fail", and "log" states. Defaults to true.
+                default: true
                 example: false
                 example: false
             ping_body_limit:
             ping_body_limit:
                 type: integer
                 type: integer
@@ -2478,6 +2502,7 @@ properties:
                     the slug URL scheme (https://hc-ping.com/<ping-key>/<slug>
                     the slug URL scheme (https://hc-ping.com/<ping-key>/<slug>
                     as opposed to https://hc-ping.com/<uuid>).
                     as opposed to https://hc-ping.com/<uuid>).
                     Defaults to false.
                     Defaults to false.
+                default: false
                 example: true
                 example: true
         description: |
         description: |
             Configuration for a monitoring integration with Healthchecks. Create
             Configuration for a monitoring integration with Healthchecks. Create
@@ -2517,6 +2542,7 @@ properties:
                 description: |
                 description: |
                     Verify the TLS certificate of the push URL host. Defaults to
                     Verify the TLS certificate of the push URL host. Defaults to
                     true.
                     true.
+                default: true
                 example: false
                 example: false
         description: |
         description: |
             Configuration for a monitoring integration with Uptime Kuma using
             Configuration for a monitoring integration with Uptime Kuma using
@@ -2553,6 +2579,7 @@ properties:
                 description: |
                 description: |
                     Send borgmatic logs to PagerDuty when a backup errors.
                     Send borgmatic logs to PagerDuty when a backup errors.
                     Defaults to true.
                     Defaults to true.
+                default: true
                 example: false
                 example: false
         description: |
         description: |
             Configuration for a monitoring integration with PagerDuty. Create an
             Configuration for a monitoring integration with PagerDuty. Create an