helper/args: MustNewCheckedArgs for cleaner hardcoded args

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-10-07 13:33:18 +09:00
parent 9647eb6a6b
commit 0fb9e40191
4 changed files with 68 additions and 18 deletions

View File

@@ -53,3 +53,14 @@ func NewCheckedArgs(args []string) (io.WriterTo, error) {
a := argsWt(args)
return a, a.check()
}
// MustNewCheckedArgs returns a checked argument writer for args and panics if check fails.
// Callers must not retain any references to args.
func MustNewCheckedArgs(args []string) io.WriterTo {
a, err := NewCheckedArgs(args)
if err != nil {
panic(err.Error())
}
return a
}