Clean up Main.gd, improve CLI and rename 'cli' command to 'apply' - implements #48

This commit is contained in:
ChaoticByte 2025-01-31 19:50:53 +01:00
parent fee1c64775
commit 168cb036be
No known key found for this signature in database

View file

@ -11,7 +11,12 @@ const BATCH_MODE_SUPPORTED_EXTS = [
func show_help(): func show_help():
print( print(
"Usage:\n\n", "Usage:\n\n",
"./Fragmented cmd --shader PATH [--load-image PATH]\n\n", "./Fragmented <command> <args...>\n\n",
"Commands:\n\n",
" help\n\n",
" | Shows this help text.\n\n",
" apply --shader PATH [--load-image PATH]\n\n",
" | Applies a shader file.\n\n",
" --shader PATH The path to the shader\n", " --shader PATH The path to the shader\n",
" --output PATH Where to write the resulting image to.\n", " --output PATH Where to write the resulting image to.\n",
" In batch mode, this must be a folder.\n", " In batch mode, this must be a folder.\n",
@ -41,9 +46,10 @@ func cli_handle_errors(errors: Array) -> int:
printerr(e) printerr(e)
return n_errors return n_errors
func _ready(): func cli(args: PackedStringArray):
var args = OS.get_cmdline_args() print(
if "cmd" in args: # commandline interface "~ Fragmented CLI ~\n",
"-================-\n")
if "help" in args: if "help" in args:
show_help() show_help()
get_tree().quit(1) get_tree().quit(1)
@ -100,7 +106,8 @@ func _ready():
get_tree().quit(0) get_tree().quit(0)
else: else:
get_tree().quit(1) get_tree().quit(1)
else:
func prepare_gui():
update_title() update_title()
# position windows # position windows
get_window().position = Vector2i( get_window().position = Vector2i(
@ -114,6 +121,14 @@ func _ready():
if Filesystem.last_shader_savepath != "": if Filesystem.last_shader_savepath != "":
ui_container.get_node("Editor")._on_open_shader_dialog_file_selected(Filesystem.last_shader_savepath) ui_container.get_node("Editor")._on_open_shader_dialog_file_selected(Filesystem.last_shader_savepath)
func _ready():
var args = OS.get_cmdline_args()
if len(args) > 0 and args[0] in ["apply", "help"]:
# use the commandline interface
cli(args)
else:
prepare_gui()
func update_title(current_file: String = ""): func update_title(current_file: String = ""):
if current_file == "": if current_file == "":
get_window().title = app_name + " - Viewer" get_window().title = app_name + " - Viewer"