-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ipinfo/v2
v2
- Loading branch information
Showing
190 changed files
with
26,521 additions
and
632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
.vim/ | ||
ipinfo/dist/ | ||
grepip/dist/ | ||
cidr2range/dist/ | ||
range2cidr/dist/ | ||
!ipinfo/dist/DEBIAN/ | ||
!grepip/dist/DEBIAN/ | ||
!cidr2range/dist/DEBIAN/ | ||
!range2cidr/dist/DEBIAN/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Build binary for all platforms for version $1. | ||
|
||
set -e | ||
|
||
DIR=`dirname $0` | ||
ROOT=$DIR/.. | ||
|
||
VSN=$1 | ||
|
||
$ROOT/scripts/build-all-platforms.sh "cidr2range" $VSN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Build local binary. | ||
|
||
set -e | ||
|
||
DIR=`dirname $0` | ||
ROOT=$DIR/.. | ||
|
||
$ROOT/scripts/build.sh "cidr2range" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ipinfo/cli/lib/complete" | ||
"github.com/ipinfo/cli/lib/complete/predict" | ||
) | ||
|
||
var completions = &complete.Command{ | ||
Flags: map[string]complete.Predictor{ | ||
"-v": predict.Nothing, | ||
"--version": predict.Nothing, | ||
"-h": predict.Nothing, | ||
"--help": predict.Nothing, | ||
"--completions-install": predict.Nothing, | ||
"--completions-bash": predict.Nothing, | ||
"--completions-zsh": predict.Nothing, | ||
"--completions-fish": predict.Nothing, | ||
}, | ||
} | ||
|
||
func handleCompletions() { | ||
completions.Complete(progBase) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
|
||
VSN=1.0.0 | ||
|
||
curl -LO https://github.com/ipinfo/cli/releases/download/cidr2range-${VSN}/cidr2range_${VSN}.deb | ||
sudo dpkg -i cidr2range_${VSN}.deb | ||
rm cidr2range_${VSN}.deb | ||
|
||
echo | ||
echo 'You can now run `cidr2range`'. | ||
|
||
if [ -f "$0" ]; then | ||
rm $0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Source: cidr2range | ||
Section: utils | ||
Version: 1.0.0 | ||
Priority: optional | ||
Maintainer: IPinfo <[email protected]> | ||
Vcs-Git: https://github.com/ipinfo/cli | ||
Vcs-browser: https://github.com/ipinfo/cli | ||
Homepage: https://ipinfo.io | ||
Package: cidr2range | ||
Architecture: amd64 | ||
Description: A simple tool for converting from CIDRs to IP ranges. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
VSN=1.0.0 | ||
PLAT=darwin_amd64 | ||
|
||
curl -LO https://github.com/ipinfo/cli/releases/download/cidr2range-${VSN}/cidr2range_${VSN}_${PLAT}.tar.gz | ||
tar -xf cidr2range_${VSN}_${PLAT}.tar.gz | ||
rm cidr2range_${VSN}_${PLAT}.tar.gz | ||
mv cidr2range_${VSN}_${PLAT} /usr/local/bin/cidr2range | ||
|
||
echo | ||
echo 'You can now run `cidr2range`'. | ||
|
||
if [ -f "$0" ]; then | ||
rm $0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/fatih/color" | ||
"github.com/ipinfo/cli/lib" | ||
"github.com/ipinfo/cli/lib/complete/install" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
var progBase = filepath.Base(os.Args[0]) | ||
var version = "1.0.0" | ||
|
||
func printHelp() { | ||
fmt.Printf( | ||
`Usage: %s [<opts>] <cidr | filepath> | ||
Description: | ||
Accepts CIDRs and file paths to files containing CIDRs, converting them all | ||
to IP ranges. | ||
If a file is input, it is assumed that the CIDR to convert is the first entry | ||
of each line (separated by '\n'). All other data remains the same. | ||
The IP range output is of the form "<start>-<end>" where "<start>" comes | ||
before or is equal to "<end>" in numeric value. | ||
Examples: | ||
# Get the range for CIDR 1.1.1.0/30. | ||
$ %[1]s 1.1.1.0/30 | ||
# Convert CIDR entries to IP ranges in 2 files. | ||
$ %[1]s /path/to/file1.txt /path/to/file2.txt | ||
# Convert CIDR entries to IP ranges from stdin. | ||
$ cat /path/to/file1.txt | %[1]s | ||
# Convert CIDR entries to IP ranges from stdin and a file. | ||
$ cat /path/to/file1.txt | %[1]s /path/to/file2.txt | ||
Options: | ||
General: | ||
--version, -v | ||
show binary release number. | ||
--help, -h | ||
show help. | ||
Completions: | ||
--completions-install | ||
attempt completions auto-installation for any supported shell. | ||
--completions-bash | ||
output auto-completion script for bash for manual installation. | ||
--completions-zsh | ||
output auto-completion script for zsh for manual installation. | ||
--completions-fish | ||
output auto-completion script for fish for manual installation. | ||
`, progBase) | ||
} | ||
|
||
func cmd() error { | ||
var fVsn bool | ||
var fCompletionsInstall bool | ||
var fCompletionsBash bool | ||
var fCompletionsZsh bool | ||
var fCompletionsFish bool | ||
|
||
f := lib.CmdCIDR2RangeFlags{} | ||
f.Init() | ||
pflag.BoolVarP( | ||
&fVsn, | ||
"version", "v", false, | ||
"print binary release number.", | ||
) | ||
pflag.BoolVarP( | ||
&fCompletionsInstall, | ||
"completions-install", "", false, | ||
"attempt completions auto-installation for any supported shell.", | ||
) | ||
pflag.BoolVarP( | ||
&fCompletionsBash, | ||
"completions-bash", "", false, | ||
"output auto-completion script for bash for manual installation.", | ||
) | ||
pflag.BoolVarP( | ||
&fCompletionsZsh, | ||
"completions-zsh", "", false, | ||
"output auto-completion script for zsh for manual installation.", | ||
) | ||
pflag.BoolVarP( | ||
&fCompletionsFish, | ||
"completions-fish", "", false, | ||
"output auto-completion script for fish for manual installation.", | ||
) | ||
pflag.Parse() | ||
|
||
if fVsn { | ||
fmt.Println(version) | ||
return nil | ||
} | ||
|
||
if fCompletionsInstall { | ||
return install.Install(progBase) | ||
} | ||
if fCompletionsBash { | ||
installStr, err := install.BashCmd(progBase) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(installStr) | ||
return nil | ||
} | ||
if fCompletionsZsh { | ||
installStr, err := install.ZshCmd(progBase) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(installStr) | ||
return nil | ||
} | ||
if fCompletionsFish { | ||
installStr, err := install.FishCmd(progBase) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(installStr) | ||
return nil | ||
} | ||
|
||
return lib.CmdCIDR2Range(f, pflag.Args(), printHelp) | ||
} | ||
|
||
func main() { | ||
// obey NO_COLOR env var. | ||
if os.Getenv("NO_COLOR") != "" { | ||
color.NoColor = true | ||
} | ||
|
||
handleCompletions() | ||
|
||
if err := cmd(); err != nil { | ||
fmt.Printf("err: %v\n", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Build and upload (to GitHub) for all platforms for version $1. | ||
|
||
set -e | ||
|
||
DIR=`dirname $0` | ||
ROOT=$DIR/.. | ||
|
||
VSN=$1 | ||
|
||
$ROOT/scripts/release.sh "cidr2range" $VSN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.