Skip to content

Commit

Permalink
Merge pull request #75 from rm-Umar/master
Browse files Browse the repository at this point in the history
Added prips binary
  • Loading branch information
UmanShahzad authored Nov 17, 2021
2 parents c9cb4e2 + c2f3b24 commit ca244d1
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Replace `<path>` with the required location.

## Additional CLIs

The `ipinfo` CLI has some subcommands like `grepip`, `cidr2range`, `cidr2ip`,
The `ipinfo` CLI has some subcommands like `grepip`, `prips`, `cidr2range`, `cidr2ip`,
`range2cidr`, `range2ip` and `randip` which are also shipped as standalone binaries.

These binaries are available via all the **same installation methods** as
Expand All @@ -146,6 +146,7 @@ Currently these subcommands are separately shipped:
| CLI | Version |
| ---------- | ------- |
| grepip | [1.2.1](https://github.com/ipinfo/cli/releases/tag/grepip-1.2.1) |
| prips | [1.0.0](https://github.com/ipinfo/cli/releases/tag/prips-1.0.0) |
| cidr2range | [1.2.0](https://github.com/ipinfo/cli/releases/tag/cidr2range-1.2.0) |
| cidr2ip | [1.0.0](https://github.com/ipinfo/cli/releases/tag/cidr2ip-1.0.0) |
| range2cidr | [1.2.0](https://github.com/ipinfo/cli/releases/tag/range2cidr-1.2.0) |
Expand Down
12 changes: 12 additions & 0 deletions prips/build-all-platforms.sh
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
10 changes: 10 additions & 0 deletions prips/build.sh
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"
23 changes: 23 additions & 0 deletions prips/completions.go
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)
}
14 changes: 14 additions & 0 deletions prips/deb.sh
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
11 changes: 11 additions & 0 deletions prips/dist/DEBIAN/control
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.
16 changes: 16 additions & 0 deletions prips/macos.sh
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
129 changes: 129 additions & 0 deletions prips/main.go
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)
}
}
12 changes: 12 additions & 0 deletions prips/release.sh
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
1 change: 1 addition & 0 deletions scripts/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gofmt -w \
$ROOT/lib \
$ROOT/ipinfo \
$ROOT/grepip \
$ROOT/prips \
$ROOT/cidr2range \
$ROOT/range2cidr \
$ROOT/range2ip \
Expand Down
1 change: 1 addition & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ golint \
./lib/... \
./ipinfo/... \
./grepip/... \
./prips/... \
./cidr2range/... \
./range2cidr/... \
./range2ip/... \
Expand Down

0 comments on commit ca244d1

Please sign in to comment.