Skip to content

Commit

Permalink
Cleanup: use "choices" to avoid a custom string parsing function
Browse files Browse the repository at this point in the history
  • Loading branch information
ideasman42 committed May 14, 2024
1 parent 222cf37 commit 8ecb1c5
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions riverwm_utils/riverwm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,6 @@ def close_display(display: Display):
display.disconnect()


def check_direction(direction: str) -> str:
'''Check validity of direction argument'''
dir_char = direction[0].lower()
if dir_char not in ('p', 'n'):
raise argparse.ArgumentTypeError(f'Invalid direction: {direction}')

return dir_char


def check_n_tags(n_tags: int) -> int:
'''Check validity of direction argument'''
i_n_tags = int(n_tags)
Expand All @@ -215,8 +206,8 @@ def parse_command_line() -> argparse.Namespace:
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'direction', default='next', nargs='?', type=check_direction,
help=('Direction to cycle through tags. Either "next" or "previous".')
'direction', default='next', nargs='?', type=str, choices=('next', 'previous'),
help=('Direction to cycle through tags.')
)
parser.add_argument(
'n_tags', default=32, nargs='?', type=check_n_tags,
Expand Down Expand Up @@ -298,7 +289,7 @@ def get_new_tags(cli_args: argparse.Namespace,
return initial_tags

new_tags = 0
if cli_args.direction == 'n':
if cli_args.direction == 'next':
# If last tag is set => unset it and set first bit on new_tags
if (tags & last_tag) != 0:
tags ^= last_tag
Expand Down

0 comments on commit 8ecb1c5

Please sign in to comment.