@@ -4,12 +4,77 @@ import (
4
4
"bytes"
5
5
"fmt"
6
6
"io/ioutil"
7
+ "net"
8
+ "net/http"
7
9
"os"
8
10
"os/exec"
9
11
"path"
10
12
"strings"
11
13
)
12
14
15
+ func debugConnection (url string ) bool {
16
+ fmt .Print ("Test connection..." )
17
+ response , err := http .Head (url )
18
+ if err != nil {
19
+ fmt .Println ("Failed" )
20
+ fmt .Println ("Response create failed\n " , err )
21
+ return false
22
+ }
23
+ if response .StatusCode != http .StatusOK {
24
+ fmt .Println ("Failed" )
25
+ return false
26
+ } else {
27
+ fmt .Println ("Success" )
28
+ return true
29
+ }
30
+ }
31
+
32
+ func debug (url string ) bool {
33
+ if url != "--help" {
34
+ fmt .Println ("" +
35
+ "FastGit Debug Tool\n " +
36
+ "==================\n " +
37
+ "Remote Address:" , url )
38
+ fmt .Print ("IP Address: " )
39
+ addr , err := net .LookupIP (strings .Replace (strings .Replace (url , "https://" , "" , - 1 ), "http://" , "" , - 1 ))
40
+ if err != nil {
41
+ fmt .Println ("Unknown" )
42
+ } else {
43
+ fmt .Println (addr )
44
+ }
45
+
46
+ fmt .Print ("Local Address: " )
47
+ resp , err := http .Get ("https://api.ip.sb/ip" )
48
+ defer resp .Body .Close ()
49
+ if err != nil {
50
+ fmt .Println ("Unknown -> " , err )
51
+ } else {
52
+ s , err := ioutil .ReadAll (resp .Body )
53
+ if err != nil {
54
+ fmt .Println ("Unknown -> " , err )
55
+ } else {
56
+ fmt .Printf ("[%s]\n " , strings .Replace (string (s ), "\n " , "" , - 1 ))
57
+ }
58
+ }
59
+
60
+ return debugConnection (url )
61
+ } else {
62
+ fmt .Println ("" +
63
+ "FastGit Debug Command Line Tool\n " +
64
+ "===============================\n " +
65
+ "SYNTAX\n " +
66
+ " fgit debug [URL<string>] [--help]\n " +
67
+ "REMARKS\n " +
68
+ " URL is an optional parameter\n " +
69
+ " We debug https://hub.fastgit.org by default\n " +
70
+ " If you want to debug another URL, enter URL param\n " +
71
+ "EXAMPLE\n " +
72
+ " fgit debug\n " +
73
+ " fgit debug https://fastgit.org" )
74
+ return true
75
+ }
76
+ }
77
+
13
78
func convertToFastGit () bool {
14
79
return convertHelper ("https://github.com" , "https://hub.fastgit.org" )
15
80
}
@@ -48,18 +113,40 @@ func checkErr(err error, msg string, exitCode int) {
48
113
}
49
114
50
115
func main () {
51
- if len (os .Args ) == 1 {
116
+ if len (os .Args ) == 1 || ( len ( os . Args ) == 2 && os . Args [ 1 ] == "--help" ) {
52
117
fmt .Println ("" +
53
118
"FastGit Command Line Tool\n " +
54
119
"=========================\n " +
55
- "We will convert GitHub to FastGit automatically\n " +
56
- "Do everything like git\n " +
57
- "Build by KevinZonda with GoLang" )
120
+ "REMARKS\n " +
121
+ " We will convert GitHub to FastGit automatically\n " +
122
+ " Do everything like git\n " +
123
+ " Build by KevinZonda with GoLang\n " +
124
+ "EXTRA-SYNTAX\n " +
125
+ " fgit debug [URL<string>] [--help]\n " +
126
+ " If you wan to known more about extra-syntax, try to use --help" )
58
127
os .Exit (0 )
59
128
}
60
129
61
130
isConvertToFastGit := false
62
131
isPush := false
132
+
133
+ if os .Args [1 ] == "debug" {
134
+ var isConnectOk bool
135
+ switch len (os .Args ) {
136
+ case 2 :
137
+ isConnectOk = debug ("https://hub.fastgit.org" )
138
+ case 3 :
139
+ isConnectOk = debug (os .Args [2 ])
140
+ default :
141
+ fmt .Println ("Invalid args for debug. If help wanted, use --help arg." )
142
+ }
143
+ if isConnectOk {
144
+ os .Exit (0 )
145
+ } else {
146
+ os .Exit (1 )
147
+ }
148
+ }
149
+
63
150
for i := range os .Args {
64
151
if os .Args [i ] == "push" {
65
152
isPush = true
0 commit comments