cli command
This commit is contained in:
		
							
								
								
									
										42
									
								
								main_cli.gd
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										42
									
								
								main_cli.gd
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -3,32 +3,46 @@ extends SceneTree
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var config: ConfigManager = preload("res://config_manager.tres")
 | 
					var config: ConfigManager = preload("res://config_manager.tres")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const valid_commands := ["list", "stop", "start"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _init():
 | 
					func _init():
 | 
				
			||||||
	var cmd := CMD.new()
 | 
						var cmd := CMD.new()
 | 
				
			||||||
	for command in ["list", "stop", "start", "current"]:
 | 
						for command in valid_commands:
 | 
				
			||||||
		if cmd.has_argument(command):
 | 
							if cmd.has_argument(command):
 | 
				
			||||||
			call(command)
 | 
								call(command, cmd.get_argument(command))
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
	print("no command provided -- exiting")
 | 
						print("no command provided -- exiting")
 | 
				
			||||||
	quit()
 | 
						help()
 | 
				
			||||||
 | 
						quit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func list() -> void:
 | 
					func help(_show: bool = true) -> void:
 | 
				
			||||||
 | 
						print("Valid commands are:")
 | 
				
			||||||
 | 
						for command in valid_commands:
 | 
				
			||||||
 | 
							prints(" -",command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func list(show_all: bool = true) -> void:
 | 
				
			||||||
	var entries := config.timesheet.entries
 | 
						var entries := config.timesheet.entries
 | 
				
			||||||
	for item in entries:
 | 
						for item in entries:
 | 
				
			||||||
 | 
							if show_all:
 | 
				
			||||||
 | 
								print(item)
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								if not item.is_closed:
 | 
				
			||||||
				print(item)
 | 
									print(item)
 | 
				
			||||||
	quit()
 | 
						quit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func stop() -> void:
 | 
					func stop(entry_name: String) -> void:
 | 
				
			||||||
	if config.timesheet.current_entry:
 | 
						var success := config.timesheet.stop_entry(entry_name)
 | 
				
			||||||
		config.timesheet.close_entry()
 | 
						if success:
 | 
				
			||||||
 | 
							print("closed %s"%[entry_name])
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							print("could not close %s"%[entry_name])
 | 
				
			||||||
 | 
						quit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func start() -> void:
 | 
					func start(entry_name: String) -> void:
 | 
				
			||||||
	pass
 | 
						# warning-ignore:return_value_discarded
 | 
				
			||||||
 | 
						config.timesheet.add_entry(entry_name)
 | 
				
			||||||
 | 
						quit()
 | 
				
			||||||
func current() -> void:
 | 
					 | 
				
			||||||
	if config.timesheet.current_entry:
 | 
					 | 
				
			||||||
		print("{name}\t{start_time}\t{end_time}"%config.timesheet.current_entry)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,13 +69,20 @@ _global_script_class_icons={
 | 
				
			|||||||
[application]
 | 
					[application]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config/name="Rat Times"
 | 
					config/name="Rat Times"
 | 
				
			||||||
 | 
					run/main_scene="res://ui/composed_ui.tscn"
 | 
				
			||||||
config/use_custom_user_dir=true
 | 
					config/use_custom_user_dir=true
 | 
				
			||||||
config/custom_user_dir_name="rat_times"
 | 
					config/custom_user_dir_name="rat_times"
 | 
				
			||||||
run/low_processor_mode=true
 | 
					run/low_processor_mode=true
 | 
				
			||||||
 | 
					boot_splash/show_image=false
 | 
				
			||||||
 | 
					boot_splash/bg_color=Color( 0.141176, 0.141176, 0.141176, 0 )
 | 
				
			||||||
config/icon="res://assets/logo.png"
 | 
					config/icon="res://assets/logo.png"
 | 
				
			||||||
config/macos_native_icon="res://build/logo.icns"
 | 
					config/macos_native_icon="res://build/logo.icns"
 | 
				
			||||||
config/windows_native_icon="res://build/logo.ico"
 | 
					config/windows_native_icon="res://build/logo.ico"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[debug]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					settings/fps/force_fps=60
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[display]
 | 
					[display]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window/size/width=360
 | 
					window/size/width=360
 | 
				
			||||||
@@ -89,6 +96,14 @@ window/handheld/orientation="portrait"
 | 
				
			|||||||
window/ios/hide_home_indicator=false
 | 
					window/ios/hide_home_indicator=false
 | 
				
			||||||
window/stretch/aspect="keep"
 | 
					window/stretch/aspect="keep"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[gui]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					theme/use_hidpi=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[logging]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					file_logging/log_path="user://logs/rat-times.log"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[rendering]
 | 
					[rendering]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
quality/driver/driver_name="GLES2"
 | 
					quality/driver/driver_name="GLES2"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user