summaryrefslogtreecommitdiff
path: root/cal.py
diff options
context:
space:
mode:
authorTobias Brox <tobias@redpill-linpro.com>2022-01-02 01:28:53 +0100
committerTobias Brox <tobias@redpill-linpro.com>2022-01-02 01:28:53 +0100
commit1a2b0fcceb9427c652d4abfa872626684906ad5a (patch)
treec9212ef4540e9851faaf559cf6574e4b67513764 /cal.py
parent46f66948473dc0b0ef98525e03bdf73d43992b1d (diff)
downloadcalendar-cli-1a2b0fcceb9427c652d4abfa872626684906ad5a.zip
kal: milestone, ics data can be added to the calendar
Diffstat (limited to 'cal.py')
-rwxr-xr-x[-rw-r--r--]cal.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/cal.py b/cal.py
index 77e7c94..b1bf140 100644..100755
--- a/cal.py
+++ b/cal.py
@@ -41,7 +41,9 @@ import caldav
@click.pass_context
def cli(ctx, **kwargs):
"""
- CalDAV Command Line Interface
+ CalDAV Command Line Interface, in development.
+
+ This command will eventually replace calendar-cli.
"""
## The cli function will prepare a context object, a dict containing the
@@ -65,29 +67,45 @@ def cli(ctx, **kwargs):
calendars.append(principal.calendar(name=calendar_name))
if not calendars:
calendars = principal.calendars()
- ctx.obj['client'] = client
- ctx.obj['principal'] = principal
ctx.obj['calendars'] = calendars
-@cli.group()
-@click.option('-l', '--add-ical-line', multiple=True)
-@click.pass_context
-def add(ctx, add_ical_line):
- click.echo("working on something here")
-
@cli.command()
@click.pass_context
def test(ctx):
"""
Will test that we can connect to the caldav server and find the calendars.
"""
- print("Seems like everything is OK")
+ click.echo("Seems like everything is OK")
+@cli.group()
+@click.option('-l', '--add-ical-line', multiple=True, help="extra ical data to be injected")
+@click.option('--multi-add/--no-multi-add', default=False, help="Add things to multiple calendars")
+@click.option('--first-calendar/--no-first-calendar', default=False, help="Add things to the first given calendar")
+@click.pass_context
+def add(ctx, **kwargs):
+ if (len(ctx.obj['calendars'])>1 and
+ not kwargs['multi_add'] and
+ not click.confirm(f"Multiple calendars given. Do you want to duplicate to {len(ctx.obj['calendars'])} calendars? (tip: use option --multi-add to avoid this prompt in the future)")):
+ calendar = ctx.obj['calendars'][0]
+ ## TODO: we need to make sure f"{calendar.name}" will always work or something
+ if (kwargs['first_calendar'] or
+ click.confirm(f"First calendar on the list has url {calendar.url} - should we add there? (tip: use --calendar-url={calendar.url} or --first_calendar to avoid this prompt in the future)")):
+ ctx.obj['calendars'] = [ calendar ]
+ else:
+ raise click.Abort()
+ click.echo("working on something here")
+ ctx.obj['ical_fragment'] = "\n".join(kwargs['add_ical_line'])
@add.command()
-def ical():
- click.echo("soon you should be able to add ical data to your calendar")
- raise NotImplementedError("foo")
+@click.pass_context
+@click.option('-d', '--ical-data', '--ical', help="ical object to be added")
+@click.option('-f', '--ical-file', type=click.File('rb'), help="file containing ical data")
+def ical(ctx, ical_data, ical_file):
+ if (ical_file):
+ ical = ical_file.read()
+ for c in ctx.obj['calendars']:
+ ## TODO: this may not be an event - should make a Calendar.save_object method
+ c.save_event(ical)
@add.command()
def todo():