Skip to content

Commit

Permalink
Reset values for single attribute from CLI (#303)
Browse files Browse the repository at this point in the history
The `-r` attribute in the adminapi CLI tool was only able to reset
MultiAttr type attributes. With this commit, the `-r` option should be
able to clear any type of attribute.
  • Loading branch information
lamaral committed Mar 31, 2023
1 parent e1d776d commit c3bc6ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions adminapi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from argparse import ArgumentParser, ArgumentTypeError

from adminapi.dataset import Query
from adminapi.dataset import MultiAttr, Query
from adminapi.parse import parse_query


Expand Down Expand Up @@ -35,7 +35,7 @@ def parse_args(args):
'-r',
'--reset',
action='append',
help='Multi attributes to reset' + multi_note,
help='Attributes to reset' + multi_note,
)
parser.add_argument(
'-u',
Expand Down Expand Up @@ -87,7 +87,12 @@ def attr_value(arg):

def apply_resets(server, attribute_ids):
for attribute_id in attribute_ids:
server[attribute_id].clear()
if isinstance(server[attribute_id], MultiAttr):
server[attribute_id].clear()
elif isinstance(server[attribute_id], bool):
raise Exception('Attribute of type boolean cannot be reset')
else:
server.set(attribute_id, None)


def apply_updates(server, attribute_values):
Expand Down

0 comments on commit c3bc6ab

Please sign in to comment.