Skip to content
Snippets Groups Projects
Commit c4230bbc authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add command abbreviations (e.g. bbbmon m)

parent 29880dc9
No related branches found
No related tags found
No related merge requests found
......@@ -77,3 +77,13 @@ For help run:
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
......@@ -23,9 +23,29 @@ FRIENDLY_KEYNAMES = {
"moderatorCount" : "Number of Moderators"
}
# Allow -h as help option as well
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:
"""
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
else:
print("{:>5} {}".format(m[key], m["meetingName"]))
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.
......@@ -184,12 +205,14 @@ def print_duration_leaderboard(meetings: Iterable[XmlDictConfig], endpoint_name:
else:
print("{:>12} {}".format(format_duration(m), m["meetingName"]))
def print_header(endpoint_name: str, text: str, fancy=True):
if fancy:
click.echo(click.style(" [{}] {} ".format(endpoint_name, text), fg='black', bg='white', bold=True))
else:
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):
"""
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
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():
"""BBBMON is a small CLI utility to monitor bbb usage
......@@ -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('--path', is_flag=True, help="Print the path to the config")
def config(ctx, new, edit, path, print_):
"""Print, show or edit the config
Example: bbbmon config --new
"""
"""Print, show or edit the config"""
user_config_path = get_user_config_path()
if edit:
......
[tool.poetry]
name = "bbbmon"
version = "0.1.12"
version = "0.1.13"
description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment