-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
77 lines (59 loc) · 1.38 KB
/
helper.go
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
69
70
71
72
73
74
75
76
77
package main
import (
"file_transfer_protocol/file_components"
"flag"
"fmt"
"net"
"os"
)
// This functions handles logic behind args or flag of cli commands.
func argHandler(filepath *string, useQuit *bool, useViewFile *string, usePreview *bool, currentIp *bool) {
// if flag.NArg() == 0 || flag.Arg(0) != "fsa" {
// fmt.Println("correct command required")
// os.Exit(1)
// }
if *useQuit {
quitFlag(useQuit)
}
if *filepath != "" {
file_components.ReadFileFromPath(filepath)
}
if *currentIp {
displayAddress()
os.Exit(0)
}
if *useViewFile == "" {
flag.Usage()
os.Exit(1)
} else {
file_components.MarkDownRun(*useViewFile, *usePreview)
}
}
// this function when called exits the cli
func quitFlag(useQuit *bool) {
if *useQuit {
// logic if user enter "-q or --q arguments"
os.Exit(0)
}
}
func displayAddress() {
interfaces, err := net.Interfaces()
if err != nil {
fmt.Println("Error getting interfaces:", err)
return
}
for _, iface := range interfaces {
// Get the addresses associated with the current interface
addrs, err := iface.Addrs()
if err != nil {
fmt.Println("Error getting addresses for interface", iface.Name, ":", err)
continue
}
// Print the IP addresses associated with the current interface
fmt.Println("IP Addresses for interface", iface.Name+":")
for _, addr := range addrs {
fmt.Println(addr)
}
}
return
}