Unexpected Argument Problem
(go version go1.24.0 linux/amd64, Fedora 41)
Consider the following trivial cutdown example program:
package main
import (
"fmt"
"os"
"github.com/fred1268/go-clap/clap"
)
type TestParams struct {
Binary string `clap:"-b,--binary,help='Binary path'"`
}
func main() {
var results *clap.Results
var err error
_ = results
testParams := TestParams{}
results, err = clap.Parse(os.Args[2:], &testParams)
if err != nil {
fmt.Println("Error parsing test command:", err)
os.Exit(1)
}
fmt.Printf("Test parameters: %+v\n", testParams)
}
Running this produces the following:
% go run t.go test -b mybinary Error parsing test command: field 'Binary': invalid tag (got '-b,--binary,help='Binary path'', expected a single char value)
This is such a trivial program, and error, that I suspect something bizarre is happening.
What am I doing wrong?
Thanks, Jon
I might have figured this out. I got this program from Google AI, and I think there's a bug. The line that says
Binary string clap:"-b,--binary,help='Binary path'"
should be
Binary string clap:"--binary,-b,help='Binary path'"
since the documentation says:
"A clap struct tag has the following structure:
Name Type `clap:"longName[,shortName][,mandatory]"`"
It's too late for me to try this tonight.
I've discovered other issues. The sample program always shows the output (e.g.
{false false} { false}
no matter what I enter.
I'd love to use your package but I'm wondering what its current status is.