Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ipinfo/cmd_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var completionsTool = &complete.Command{
"aggregate": completionsToolAggregate,
"lower": completionsToolLower,
"upper": completionsToolUpper,
"is_v6": completionsToolIsV6,
"ip2n": completionsToolIP2n,
"n2ip": completionsToolN2IP,
"n2ip6": completionsToolN2IP6,
Expand All @@ -33,6 +34,7 @@ Commands:
aggregate aggregate IPs, IP ranges, and CIDRs.
lower get start IP of IPs, IP ranges, and CIDRs.
upper get end IP of IPs, IP ranges, and CIDRs.
is_v6 check if IPs are IPv6.
ip2n converts an IPv4 or IPv6 address to its decimal representation.
n2ip evaluates a mathematical expression and converts it to an IPv4 or IPv6.
n2ip6 evaluates a mathematical expression and converts it to an IPv6.
Expand Down Expand Up @@ -70,6 +72,8 @@ func cmdTool() error {
err = cmdToolLower()
case cmd == "upper":
err = cmdToolUpper()
case cmd == "is_v6":
err = cmdToolIsV6()
case cmd == "ip2n":
err = cmdToolIP2n()
case cmd == "n2ip":
Expand Down
43 changes: 43 additions & 0 deletions ipinfo/cmd_tool_is_v6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"github.com/ipinfo/cli/lib"
"github.com/ipinfo/cli/lib/complete"
"github.com/ipinfo/cli/lib/complete/predict"
"github.com/spf13/pflag"
)

var completionsToolIsV6 = &complete.Command{
Flags: map[string]complete.Predictor{
"-h": predict.Nothing,
"--help": predict.Nothing,
},
}

func printHelpToolIsV6() {
fmt.Printf(
`Usage: %s tool is_v6 <ip>

Description:
check if IPs are IPv6.

Examples:
$ %[1]s tool is_v6 "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
$ %[1]s tool is_v6 "2001:0db8:85a3::8a2e:0370:7334"
$ %[1]s tool is_v6 "::7334"

Options:
General:
--help, -h
show help.
`, progBase)
}

func cmdToolIsV6() error {
f := lib.CmdToolIsV6Flags{}
f.Init()
pflag.Parse()

return lib.CmdToolIsV6(f, pflag.Args()[2:], printHelpToolIsV6)
}
34 changes: 34 additions & 0 deletions lib/cmd_tool_is_v6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lib

import (
"fmt"
"github.com/spf13/pflag"
)

// CmdToolIsV6Flags are flags expected by CmdToolIsV6.
type CmdToolIsV6Flags struct {
Help bool
}

// Init initializes the common flags available to CmdToolIsV6 with sensible
func (f *CmdToolIsV6Flags) Init() {
pflag.BoolVarP(
&f.Help,
"help", "h", false,
"show help.",
)
}

func CmdToolIsV6(f CmdToolIsV6Flags, args []string, printHelp func()) error {
if f.Help {
printHelp()
return nil
}

op := func(input string, input_type INPUT_TYPE) error {
fmt.Printf("%s %t\n", input, StrIsIPv6Str(input))
return nil
}

return GetInputFrom(args, true, true, op)
}