@@ -4,12 +4,77 @@ import (
44 "bytes"
55 "fmt"
66 "io/ioutil"
7+ "net"
8+ "net/http"
79 "os"
810 "os/exec"
911 "path"
1012 "strings"
1113)
1214
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+
1378func convertToFastGit () bool {
1479 return convertHelper ("https://github.com" , "https://hub.fastgit.org" )
1580}
@@ -48,18 +113,40 @@ func checkErr(err error, msg string, exitCode int) {
48113}
49114
50115func main () {
51- if len (os .Args ) == 1 {
116+ if len (os .Args ) == 1 || ( len ( os . Args ) == 2 && os . Args [ 1 ] == "--help" ) {
52117 fmt .Println ("" +
53118 "FastGit Command Line Tool\n " +
54119 "=========================\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" )
58127 os .Exit (0 )
59128 }
60129
61130 isConvertToFastGit := false
62131 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+
63150 for i := range os .Args {
64151 if os .Args [i ] == "push" {
65152 isPush = true
0 commit comments