Skip to content

Commit c2edb95

Browse files
authored
Merge pull request #194 from Taimoor-12/adding-manpages
ipinfo man page
2 parents f3be503 + 9c328c6 commit c2edb95

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

ipinfo/cmd_default.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,68 @@ Options:
7777
`, progBase)
7878
}
7979

80+
var detailedHelp = fmt.Sprintf(`Usage: %s <cmd> [<opts>] [<args>]
81+
82+
Commands:
83+
<ip> look up details for an IP address, e.g. 8.8.8.8.
84+
<asn> look up details for an ASN, e.g. AS123 or as123.
85+
myip get details for your IP.
86+
bulk get details for multiple IPs in bulk.
87+
asn tools related to ASNs.
88+
summarize get summarized data for a group of IPs.
89+
map open a URL to a map showing the locations of a group of IPs.
90+
prips print IP list from CIDR or range.
91+
grepip grep for IPs matching criteria from any source.
92+
matchip print the overlapping IPs and subnets.
93+
grepdomain grep for domains matching criteria from any source.
94+
cidr2range convert CIDRs to IP ranges.
95+
cidr2ip convert CIDRs to individual IPs within those CIDRs.
96+
range2cidr convert IP ranges to CIDRs.
97+
range2ip convert IP ranges to individual IPs within those ranges.
98+
randip Generates random IPs.
99+
splitcidr splits a larger CIDR into smaller CIDRs.
100+
mmdb read, import and export mmdb files.
101+
calc evaluates a mathematical expression that may contain IP addresses.
102+
tool misc. tools related to IPs, IP ranges and CIDRs.
103+
download download free ipinfo database files.
104+
cache manage the cache.
105+
config manage the config.
106+
quota print the request quota of your account.
107+
init login or signup account.
108+
logout delete your current API token session.
109+
completion install or output shell auto-completion script.
110+
version show current version.
111+
112+
Options:
113+
General:
114+
--token <tok>, -t <tok>
115+
use <tok> as API token.
116+
--nocache
117+
do not use the cache.
118+
--version, -v
119+
show binary release number.
120+
--help, -h
121+
show help.
122+
123+
Outputs:
124+
--field <field>, -f <field>
125+
lookup only specific fields in the output.
126+
field names correspond to JSON keys, e.g. 'hostname' or 'company.type'.
127+
multiple field names must be separated by commas.
128+
--nocolor
129+
disable colored output.
130+
131+
Formats:
132+
--pretty, -p
133+
output pretty format.
134+
--json, -j
135+
output JSON format.
136+
--csv, -c
137+
output CSV format.
138+
--yaml, -y
139+
output YAML format.
140+
`, progBase)
141+
80142
func cmdDefault() (err error) {
81143
var ips []net.IP
82144
var fTok string
@@ -90,7 +152,8 @@ func cmdDefault() (err error) {
90152
pflag.StringVarP(&fTok, "token", "t", "", "the token to use.")
91153
pflag.BoolVar(&fNoCache, "nocache", false, "disable the cache.")
92154
pflag.BoolVarP(&fVsn, "version", "v", false, "print binary release number.")
93-
pflag.BoolVarP(&fHelp, "help", "h", false, "show help.")
155+
pflag.BoolVarP(&fHelp, "", "h", false, "show help.")
156+
pflag.BoolVar(&fHelpDetailed, "help", false, "show detailed help")
94157
pflag.StringSliceVarP(&fField, "field", "f", nil, "specific field to lookup.")
95158
pflag.BoolVarP(&fPretty, "pretty", "p", true, "output pretty format.")
96159
pflag.BoolVarP(&fJSON, "json", "j", true, "output JSON format. (default)")
@@ -108,6 +171,12 @@ func cmdDefault() (err error) {
108171
return nil
109172
}
110173

174+
if fHelpDetailed {
175+
// Read the string and display it using a pager
176+
lib.HelpDetailed(detailedHelp, printHelpDefault)
177+
return nil
178+
}
179+
111180
if fVsn {
112181
fmt.Println(version)
113182
return nil

ipinfo/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var version = "3.2.0"
1515

1616
// global flags.
1717
var fHelp bool
18+
var fHelpDetailed bool
1819
var fNoCache bool
1920
var fNoColor bool
2021

lib/help_detailed.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package lib
2+
3+
import (
4+
"io"
5+
"os"
6+
"os/exec"
7+
"strings"
8+
)
9+
10+
func HelpDetailed(detailedHelp string, printHelpDefault func()) error {
11+
pagerCmd := os.Getenv("PAGER")
12+
if pagerCmd == "" {
13+
// If PAGER is not set, use a default pager (e.g., less)
14+
pagerCmd = "less"
15+
}
16+
17+
cmd := exec.Command(pagerCmd)
18+
reader := io.Reader(strings.NewReader(detailedHelp))
19+
cmd.Stdin = reader
20+
cmd.Stdout = os.Stdout
21+
cmd.Stderr = os.Stderr
22+
23+
// If an error occurs running the pager, display the default help
24+
if err := cmd.Run(); err != nil {
25+
printHelpDefault()
26+
}
27+
28+
return nil
29+
}

0 commit comments

Comments
 (0)