Skip to content

Commit

Permalink
Fix list command names from importlib
Browse files Browse the repository at this point in the history
The compatibility code for importlib.metadata
returned names was not correct.

Closes: #188
  • Loading branch information
tobias-urdin committed Oct 11, 2024
1 parent 019aeac commit 2b9face
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pifpaf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def _format_multiple_exceptions(e, debug=False):
DAEMONS = importlib.metadata.entry_points()['pifpaf.daemons']


def _daemons_names():
names = []
if hasattr(DAEMONS, 'names'):
names = DAEMONS.names
else:
for i in DAEMONS:
names.append(i.name)
return names


@click.group()
@click.option('--verbose/--quiet', help="Print mode details.")
@click.option('--debug', help="Show tracebacks on errors.", is_flag=True)
Expand Down Expand Up @@ -119,14 +129,14 @@ def main(ctx, verbose=False, debug=False, log_file=None,

@main.command(name="list")
def drivers_list():
for n in DAEMONS.keys():
for n in _daemons_names():
click.echo(n)


class RunGroup(click.MultiCommand):
@staticmethod
def list_commands(ctx):
return DAEMONS.keys()
return _daemons_names()

def get_command(self, ctx, name):
params = [click.Argument(["command"], nargs=-1)]
Expand Down

0 comments on commit 2b9face

Please sign in to comment.