Skip to content

Commit ed1f694

Browse files
adding validation to natures command (#91)
1 parent e2b5f2b commit ed1f694

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/validateargs.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ func handleHelpFlag(args []string) {
1616
}
1717
}
1818

19+
// ValidateNaturesArgs validates the command line arguments
20+
func ValidateNaturesArgs(args []string) error {
21+
handleHelpFlag(args)
22+
23+
if len(args) > 3 {
24+
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
25+
return fmt.Errorf("%s", errMessage)
26+
}
27+
28+
// Check if there are exactly 3 arguments and the third argument is neither '-h' nor '--help'
29+
// If true, return an error message since only '-h' and '--help' are allowed after 'types'
30+
if len(args) == 3 && (args[2] != "-h" && args[2] != "--help") {
31+
errorTitle := errorColor.Render("Error!")
32+
errorString := "\nThe only currently available options\nafter [natures] command are '-h' or '--help'"
33+
finalErrorMessage := errorTitle + errorString
34+
renderedError := errorBorder.Render(finalErrorMessage)
35+
return fmt.Errorf("%s", renderedError)
36+
}
37+
38+
return nil
39+
}
40+
1941
// ValidatePokemonArgs validates the command line arguments
2042
func ValidatePokemonArgs(args []string) error {
2143
handleHelpFlag(args)

0 commit comments

Comments
 (0)