rat-times/main_cli.gd

49 lines
1.0 KiB
GDScript3
Raw Permalink Normal View History

2023-03-09 20:26:57 +00:00
#!/usr/bin/env -S godot --no-window -s
2023-03-03 21:44:32 +00:00
extends SceneTree
2023-03-04 14:07:03 +00:00
var config: ConfigManager = preload("res://config_manager.tres")
2023-03-03 21:44:32 +00:00
2023-04-22 21:06:27 +00:00
const valid_commands := ["list", "stop", "start"]
2023-03-03 21:44:32 +00:00
func _init():
2023-03-04 14:07:03 +00:00
var cmd := CMD.new()
2023-04-22 21:06:27 +00:00
for command in valid_commands:
2023-03-03 21:44:32 +00:00
if cmd.has_argument(command):
2023-04-22 21:06:27 +00:00
call(command, cmd.get_argument(command))
2023-03-04 14:07:03 +00:00
return
print("no command provided -- exiting")
2023-04-22 21:06:27 +00:00
help()
quit(1)
func help(_show: bool = true) -> void:
print("Valid commands are:")
for command in valid_commands:
prints(" -",command)
2023-03-03 21:44:32 +00:00
2023-04-22 21:06:27 +00:00
func list(show_all: bool = true) -> void:
2023-03-04 14:07:03 +00:00
var entries := config.timesheet.entries
for item in entries:
2023-04-22 21:06:27 +00:00
if show_all:
print(item)
else:
if not item.is_closed:
print(item)
2023-03-04 14:07:03 +00:00
quit()
2023-03-03 21:44:32 +00:00
2023-04-22 21:06:27 +00:00
func stop(entry_name: String) -> void:
var success := config.timesheet.stop_entry(entry_name)
if success:
print("closed %s"%[entry_name])
else:
print("could not close %s"%[entry_name])
quit()
2023-03-03 21:44:32 +00:00
2023-04-22 21:06:27 +00:00
func start(entry_name: String) -> void:
# warning-ignore:return_value_discarded
config.timesheet.add_entry(entry_name)
quit()