Skip to content

Commit

Permalink
空输入增加提示功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed Dec 22, 2021
1 parent 90b9d09 commit dcd92ba
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
60 changes: 60 additions & 0 deletions internal/cli/help.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 0 additions & 1 deletion internal/cli/help_windows.go

This file was deleted.

4 changes: 4 additions & 0 deletions internal/cli/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"fofax/internal/fxparser"
"fofax/internal/printer"
"fofax/internal/utils"
"math/rand"
"os"
"path/filepath"
"strings"
"time"

"fofax/internal/goflags"
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dcd92ba

Please sign in to comment.