-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.gd
More file actions
68 lines (55 loc) · 1.59 KB
/
Copy pathmain.gd
File metadata and controls
68 lines (55 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extends Node
var result_code: int = 0
var arguments: Array = []
var options: Dictionary = {}
var commands: Dictionary = {
'install': preload('res://command/install.gd'),
'update': preload('res://command/update.gd'),
}
func _ready() -> void:
_parse_input_args()
if not PackageMetaReader.package_configuration_exists():
printerr('dotpm.json not found in current work directory!')
get_tree().quit(1)
return
var command_node: BaseCommand
var command: String
if arguments.size() > 0 and arguments[0] != 'help':
command = arguments.pop_front()
if commands.has(command):
command_node = commands[command].new()
add_child(command_node)
result_code = command_node.execute(arguments, options)
else:
print('command unknown: "' + command + '"')
print_help()
result_code = 128
else:
print_help()
get_tree().quit(result_code)
queue_free()
func _parse_input_args() -> void:
for input in OS.get_cmdline_args():
if input.begins_with('--'):
var equal_sep = input.find('=')
if equal_sep != -1:
options[input.substr(2, equal_sep - 2)] = input.substr(equal_sep + 1)
else:
options[input.substr(2)] = true
elif input.begins_with('-'):
if input.length() > 2:
options[input.substr(1, 1)[0]] = input.substr(2)
else:
options[input.substr(1, 1)[0]] = true
else:
arguments.append(input)
func print_help() -> void:
var command_node: BaseCommand
print('Available commands:')
for command_name: String in commands:
command_node = commands[command_name].new()
print(
(' ' + command_name + ': ').rpad(15),
command_node.description()
)
command_node.free()