mkideal / cli

CLI - A package for building command line app with go
MIT License
730 stars 43 forks source link

Default value incorrect when printing usage #64

Closed chrjen closed 3 years ago

chrjen commented 3 years ago

Version: 0.2.7

The value Hello, %s! as a default value seems to be treated as a format string when it really should just be printed as is.

Example code:

package main

import (
    "fmt"
    "os"

    "github.com/mkideal/cli"
)

type argT struct {
    Format string `cli:"f,format" dft:"Hello, %s!" usage:"format for greeting"`
}

func main() {
    os.Exit(cli.Run(new(argT), func(ctx *cli.Context) error {
        argv := ctx.Argv().(*argT)
        fmt.Println(argv.Format)
        fmt.Println("==================")
        ctx.WriteUsage()
        return nil
    }))
}

Expected output:

Hello, %s!
==================
Options:

  -f, --format[=Hello, %s!]   format for greeting

Actual output:

Hello, %s!
==================
Options:

  -f, --format[=Hello, %!s(MISSING)!]   format for greeting

It prints out Hello, %!s(MISSING)! instead.