-
Notifications
You must be signed in to change notification settings - Fork 154
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 #75 from rm-Umar/master
Added prips binary
- Loading branch information
Showing
11 changed files
with
231 additions
and
1 deletion.
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
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 "prips" $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 "prips" |
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/prips-${VSN}/prips_${VSN}.deb | ||
sudo dpkg -i prips_${VSN}.deb | ||
rm prips_${VSN}.deb | ||
|
||
echo | ||
echo 'You can now run `prips`'. | ||
|
||
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: prips | ||
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: prips | ||
Architecture: amd64 | ||
Description: A tool for printing IPs. |
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/prips-${VSN}/prips_${VSN}_${PLAT}.tar.gz | ||
tar -xf prips_${VSN}_${PLAT}.tar.gz | ||
rm prips_${VSN}_${PLAT}.tar.gz | ||
mv prips_${VSN}_${PLAT} /usr/local/bin/prips | ||
|
||
echo | ||
echo 'You can now run `prips`'. | ||
|
||
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,129 @@ | ||
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>] <ip | ip-range | cidr | file> | ||
Description: | ||
Accepts CIDRs (e.g. 8.8.8.0/24) and IP ranges (e.g. 8.8.8.0-8.8.8.255). | ||
Examples: | ||
# List all IPs in a CIDR. | ||
$ %[1]s 8.8.8.0/24 | ||
# List all IPs in multiple CIDRs. | ||
$ %[1]s 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24 | ||
# List all IPs in an IP range. | ||
$ %[1]s 8.8.8.0-8.8.8.255 | ||
# List all IPs in multiple CIDRs and IP ranges. | ||
$ %[1]s 1.1.1.0/30 8.8.8.0-8.8.8.255 2.2.2.0/30 7.7.7.0,7.7.7.10 | ||
# List all IPs from stdin input (newline-separated). | ||
$ echo '1.1.1.0/30\n8.8.8.0-8.8.8.255\n7.7.7.0,7.7.7.10' | %[1]s | ||
Options: | ||
--help, -h | ||
show help. | ||
`, progBase) | ||
} | ||
|
||
func cmd() error { | ||
var fVsn bool | ||
var fCompletionsInstall bool | ||
var fCompletionsBash bool | ||
var fCompletionsZsh bool | ||
var fCompletionsFish bool | ||
|
||
f := lib.CmdPripsFlags{} | ||
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.CmdPrips(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 "prips" $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
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