adding -e/ -s flags to end/ start command
This commit is contained in:
12
main.py
12
main.py
@@ -27,9 +27,11 @@ def create_parser():
|
|||||||
# Create the parser for the "start" command
|
# Create the parser for the "start" command
|
||||||
parser_start = subparsers.add_parser("start", help="Starting a new event.")
|
parser_start = subparsers.add_parser("start", help="Starting a new event.")
|
||||||
parser_start.add_argument("name", help="Name of the event")
|
parser_start.add_argument("name", help="Name of the event")
|
||||||
|
parser_start.add_argument("-s", "--start", help="Start datetime (default now)")
|
||||||
|
|
||||||
# Create the parser for the "end" command
|
# Create the parser for the "end" command
|
||||||
_ = subparsers.add_parser("end", help="Ending the current event.")
|
parser_end = subparsers.add_parser("end", help="Ending the current event.")
|
||||||
|
parser_end.add_argument("-e", "--end", help="End datetime")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -48,6 +50,10 @@ if __name__ == "__main__":
|
|||||||
running = list(filter(lambda x: x.end is None, time_slots))
|
running = list(filter(lambda x: x.end is None, time_slots))
|
||||||
if len(running):
|
if len(running):
|
||||||
print("An event is already running.")
|
print("An event is already running.")
|
||||||
|
else:
|
||||||
|
if args.start is not None:
|
||||||
|
s = datetime.strptime(args.start, '%d.%m.%y %H:%M')
|
||||||
|
ds.add_time_slot(TimeSlot(args.name, start=s))
|
||||||
else:
|
else:
|
||||||
ds.add_time_slot(TimeSlot(args.name))
|
ds.add_time_slot(TimeSlot(args.name))
|
||||||
print(f"Started event {args.name}.")
|
print(f"Started event {args.name}.")
|
||||||
@@ -59,6 +65,10 @@ if __name__ == "__main__":
|
|||||||
print("No running event.")
|
print("No running event.")
|
||||||
elif len(running) > 1:
|
elif len(running) > 1:
|
||||||
raise Exception("Found multiple running event.")
|
raise Exception("Found multiple running event.")
|
||||||
|
else:
|
||||||
|
if args.end is not None:
|
||||||
|
s = datetime.strptime(args.end, '%d.%m.%y %H:%M')
|
||||||
|
running[0].end = s
|
||||||
else:
|
else:
|
||||||
running[0].end_now()
|
running[0].end_now()
|
||||||
ds.write_update()
|
ds.write_update()
|
||||||
|
|||||||
Reference in New Issue
Block a user