start command line setup
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
[gd_resource type="Resource" script_class="ConfigManager" load_steps=2 format=3 uid="uid://e3yofdasfcli"]
 | 
					[gd_resource type="Resource" script_class="ConfigManager" load_steps=2 format=3]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ext_resource type="Script" path="res://config_manager.gd" id="1_xfu8y"]
 | 
					[ext_resource type="Script" path="res://scripts/config_manager.gd" id="1_xfu8y"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[resource]
 | 
					[resource]
 | 
				
			||||||
script = ExtResource("1_xfu8y")
 | 
					script = ExtResource("1_xfu8y")
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								main.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								main.gd
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env -S godot --headless -s
 | 
				
			||||||
 | 
					extends SceneTree
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var cmd := CMD.new()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _init():
 | 
				
			||||||
 | 
						for command in ["list", "stop", "start", "current"]:
 | 
				
			||||||
 | 
							if cmd.has_argument(command):
 | 
				
			||||||
 | 
								call(command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func list() -> void:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func stop() -> void:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func start() -> void:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func current() -> void:
 | 
				
			||||||
 | 
						pass
 | 
				
			||||||
@@ -12,7 +12,7 @@ config_version=5
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
config/name="Rat Times"
 | 
					config/name="Rat Times"
 | 
				
			||||||
config/description="Track your time(s)s"
 | 
					config/description="Track your time(s)s"
 | 
				
			||||||
run/main_scene="res://Main.tscn"
 | 
					run/main_scene="res://ui/Main.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"
 | 
				
			||||||
config/features=PackedStringArray("4.0")
 | 
					config/features=PackedStringArray("4.0")
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										43
									
								
								scripts/cmd.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								scripts/cmd.gd
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					class_name CMD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Returns a dictionary of all arguments passed after `--` on the command line
 | 
				
			||||||
 | 
					## arguments take one of 2 forms:
 | 
				
			||||||
 | 
					## - `--arg` which is a boolean (using `--no-arg` for `false` is possible)
 | 
				
			||||||
 | 
					## - `--arg=value`. If the value is quoted with `"` or `'`, this function will 
 | 
				
			||||||
 | 
					##    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 unsurround := func unsurround(value: String, quotes := PackedStringArray(['"', "'"])) -> String:
 | 
				
			||||||
 | 
							for quote_str in quotes:
 | 
				
			||||||
 | 
								if value.begins_with(quote_str) \
 | 
				
			||||||
 | 
								and value.ends_with(quote_str) \
 | 
				
			||||||
 | 
								and value[value.length() - 2] != "\\":
 | 
				
			||||||
 | 
									return value.trim_prefix(quote_str).trim_suffix(quote_str).strip_edges()
 | 
				
			||||||
 | 
							return value
 | 
				
			||||||
 | 
						var arguments := {}
 | 
				
			||||||
 | 
						for argument in OS.get_cmdline_user_args():
 | 
				
			||||||
 | 
							argument = argument.lstrip("--").to_lower()
 | 
				
			||||||
 | 
							if argument.find("=") > -1:
 | 
				
			||||||
 | 
								var arg_tuple := argument.split("=")
 | 
				
			||||||
 | 
								var key := arg_tuple[0]
 | 
				
			||||||
 | 
								var value:String = unsurround.call(arg_tuple[1])
 | 
				
			||||||
 | 
								arguments[key] = value
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								var key := argument
 | 
				
			||||||
 | 
								var value := true
 | 
				
			||||||
 | 
								if argument.begins_with("no-"):
 | 
				
			||||||
 | 
									value = false
 | 
				
			||||||
 | 
									key = argument.lstrip("no-")
 | 
				
			||||||
 | 
								arguments[key] = value
 | 
				
			||||||
 | 
						return arguments).call()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func get_argument(name: String, default: Variant = null) -> Variant:
 | 
				
			||||||
 | 
						if command_line_arguments.has(name):
 | 
				
			||||||
 | 
							return command_line_arguments[name]
 | 
				
			||||||
 | 
						return default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func has_argument(name: String) -> bool:
 | 
				
			||||||
 | 
						return command_line_arguments.has(name)
 | 
				
			||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
[gd_scene load_steps=7 format=3 uid="uid://bmlciwscreowf"]
 | 
					[gd_scene load_steps=7 format=3 uid="uid://bmlciwscreowf"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ext_resource type="Theme" uid="uid://bd8ancgbfsvmd" path="res://assets/default_theme.theme" id="1_1mila"]
 | 
					[ext_resource type="Theme" uid="uid://bd8ancgbfsvmd" path="res://assets/default_theme.theme" id="1_2s8h2"]
 | 
				
			||||||
[ext_resource type="Script" path="res://Main.gd" id="1_vrowr"]
 | 
					[ext_resource type="Script" path="res://ui/Main.gd" id="2_sl5q6"]
 | 
				
			||||||
[ext_resource type="AudioStream" uid="uid://cdsbhoidgyx70" path="res://assets/pop.ogg" id="3_o37py"]
 | 
					[ext_resource type="Script" path="res://ui/time_entries_items_tree.gd" id="3_oxqux"]
 | 
				
			||||||
[ext_resource type="Script" path="res://ui/time_entries_items_tree.gd" id="3_wwscb"]
 | 
					[ext_resource type="AudioStream" uid="uid://cdsbhoidgyx70" path="res://assets/pop.ogg" id="4_6ajaq"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="InputEventKey" id="InputEventKey_guuii"]
 | 
					[sub_resource type="InputEventKey" id="InputEventKey_guuii"]
 | 
				
			||||||
device = -1
 | 
					device = -1
 | 
				
			||||||
@@ -20,7 +20,7 @@ anchor_right = 1.0
 | 
				
			|||||||
anchor_bottom = 1.0
 | 
					anchor_bottom = 1.0
 | 
				
			||||||
grow_horizontal = 2
 | 
					grow_horizontal = 2
 | 
				
			||||||
grow_vertical = 2
 | 
					grow_vertical = 2
 | 
				
			||||||
theme = ExtResource("1_1mila")
 | 
					theme = ExtResource("1_2s8h2")
 | 
				
			||||||
theme_type_variation = &"background"
 | 
					theme_type_variation = &"background"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Main" type="MarginContainer" parent="."]
 | 
					[node name="Main" type="MarginContainer" parent="."]
 | 
				
			||||||
@@ -29,7 +29,7 @@ theme_override_constants/margin_left = 5
 | 
				
			|||||||
theme_override_constants/margin_top = 5
 | 
					theme_override_constants/margin_top = 5
 | 
				
			||||||
theme_override_constants/margin_right = 5
 | 
					theme_override_constants/margin_right = 5
 | 
				
			||||||
theme_override_constants/margin_bottom = 5
 | 
					theme_override_constants/margin_bottom = 5
 | 
				
			||||||
script = ExtResource("1_vrowr")
 | 
					script = ExtResource("2_sl5q6")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="VBoxContainer" type="VBoxContainer" parent="Main"]
 | 
					[node name="VBoxContainer" type="VBoxContainer" parent="Main"]
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
@@ -132,7 +132,7 @@ layout_mode = 2
 | 
				
			|||||||
size_flags_horizontal = 3
 | 
					size_flags_horizontal = 3
 | 
				
			||||||
size_flags_vertical = 3
 | 
					size_flags_vertical = 3
 | 
				
			||||||
columns = 2
 | 
					columns = 2
 | 
				
			||||||
script = ExtResource("3_wwscb")
 | 
					script = ExtResource("3_oxqux")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="SettingsWindow" type="Window" parent="Main"]
 | 
					[node name="SettingsWindow" type="Window" parent="Main"]
 | 
				
			||||||
unique_name_in_owner = true
 | 
					unique_name_in_owner = true
 | 
				
			||||||
@@ -235,4 +235,4 @@ This game uses Godot Engine, available under the following license:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
 | 
					[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
 | 
				
			||||||
unique_name_in_owner = true
 | 
					unique_name_in_owner = true
 | 
				
			||||||
stream = ExtResource("3_o37py")
 | 
					stream = ExtResource("4_6ajaq")
 | 
				
			||||||
		Reference in New Issue
	
	Block a user