/
command.go
64 lines (51 loc) · 1.24 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package check
import (
"fmt"
stdLog "log"
// backend definition
"github.com/leprechau/ipman/common/ip"
)
// command configuration
type config struct {
v4 bool
v6 bool
ipbe string
}
// Command is a Command implementation for the check operation
type Command struct {
Self string
Log *stdLog.Logger
config *config
ip ip.Backend
}
// Run is a function to run the command
func (c *Command) Run(args []string) int {
var err error
// init flags
if err = c.setupFlags(args); err != nil {
c.Log.Printf("[Error] Failed to init flags: %s", err.Error())
return 1
}
// check ip
if err = c.checkIP(); err != nil {
c.Log.Printf("[Error] Failed to check addresses: %s", err.Error())
return 1
}
// exit clean
return 0
}
// Synopsis shows the command summary
func (c *Command) Synopsis() string {
return "Return current external ip address of local machine."
}
// Help shows the detailed command options
func (c *Command) Help() string {
return fmt.Sprintf(`
Usage: %s cmd [options]
Return current external ip address of local machine.
Options:
-4 Get external IPv4 address if available.
-6 Get external IPv6 address if available.
-ipbe IP lookup backend (local or ipify). (default: ipify)
`, c.Self)
}