diff --git a/internal/cli/help.go b/internal/cli/help.go index 7f1e458..9545526 100644 --- a/internal/cli/help.go +++ b/internal/cli/help.go @@ -1 +1,61 @@ package cli + +import ( + "fmt" + "math/rand" + "runtime" + "strings" +) + +type fgx struct { + Usage string + Comment string +} + +func (f *fgx) String() string { + return fmt.Sprintf("Comment: %s\nUsage: %s\n", f.Comment, f.Usage) +} + +var UsageLists = []fgx{ + { + Usage: `fofax -q 'fx="google-reverse"' -fe -open`, + Comment: "搜索fx 中 google-reverse 并用浏览器打开, 查询时使用扩展功能必须加 -fe 参数", + }, + { + Usage: `fofax -q 'fx="google-reverse"' -fe`, + Comment: "搜索 fx 中 google-reverse, 查询时使用扩展功能必须加 -fe 参数", + }, + { + Usage: `fofax app="Grafana" -open`, + Comment: `搜索 fofa 语法 app="Grafana" 并用浏览器打开`, + }, + { + Usage: `fofax -s google`, + Comment: "搜索含有 google 的 fx 语句", + }, + { + Usage: `fofax -ss fx-2021-1001`, + Comment: "列出 fx 语句的详细内容", + }, + { + Usage: `fofax -use`, + Comment: "打印 fofa 语法规则", + }, + { + Usage: `fofax -uc https://www.baidu.com -open`, + Comment: "搜索百度网站相同证书的站点, 并用浏览器打开", + }, +} + +func PrintSingleUsage() { + ulen := len(UsageLists) + sug := UsageLists[rand.Intn(ulen)].String() + fmt.Println("Tips:") + if runtime.GOOS == "windows" { + fmt.Println(`windows 命令行下下需要特别注意双引号转义eg: ( 'fx=\"google-reverse\"' )`) + sug := strings.Replace(sug, "fofax", "fofax.exe", 1) + fmt.Println(strings.ReplaceAll(sug, "\"", "\\\"")) + return + } + fmt.Println(sug) +} diff --git a/internal/cli/help_windows.go b/internal/cli/help_windows.go deleted file mode 100644 index 7f1e458..0000000 --- a/internal/cli/help_windows.go +++ /dev/null @@ -1 +0,0 @@ -package cli diff --git a/internal/cli/parser.go b/internal/cli/parser.go index 41117f7..404f9b7 100644 --- a/internal/cli/parser.go +++ b/internal/cli/parser.go @@ -7,9 +7,11 @@ import ( "fofax/internal/fxparser" "fofax/internal/printer" "fofax/internal/utils" + "math/rand" "os" "path/filepath" "strings" + "time" "fofax/internal/goflags" ) @@ -100,6 +102,7 @@ var ( ) func initOptions() { + rand.Seed(time.Now().UnixNano()) args = new(Options) args.FoFaEmail = os.Getenv("FOFA_EMAIL") args.FoFaKey = os.Getenv("FOFA_KEY") @@ -287,6 +290,7 @@ func checkMutFlags() error { if flagNum == 0 && args.Mode != Stdin_Mode { // return errors.New("query are empty") fmt.Print("fofaX is a command line fofa query tool, simple is the best!\n\n") + PrintSingleUsage() os.Exit(0) } if args.Mode != Query_Mode {