diff --git a/ipinfo/cmd_default.go b/ipinfo/cmd_default.go index ddb0de10..887868ac 100644 --- a/ipinfo/cmd_default.go +++ b/ipinfo/cmd_default.go @@ -77,6 +77,68 @@ Options: `, progBase) } +var detailedHelp = fmt.Sprintf(`Usage: %s [] [] + +Commands: + look up details for an IP address, e.g. 8.8.8.8. + look up details for an ASN, e.g. AS123 or as123. + myip get details for your IP. + bulk get details for multiple IPs in bulk. + asn tools related to ASNs. + summarize get summarized data for a group of IPs. + map open a URL to a map showing the locations of a group of IPs. + prips print IP list from CIDR or range. + grepip grep for IPs matching criteria from any source. + matchip print the overlapping IPs and subnets. + grepdomain grep for domains matching criteria from any source. + cidr2range convert CIDRs to IP ranges. + cidr2ip convert CIDRs to individual IPs within those CIDRs. + range2cidr convert IP ranges to CIDRs. + range2ip convert IP ranges to individual IPs within those ranges. + randip Generates random IPs. + splitcidr splits a larger CIDR into smaller CIDRs. + mmdb read, import and export mmdb files. + calc evaluates a mathematical expression that may contain IP addresses. + tool misc. tools related to IPs, IP ranges and CIDRs. + download download free ipinfo database files. + cache manage the cache. + config manage the config. + quota print the request quota of your account. + init login or signup account. + logout delete your current API token session. + completion install or output shell auto-completion script. + version show current version. + +Options: + General: + --token , -t + use as API token. + --nocache + do not use the cache. + --version, -v + show binary release number. + --help, -h + show help. + + Outputs: + --field , -f + lookup only specific fields in the output. + field names correspond to JSON keys, e.g. 'hostname' or 'company.type'. + multiple field names must be separated by commas. + --nocolor + disable colored output. + + Formats: + --pretty, -p + output pretty format. + --json, -j + output JSON format. + --csv, -c + output CSV format. + --yaml, -y + output YAML format. +`, progBase) + func cmdDefault() (err error) { var ips []net.IP var fTok string @@ -90,7 +152,8 @@ func cmdDefault() (err error) { pflag.StringVarP(&fTok, "token", "t", "", "the token to use.") pflag.BoolVar(&fNoCache, "nocache", false, "disable the cache.") pflag.BoolVarP(&fVsn, "version", "v", false, "print binary release number.") - pflag.BoolVarP(&fHelp, "help", "h", false, "show help.") + pflag.BoolVarP(&fHelp, "", "h", false, "show help.") + pflag.BoolVar(&fHelpDetailed, "help", false, "show detailed help") pflag.StringSliceVarP(&fField, "field", "f", nil, "specific field to lookup.") pflag.BoolVarP(&fPretty, "pretty", "p", true, "output pretty format.") pflag.BoolVarP(&fJSON, "json", "j", true, "output JSON format. (default)") @@ -108,6 +171,12 @@ func cmdDefault() (err error) { return nil } + if fHelpDetailed { + // Read the string and display it using a pager + lib.HelpDetailed(detailedHelp, printHelpDefault) + return nil + } + if fVsn { fmt.Println(version) return nil diff --git a/ipinfo/main.go b/ipinfo/main.go index ede35331..53343841 100644 --- a/ipinfo/main.go +++ b/ipinfo/main.go @@ -15,6 +15,7 @@ var version = "3.2.0" // global flags. var fHelp bool +var fHelpDetailed bool var fNoCache bool var fNoColor bool diff --git a/lib/help_detailed.go b/lib/help_detailed.go new file mode 100644 index 00000000..00fb72f6 --- /dev/null +++ b/lib/help_detailed.go @@ -0,0 +1,29 @@ +package lib + +import ( + "io" + "os" + "os/exec" + "strings" +) + +func HelpDetailed(detailedHelp string, printHelpDefault func()) error { + pagerCmd := os.Getenv("PAGER") + if pagerCmd == "" { + // If PAGER is not set, use a default pager (e.g., less) + pagerCmd = "less" + } + + cmd := exec.Command(pagerCmd) + reader := io.Reader(strings.NewReader(detailedHelp)) + cmd.Stdin = reader + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + // If an error occurs running the pager, display the default help + if err := cmd.Run(); err != nil { + printHelpDefault() + } + + return nil +}