mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-01 14:13:01 +02:00
Factor out schema type parsing (#303).
This commit is contained in:
@@ -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('_', '-')}",
|
||||
|
||||
@@ -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}')
|
||||
|
||||
Reference in New Issue
Block a user