-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(args)!: refactor args (breaking!) (#15)
Now all subcommands accept VMID as the first unnamed arg.
- Loading branch information
Showing
7 changed files
with
86 additions
and
85 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
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
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
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,31 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
MaxVmid = 999999999 | ||
MinVmid = 100 | ||
) | ||
|
||
func VmidOutOfRangeError() error { | ||
return fmt.Errorf("please supply a VMID between %d and %d", MinVmid, MaxVmid) | ||
} | ||
func CheckVmidRange(vmid uint64) error { | ||
if vmid < MinVmid || vmid > MaxVmid { | ||
return VmidOutOfRangeError() | ||
} | ||
return nil | ||
} | ||
|
||
func GetVmidArg(args []string) (uint64, error) { | ||
ivmid, err := strconv.Atoi(args[0]) | ||
err = CheckVmidRange(uint64(ivmid)) | ||
if err != nil { | ||
return 0, VmidOutOfRangeError() | ||
} | ||
vmid := uint64(ivmid) | ||
return vmid, nil | ||
} |