Clean up Main.gd, improve CLI and rename 'cli' command to 'apply' - implements #48
This commit is contained in:
parent
fee1c64775
commit
168cb036be
1 changed files with 90 additions and 75 deletions
25
src/Main.gd
25
src/Main.gd
|
@ -11,7 +11,12 @@ const BATCH_MODE_SUPPORTED_EXTS = [
|
|||
func show_help():
|
||||
print(
|
||||
"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",
|
||||
" --output PATH Where to write the resulting image to.\n",
|
||||
" In batch mode, this must be a folder.\n",
|
||||
|
@ -41,9 +46,10 @@ func cli_handle_errors(errors: Array) -> int:
|
|||
printerr(e)
|
||||
return n_errors
|
||||
|
||||
func _ready():
|
||||
var args = OS.get_cmdline_args()
|
||||
if "cmd" in args: # commandline interface
|
||||
func cli(args: PackedStringArray):
|
||||
print(
|
||||
"~ Fragmented CLI ~\n",
|
||||
"-================-\n")
|
||||
if "help" in args:
|
||||
show_help()
|
||||
get_tree().quit(1)
|
||||
|
@ -100,7 +106,8 @@ func _ready():
|
|||
get_tree().quit(0)
|
||||
else:
|
||||
get_tree().quit(1)
|
||||
else:
|
||||
|
||||
func prepare_gui():
|
||||
update_title()
|
||||
# position windows
|
||||
get_window().position = Vector2i(
|
||||
|
@ -114,6 +121,14 @@ func _ready():
|
|||
if 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 = ""):
|
||||
if current_file == "":
|
||||
get_window().title = app_name + " - Viewer"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue