-
Notifications
You must be signed in to change notification settings - Fork 204
IP calculator #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
IP calculator #154
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
860f3d4
Implement IP to Integer Conversion as Part of Issue #108
Harisabdullah b0ceb39
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah 7fdd0be
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah a184ba5
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah 17af602
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah 27e310e
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah bdabecf
This commit is a part of Issue #108, which involves implementing the …
Harisabdullah edd3de9
refactoring
Harisabdullah 08801dd
Update ipinfo/cmd_calc.go
Harisabdullah 530454e
Update ipinfo/cmd_calc.go
Harisabdullah 323b2a4
Update ipinfo/cmd_calc.go
Harisabdullah 2f51394
Update ipinfo/cmd_calc.go
Harisabdullah 5fa615a
Update ipinfo/cmd_calc_infix.go
Harisabdullah 444621e
Update ipinfo/cmd_calc_infix.go
Harisabdullah dfd3ef8
Update ipinfo/cmd_calc_infix.go
Harisabdullah ba19d99
Moving 'calc', 'n2ip', 'n2ip6', and 'ip2n' in hep message
Harisabdullah 49ee322
Merge remote-tracking branch 'origin/haris/be-987' into haris/be-987
Harisabdullah 8ce8504
Update ipinfo/cmd_ip2n.go
Harisabdullah 82f406c
Update ipinfo/cmd_ip2n.go
Harisabdullah 92068c9
Update ipinfo/cmd_n2ip.go
Harisabdullah 1a8a3b1
Fixed repetition of progbase, and removed unused flags
Harisabdullah fb5dd9d
Relocated 'calc', 'ip2n', 'n2ip', and 'n2ip6'
Harisabdullah 462a1b5
making flags work
Harisabdullah 4f447d7
Merge remote-tracking branch 'origin/haris/be-987' into haris/be-987
Harisabdullah a7d3129
Moved Logic to lib
Harisabdullah 6129a41
Moved Logic to lib
Harisabdullah 114eeb1
sorting imports
Harisabdullah efffdd4
1) Moving logic to ```lib/```
Harisabdullah c5dc299
1) Fixed a parsing from string to float which was causing information…
Harisabdullah 095ffd2
removed print statement
Harisabdullah 992a32b
Fixed a bug where calc was not accepting alphabets for ipv6
Harisabdullah b5346c9
Updated Comments
Harisabdullah 5f2b34d
Refactor: Moved logic to ```lib/```
Harisabdullah 92bb8f2
- Declared constant for precision while parsing string to float
Harisabdullah 378ac63
- Renamed ```lib/calc_infix.go``` to ```lib/cmd_calc.go```
Harisabdullah 50a58ac
Moved ```StrIsIPv4Str``` and ```StrIsIPv6Str``` to ```lib/ip_str.go```
Harisabdullah a28331d
Moved ```StrIsIPv4Str``` and ```StrIsIPv6Str``` to ```lib/ip_str.go```
Harisabdullah 7e652c1
Update lib/cmd_calc.go
Harisabdullah 52a91f1
Update lib/cmd_calc.go
Harisabdullah 6ac24da
Update lib/cmd_calc.go
Harisabdullah c012c93
Update lib/cmd_calc.go
Harisabdullah addd2dd
Update lib/cmd_calc.go
Harisabdullah 2f77e43
Update lib/cmd_calc.go
Harisabdullah 5e55a89
Update lib/cmd_calc.go
Harisabdullah aa50cae
Suggested changes applied
Harisabdullah 8586480
Update lib/cmd_calc.go
Harisabdullah 360c610
* Nested `n2ip, n2ip6, and ip2n` sub commands inside `tool` sub command
Harisabdullah 8efc978
Merge remote-tracking branch 'origin/haris/be-987' into haris/be-987
Harisabdullah 55fa316
Removed unnecessary color flags
Harisabdullah 5bd8496
Update lib/cmd_tool_n2ip.go
Harisabdullah ab8fbb0
- Regex is now global to avoid redundant compilation
Harisabdullah 2644c1f
Update lib/cmd_tool_n2ip6.go
Harisabdullah 7fc3cc6
`MustCompilePOSIX`instead of `MustCompile`.
Harisabdullah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,45 @@ | ||
| 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 completionsCalc = &complete.Command{ | ||
| Flags: map[string]complete.Predictor{ | ||
| "-h": predict.Nothing, | ||
| "--help": predict.Nothing, | ||
| }, | ||
| } | ||
|
|
||
| // printHelpCalc prints the help message for the "calc" command. | ||
| func printHelpCalc() { | ||
| fmt.Printf( | ||
| `Usage: %s calc <expression> [<opts>] | ||
|
|
||
| Description: | ||
| Evaluate a mathematical expression and print the result. | ||
|
|
||
| Examples: | ||
| %[1]s calc "2*2828-1" | ||
| %[1]s calc "190.87.89.1*2" | ||
| %[1]s calc "2001:0db8:85a3:0000:0000:8a2e:0370:7334*6" | ||
|
|
||
| Options: | ||
| General: | ||
| --help, -h | ||
| show help. | ||
| `, progBase) | ||
| } | ||
|
|
||
| // cmdCalc is the handler for the "calc" command. | ||
| func cmdCalc() error { | ||
| f := lib.CmdCalcFlags{} | ||
| f.Init() | ||
| pflag.Parse() | ||
|
|
||
|
Harisabdullah marked this conversation as resolved.
|
||
| return lib.CmdCalc(f, pflag.Args()[1:], printHelpCalc) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| 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 completionsToolIP2n = &complete.Command{ | ||
| Flags: map[string]complete.Predictor{ | ||
| "-h": predict.Nothing, | ||
| "--help": predict.Nothing, | ||
| }, | ||
| } | ||
|
|
||
| // printHelpToolIp2n prints the help message for the "ip2n" command. | ||
| func printHelpToolIp2n() { | ||
| fmt.Printf( | ||
| `Usage: %s tool ip2n <ip> | ||
|
|
||
| Description: | ||
| Converts an IPv4 or IPv6 address to its decimal representation. | ||
|
|
||
| Examples: | ||
| %[1]s ip2n "190.87.89.1" | ||
| %[1]s ip2n "2001:0db8:85a3:0000:0000:8a2e:0370:7334" | ||
| %[1]s ip2n "2001:0db8:85a3::8a2e:0370:7334" | ||
| %[1]s ip2n "::7334" | ||
| %[1]s ip2n "7334::" | ||
|
|
||
| Options: | ||
| General: | ||
| --help, -h | ||
| show help. | ||
| `, progBase) | ||
| } | ||
|
|
||
| // cmdToolIP2n is the handler for the "ip2n" command. | ||
| func cmdToolIP2n() error { | ||
| f := lib.CmdToolIP2nFlags{} | ||
| f.Init() | ||
| pflag.Parse() | ||
|
|
||
| return lib.CmdToolIP2n(f, pflag.Args()[2:], printHelpToolIp2n) | ||
| } |
This file contains hidden or 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,53 @@ | ||
| 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" | ||
| ) | ||
|
|
||
| // cmdToolN2IP is the handler for the "n2ip" command. | ||
| var completionsToolN2IP = &complete.Command{ | ||
| Flags: map[string]complete.Predictor{ | ||
| "-h": predict.Nothing, | ||
| "--help": predict.Nothing, | ||
| "-6": predict.Set(predictReadFmts), | ||
| "--ipv6": predict.Set(predictReadFmts), | ||
| }, | ||
| } | ||
|
|
||
| // printHelpToolN2IP prints the help message for the "n2ip" command. | ||
| func printHelpToolN2IP() { | ||
| fmt.Printf( | ||
| `Usage: %s n2ip tool [<opts>] <number> | ||
|
|
||
| Description: | ||
| Converts a given numeric representation to its corresponding IPv4 or IPv6 address, | ||
| and can also evaluate a mathematical expression for conversion. | ||
|
|
||
| Examples: | ||
| %[1]s n2ip "4294967295 + 87" | ||
| %[1]s n2ip "4294967295" --ipv6 | ||
| %[1]s n2ip -6 "201523715" | ||
| %[1]s n2ip "51922968585348276285304963292200960" | ||
| %[1]s n2ip "a:: - 4294967295" | ||
|
|
||
| Options: | ||
| General: | ||
| --help, -h | ||
| show help. | ||
| --ipv6, -6 | ||
| force conversion to IPv6 address | ||
| `, progBase) | ||
| } | ||
|
|
||
| // cmdToolN2IP is the handler for the "n2ip" command. | ||
| func cmdToolN2IP() error { | ||
| f := lib.CmdToolN2IPFlags{} | ||
| f.Init() | ||
| pflag.Parse() | ||
|
|
||
| return lib.CmdToolN2IP(f, pflag.Args()[2:], printHelpToolN2IP) | ||
| } |
This file contains hidden or 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,48 @@ | ||
| 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 completionsToolN2IP6 = &complete.Command{ | ||
| Flags: map[string]complete.Predictor{ | ||
| "-h": predict.Nothing, | ||
| "--help": predict.Nothing, | ||
| }, | ||
| } | ||
|
|
||
| // printHelpToolN2IP6 prints the help message for the "n2ip6" command. | ||
| func printHelpToolN2IP6() { | ||
| fmt.Printf( | ||
| `Usage: %s tool n2ip6 [<opts>] <number> | ||
|
|
||
| Description: | ||
| Converts a given numeric representation to its corresponding IPv6 address, | ||
| and can also evaluate a mathematical expression for conversion. | ||
|
|
||
| Examples: | ||
| %[1]s n2ip6 "4294967295 + 87" | ||
| %[1]s n2ip6 "4294967295" | ||
| %[1]s n2ip6 "201523715" | ||
| %[1]s n2ip6 "51922968585348276285304963292200960" | ||
| %[1]s n2ip6 "a:: - 4294967295" | ||
|
|
||
| Options: | ||
| General: | ||
| --help, -h | ||
| show help. | ||
| `, progBase) | ||
| } | ||
|
|
||
| // cmdToolN2IP6 is the handler for the "n2ip6" command. | ||
| func cmdToolN2IP6() error { | ||
| f := lib.CmdToolN2IP6Flags{} | ||
| f.Init() | ||
| pflag.Parse() | ||
|
|
||
| return lib.CmdToolN2IP6(f, pflag.Args()[2:], printHelpToolN2IP6) | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.