Commit c4230bbc authored by David Huss's avatar David Huss 💬
Browse files

Add command abbreviations (e.g. bbbmon m)

parent 29880dc9
...@@ -77,3 +77,13 @@ For help run: ...@@ -77,3 +77,13 @@ For help run:
bbbmon -h bbbmon -h
``` ```
bbbmon supports command abbreviations – these commands produce the same result:
```bash
bbbmon meetings
bbbmon meeting
bbbmon mee
bbbmon m
```
This works as long as there is no other command starting with the same letters.
\ No newline at end of file
...@@ -16,16 +16,36 @@ from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url, ...@@ -16,16 +16,36 @@ from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url,
FRIENDLY_KEYNAMES = { FRIENDLY_KEYNAMES = {
"participantCount": "Participants", "participantCount" : "Participants",
"listenerCount": "only listening", "listenerCount" : "only listening",
"voiceParticipantCount": "Mics on", "voiceParticipantCount" : "Mics on",
"videoCount": "Webcams on", "videoCount" : "Webcams on",
"moderatorCount": "Number of Moderators" "moderatorCount" : "Number of Moderators"
} }
# Allow -h as help option as well
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
class AliasedGroup(click.Group):
"""
Subclass of Group to allow abbreviating commands like this:
Instead of `bbbmon meetings` one could type `bbbmon m`
"""
def get_command(self, ctx, cmd_name):
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [x for x in self.list_commands(ctx)
if x.startswith(cmd_name)]
if not matches:
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
def generate_checksum(call_name: str, query_string: str, secret: Secret) -> str: def generate_checksum(call_name: str, query_string: str, secret: Secret) -> str:
""" """
Generate Checksum for the request header (passed as value for `?checksum=`) Generate Checksum for the request header (passed as value for `?checksum=`)
...@@ -167,6 +187,7 @@ def print_leaderboard(meetings: Iterable[XmlDictConfig], key: str, endpoint_name ...@@ -167,6 +187,7 @@ def print_leaderboard(meetings: Iterable[XmlDictConfig], key: str, endpoint_name
else: else:
print("{:>5} {}".format(m[key], m["meetingName"])) print("{:>5} {}".format(m[key], m["meetingName"]))
def print_duration_leaderboard(meetings: Iterable[XmlDictConfig], endpoint_name: str, presenter: bool, presenter_id: bool, fancy: bool): def print_duration_leaderboard(meetings: Iterable[XmlDictConfig], endpoint_name: str, presenter: bool, presenter_id: bool, fancy: bool):
""" """
Print a leaderboard of all meetings sorted by a given key (e.g. Print a leaderboard of all meetings sorted by a given key (e.g.
...@@ -184,12 +205,14 @@ def print_duration_leaderboard(meetings: Iterable[XmlDictConfig], endpoint_name: ...@@ -184,12 +205,14 @@ def print_duration_leaderboard(meetings: Iterable[XmlDictConfig], endpoint_name:
else: else:
print("{:>12} {}".format(format_duration(m), m["meetingName"])) print("{:>12} {}".format(format_duration(m), m["meetingName"]))
def print_header(endpoint_name: str, text: str, fancy=True): def print_header(endpoint_name: str, text: str, fancy=True):
if fancy: if fancy:
click.echo(click.style(" [{}] {} ".format(endpoint_name, text), fg='black', bg='white', bold=True)) click.echo(click.style(" [{}] {} ".format(endpoint_name, text), fg='black', bg='white', bold=True))
else: else:
print("[{}] {}".format(endpoint_name, text)) print("[{}] {}".format(endpoint_name, text))
def print_overview(config: Config, leaderboards: bool, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, watch: int, fancy: bool): def print_overview(config: Config, leaderboards: bool, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, watch: int, fancy: bool):
""" """
For each endpoint in the configuration get the active meetings and print For each endpoint in the configuration get the active meetings and print
...@@ -254,7 +277,8 @@ def print_overview(config: Config, leaderboards: bool, participants: bool, prese ...@@ -254,7 +277,8 @@ def print_overview(config: Config, leaderboards: bool, participants: bool, prese
print_duration_leaderboard(meeting, endpoint.name, presenter, presenter_id, fancy) print_duration_leaderboard(meeting, endpoint.name, presenter, presenter_id, fancy)
@click.group(context_settings=CONTEXT_SETTINGS)
@click.group(context_settings=CONTEXT_SETTINGS, cls=AliasedGroup)
def main(): def main():
"""BBBMON is a small CLI utility to monitor bbb usage """BBBMON is a small CLI utility to monitor bbb usage
...@@ -296,10 +320,7 @@ def meetings(ctx, leaderboards, participants, presenter, watch, presenter_id, me ...@@ -296,10 +320,7 @@ def meetings(ctx, leaderboards, participants, presenter, watch, presenter_id, me
@click.option('--print', 'print_', is_flag=True, help="Print the config to stdout") @click.option('--print', 'print_', is_flag=True, help="Print the config to stdout")
@click.option('--path', is_flag=True, help="Print the path to the config") @click.option('--path', is_flag=True, help="Print the path to the config")
def config(ctx, new, edit, path, print_): def config(ctx, new, edit, path, print_):
"""Print, show or edit the config """Print, show or edit the config"""
Example: bbbmon config --new
"""
user_config_path = get_user_config_path() user_config_path = get_user_config_path()
if edit: if edit:
......
[tool.poetry] [tool.poetry]
name = "bbbmon" name = "bbbmon"
version = "0.1.12" version = "0.1.13"
description = "A small CLI utility to monitor bbb usage" description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"] authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"] maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment