Add dryrun flag.

This commit is contained in:
redxef 2022-10-13 00:53:28 +02:00
parent 4059b9b6dd
commit d3895cd43d
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -114,7 +114,8 @@ def init_logging(level: str):
@click.command() @click.command()
@click.option('--level', '-l', envvar='WP_CAL_LEVEL', default=':WARNING,wp_cal:INFO', help='The log level for the application') @click.option('--level', '-l', envvar='WP_CAL_LEVEL', default=':WARNING,wp_cal:INFO', help='The log level for the application')
@click.option('--config', '-c', envvar='WP_CAL_CONFIG', default='-', help='The configuration file') @click.option('--config', '-c', envvar='WP_CAL_CONFIG', default='-', help='The configuration file')
def main(level, config): @click.option('--dryrun', '-d', envvar='WP_CAL_DRYRUN', is_flag=True, help="Don't actually post any data, just show it")
def main(level, config, dryrun):
logging.basicConfig() logging.basicConfig()
init_logging(level) init_logging(level)
@ -149,7 +150,10 @@ def main(level, config):
events = g.get_events() events = g.get_events()
logger.info("syncing %d events", len(events)) logger.info("syncing %d events", len(events))
w.login() w.login()
w.post_events(events) if dryrun:
logger.info("dryrun; would post events: %s", events)
else:
w.post_events(events)
logger.info("done") logger.info("done")
if __name__ == '__main__': if __name__ == '__main__':