Skip to content
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

add port format A-B #26

Merged
merged 2 commits into from
Nov 13, 2022
Merged
Changes from 1 commit
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
Next Next commit
add port format A-B
  • Loading branch information
cokeBeer committed Oct 19, 2022
commit 5ee0cb3be2ddfa83f11f3cfe5b3a1b67727f1f0d
26 changes: 22 additions & 4 deletions internal/core/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,27 @@ func getPorts() []int {
thesePorts := []int{}
if value, ok := g.Args["p"]; ok {
for _, port := range strings.Split(value, ",") {
intPort, err := strconv.Atoi(port)
if err == nil && intPort >= 0 && intPort <= 65535 {
thesePorts = append(thesePorts, intPort)
portList := strings.Split(port, "-")
if len(portList) == 2 {
start, err := strconv.Atoi(portList[0])
if err != nil {
fmt.Fprint(os.Stderr, "' ' is not a valid port number.\nQUITTING!\n")
os.Exit(1)
}
end, err := strconv.Atoi(portList[1])
if err == nil && start >= 0 && start <= end && end <= 65535 {
for i := start; i < end; i++ {
thesePorts = append(thesePorts, i)
}
}
} else if len(portList) == 1 {
intPort, err := strconv.Atoi(portList[0])
if err == nil && intPort >= 0 && intPort <= 65535 {
thesePorts = append(thesePorts, intPort)
} else {
fmt.Fprint(os.Stderr, "' ' is not a valid port number.\nQUITTING!\n")
os.Exit(1)
}
} else {
fmt.Fprint(os.Stderr, "' ' is not a valid port number.\nQUITTING!\n")
os.Exit(1)
Expand Down Expand Up @@ -149,7 +167,7 @@ func handleOutput() {
continueOutput = []func(g.Output){o.ContinueSmap}
endOutput = []func(){o.EndSmap}
g.SmapFilename = value
} else if value, ok := g.Args["oP"]; ok {
} else if value, ok := g.Args["oP"]; ok {
startOutput = []func(){o.StartPair}
continueOutput = []func(g.Output){o.ContinuePair}
endOutput = []func(){o.EndPair}
Expand Down