6
6
from knot_resolver_manager .cli .command import Command , CommandArgs , CompWords , register_command
7
7
from knot_resolver_manager .datamodel .cache_schema import CacheClearRPCSchema
8
8
from knot_resolver_manager .utils .modeling .exceptions import AggregateDataValidationError , DataValidationError
9
- from knot_resolver_manager .utils .modeling .parsing import DataFormat
9
+ from knot_resolver_manager .utils .modeling .parsing import DataFormat , parse_json
10
10
from knot_resolver_manager .utils .requests import request
11
11
12
12
@@ -19,6 +19,7 @@ class CacheCommand(Command):
19
19
def __init__ (self , namespace : argparse .Namespace ) -> None :
20
20
super ().__init__ (namespace )
21
21
self .operation : Optional [CacheOperations ] = namespace .operation if hasattr (namespace , "operation" ) else None
22
+ self .out_format : DataFormat = namespace .out_format if hasattr (namespace , "out_format" ) else DataFormat .YAML
22
23
23
24
# CLEAR operation
24
25
self .clear_dict : Dict [str , Any ] = {}
@@ -70,6 +71,22 @@ def register_args_subparser(
70
71
default = None ,
71
72
)
72
73
74
+ out_format = clear_subparser .add_mutually_exclusive_group ()
75
+ out_format .add_argument (
76
+ "--json" ,
77
+ help = "Set output format in JSON format, default." ,
78
+ const = DataFormat .JSON ,
79
+ action = "store_const" ,
80
+ dest = "format" ,
81
+ )
82
+ out_format .add_argument (
83
+ "--yaml" ,
84
+ help = "Set configuration data in YAML format." ,
85
+ const = DataFormat .YAML ,
86
+ action = "store_const" ,
87
+ dest = "format" ,
88
+ )
89
+
73
90
return cache_parser , CacheCommand
74
91
75
92
@staticmethod
@@ -90,8 +107,9 @@ def run(self, args: CommandArgs) -> None:
90
107
91
108
body : str = DataFormat .JSON .dict_dump (validated .get_unparsed_data ())
92
109
response = request (args .socket , "POST" , "cache/clear" , body )
110
+ body_dict = parse_json (response .body )
93
111
94
112
if response .status != 200 :
95
113
print (response , file = sys .stderr )
96
114
sys .exit (1 )
97
- print (response . body )
115
+ print (self . out_format . dict_dump ( body_dict , indent = 4 ) )
0 commit comments