From d69af271fee960be329574b55ffeafc2af72aa42 Mon Sep 17 00:00:00 2001 From: Xananax Date: Sat, 4 Mar 2023 18:07:03 +0400 Subject: [PATCH] started implementing an API --- main.gd | 17 +++++++++++++---- scripts/cmd.gd | 2 +- scripts/time_entry.gd | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.gd b/main.gd index f6feaff..7f0a349 100644 --- a/main.gd +++ b/main.gd @@ -1,20 +1,28 @@ #!/usr/bin/env -S godot --headless -s extends SceneTree -var cmd := CMD.new() +var config: ConfigManager = preload("res://config_manager.tres") func _init(): + var cmd := CMD.new() for command in ["list", "stop", "start", "current"]: if cmd.has_argument(command): call(command) + return + print("no command provided -- exiting") + quit() func list() -> void: - pass + var entries := config.timesheet.entries + for item in entries: + print(item) + quit() func stop() -> void: - pass + if config.timesheet.current_entry: + config.timesheet.close_entry() func start() -> void: @@ -22,4 +30,5 @@ func start() -> void: func current() -> void: - pass + if config.timesheet.current_entry: + print("{name}\t{start_time}\t{end_time}"%config.timesheet.current_entry) diff --git a/scripts/cmd.gd b/scripts/cmd.gd index f4810c6..4c220e0 100644 --- a/scripts/cmd.gd +++ b/scripts/cmd.gd @@ -7,7 +7,7 @@ class_name CMD ## unsurround the string ## This function does no evaluation and does not attempt to guess the type of ## arguments. You will receive either bools, or strings. -var command_line_arguments: Dictionary = (func get_command_line_arguments() -> Dictionary: +var command_line_arguments: Dictionary = (func () -> Dictionary: var unsurround := func unsurround(value: String, quotes := PackedStringArray(['"', "'"])) -> String: for quote_str in quotes: if value.begins_with(quote_str) \ diff --git a/scripts/time_entry.gd b/scripts/time_entry.gd index 099fac9..c87f71b 100644 --- a/scripts/time_entry.gd +++ b/scripts/time_entry.gd @@ -75,3 +75,5 @@ func from_csv_line(line: PackedStringArray) -> TimeEntry: end_time.from_current_time() return self +func _to_string() -> String: + return "%s\t%s\t%s"%[name, Consts.ONGOING if closed == false else "", start_time] \ No newline at end of file