From 28d118155e6361133717a20822e5c710edc6c973 Mon Sep 17 00:00:00 2001 From: Ohad Eytan Date: Fri, 14 May 2021 11:26:04 +0300 Subject: Add quiet flag (#5) --- README.md | 1 + alarmpy.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5ffbb7c..772f9bd 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Options: --routine-delay INTEGER Routine message delay in seconds --alarm-id Print alarm ID --repeat-alarms Do not suppress ongoing alarms + --quiet Print only active alarms --help Show this message and exit. ``` diff --git a/alarmpy.py b/alarmpy.py index 497eabd..d3ee0f1 100644 --- a/alarmpy.py +++ b/alarmpy.py @@ -16,12 +16,13 @@ class Alarm(object): } def __init__( - self, delay=1, routine_delay=60 * 5, alarm_id=False, repeat_alarms=False + self, delay=1, routine_delay=60 * 5, alarm_id=False, repeat_alarms=False, quiet=False ): self.delay = delay self.last_routine_delay = routine_delay self.alarm_id = alarm_id self.repeat_alarms = repeat_alarms + self.quiet = quiet self.current_alarms = [] self.last_routine_output = 0 @@ -83,12 +84,14 @@ class Alarm(object): click.secho(f"{ts} ", nl=False) def output_error(self, err): - self.output_leading_timestamp() - click.secho(err, fg="yellow", bold=True) + if not self.quiet: + self.output_leading_timestamp() + click.secho(err, fg="yellow", bold=True) def output_routine(self): - self.output_leading_timestamp() - click.secho("No active alarms", fg="green") + if not self.quiet: + self.output_leading_timestamp() + click.secho(f"No active alarms", fg="green") def output_alarms(self, cities, alarm_id): self.output_leading_timestamp() @@ -105,6 +108,7 @@ class Alarm(object): ) @click.option("--alarm-id", is_flag=True, help="Print alarm IDs") @click.option("--repeat-alarms", is_flag=True, help="Do not suppress ongoing alarms") +@click.option("--quiet", is_flag=True, help="Print only active alarms") def alarm(**kwargs): Alarm(**kwargs).start() -- cgit v1.3.1