Skip to content

Commit

Permalink
improvement: list available commands for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
beanallergy committed Jun 30, 2024
1 parent 6a49e3d commit de2e91f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spotify2ytmusic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

from . import cli
import sys
import inspect

def list_commands(module):
# include only functions defined in e.g. 'cli' module
commands = [name for name, obj in inspect.getmembers(module) if inspect.isfunction(obj)]
return commands

available_commands = list_commands(cli)

if len(sys.argv) < 2:
print(f"usage: spotify2ytmusic [COMMAND] <ARGUMENTS>")
print(" For example, try 'list_playlists'")
print("Available commands:", ", ".join(available_commands))
print(" For example, try 'spotify2ytmusic list_playlists'")
sys.exit(1)

if not hasattr(cli, sys.argv[1]):
if sys.argv[1] not in available_commands:
print(
f"ERROR: Unknown command, see https://github.com/linsomniac/spotify_to_ytmusic"
f"ERROR: Unknown command '{sys.argv[1]}', see https://github.com/linsomniac/spotify_to_ytmusic"
)
print("Available commands: ", ", ".join(available_commands))
sys.exit(1)

fn = getattr(cli, sys.argv[1])
Expand Down

0 comments on commit de2e91f

Please sign in to comment.