From 903308864cbf8622c308118ca2c3170504038d4e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 17 Mar 2025 10:46:02 -0700 Subject: [PATCH] Factor out schema type parsing (#303). --- borgmatic/commands/arguments.py | 12 +----------- borgmatic/config/schema.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 6b3abf9c..dad5584d 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -1,5 +1,4 @@ import collections -import decimal import io import itertools import json @@ -377,16 +376,7 @@ def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names description = description.replace('%', '%%') - try: - argument_type = { - 'string': str, - 'integer': int, - 'number': decimal.Decimal, - 'boolean': bool, - 'array': str, - }[schema_type] - except KeyError: - raise ValueError(f'Unknown type in configuration schema: {schema_type}') + argument_type = borgmatic.config.schema.parse_type(schema_type) arguments_group.add_argument( f"--{flag_name.replace('_', '-')}", diff --git a/borgmatic/config/schema.py b/borgmatic/config/schema.py index e46d27cc..118e9437 100644 --- a/borgmatic/config/schema.py +++ b/borgmatic/config/schema.py @@ -1,3 +1,4 @@ +import decimal import itertools @@ -20,3 +21,16 @@ def get_properties(schema): ) return schema.get('properties', {}) + + +def parse_type(schema_type): + try: + return { + 'string': str, + 'integer': int, + 'number': decimal.Decimal, + 'boolean': bool, + 'array': str, + }[schema_type] + except KeyError: + raise ValueError(f'Unknown type in configuration schema: {schema_type}')