forked from daBONDi/go-rest-wol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellArgs.go
More file actions
53 lines (42 loc) · 1.19 KB
/
shellArgs.go
File metadata and controls
53 lines (42 loc) · 1.19 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
/* Processing and handling Shell Arguments */
package main
import (
"log"
"os"
"strconv"
)
// Processing Shell Arguments
func processShellArgs() (int, string) {
// Reading Shell Args
shellArgs := os.Args[1:]
filepath := DefaultComputerFilePath
port := DefaultHTTPPort
for i, arg := range shellArgs {
// Process Shell Args --port
if arg == "--port" {
// Ensure Port Argument has a following up Argument
if i+1 <= len(shellArgs) {
// Ensure we can Parse the Port Argument Value
var err error
if port, err = strconv.Atoi(shellArgs[i+1]); err != nil {
log.Fatalf("Could not find or parse ArgumentValue --port to Integer \"%s\"", shellArgs[i+1])
}
}
}
// Process Shell Args --file
if arg == "--file" {
// Ensure we got a shell Argument afterwards
if i+1 <= len(shellArgs) {
// Ensure passed File Argument Value is something
if len(shellArgs[i+1]) > 0 {
filepath = shellArgs[i+1]
}
}
}
}
// Try to Stat the File if not Fail Fatal
if !FileExists(filepath) {
log.Fatalf("Could not find or access Computerlist --file Argument Value: \"%s\"", filepath)
}
return port, filepath
}