summaryrefslogtreecommitdiff
path: root/cal.py
diff options
context:
space:
mode:
Diffstat (limited to 'cal.py')
-rwxr-xr-xcal.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/cal.py b/cal.py
index b1bf140..f1b9b10 100755
--- a/cal.py
+++ b/cal.py
@@ -8,9 +8,18 @@ See https://www.gnu.org/licenses/gpl-3.0.en.html for license information.
This is a new cli to be fully released in version 1.0, until then
quite much functionality will only be available through the legacy
-calendar-cli
+calendar-cli. For discussions on the directions, see
+https://github.com/tobixen/calendar-cli/issues/88
"""
+## This file should preferably just be a thin interface between public
+## python libraries and the command line. Logics that isn't strictly
+## tied to the cli as such but also does not fit into other libraries
+## may be moved out to a separate library file.
+
+## This file aims to be smaller than the old calendar-cli while
+## offering more featuores.
+
from calendar_cli import __version__
import click
@@ -29,6 +38,10 @@ import caldav
## See https://click.palletsprojects.com/en/8.0.x/api/#click.ParamType and
## /usr/lib/*/site-packages/click/types.py on how to do this.
+## TODO ...
+def _parse_timespec(timespec):
+ raise NotImplementedError()
+
@click.group()
## TODO
#@click.option('-c', '--config-file', type=click.File("rb"), default=f"{os.environ['HOME']}/.config/calendar.conf")
@@ -77,6 +90,13 @@ def test(ctx):
"""
click.echo("Seems like everything is OK")
+attr_txt_one = ['location', 'description', 'geo', 'organizer', 'summary']
+attr_txt_many = ['categories', 'comment', 'contact', 'resources']
+
+def set_attr_options(func):
+ for foo in attr_txt_one:
+ func = click.option()
+
@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")
@@ -93,7 +113,6 @@ def add(ctx, **kwargs):
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()
@@ -103,6 +122,8 @@ def add(ctx, **kwargs):
def ical(ctx, ical_data, ical_file):
if (ical_file):
ical = ical_file.read()
+ if ctx.obj['ical_fragment']:
+ ical = ical.replace('\nEND:', f"{ctx.obj['ical_fragment']}\nEND:")
for c in ctx.obj['calendars']:
## TODO: this may not be an event - should make a Calendar.save_object method
c.save_event(ical)
@@ -113,9 +134,25 @@ def todo():
raise NotImplementedError("foo")
@add.command()
-def event():
- click.echo("soon you should be able to add events to your calendar")
- raise NotImplementedError("foo")
+## TODO
+@click.argument('description')
+@click.argument('timespec')
+@click.pass_context
+def event(ctx, description, timespec):
+ """
+ Creates a new event with given DESCRIPTION at the time specifed through TIMESPEC.
+
+ TIMESPEC is an ISO-formatted date or timestamp, optionally with a postfixed interval.
+
+ Examples:
+
+ kal add event "final bughunting session" 2004-11-25+5d
+ kal add event "release party" 2004-11-30T19:00+2h
+ """
+ for cal in ctx['calendars']:
+ (dtstart, dtend) = _parse_timespec(timespec)
+ #event = cal.add_event(
+ click.echo(uid)
def journal():
click.echo("soon you should be able to add journal entries to your calendar")