jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
872 stars 55 forks source link

The default value of the empty default option is not printed correctly #98

Closed daemtri closed 4 years ago

daemtri commented 5 years ago
package main

import (
    "fmt"
    "os"

    "github.com/jawher/mow.cli"
)

// Global options available to any of the commands
var filename *string

func main() {
    app := cli.App("vault", "Password Keeper")

    // Define our top-level global options
    filename = app.StringOpt("f file", "", "Path to safe")

    // Define our command structure for usage like this:
    app.Command("list", "list accounts", cmdList)
    app.Run(os.Args)
}

// Sample use: vault list OR vault config list
func cmdList(cmd *cli.Cmd) {
    cmd.Action = func() {
        fmt.Printf("list the contents of the safe here")
    }
}

The default value of filename is abc.txt which is specified when I execute the program.

 ~ ./vault -f abc.txt

Usage: vault [OPTIONS] COMMAND [arg...]

Password Keeper

Options:       
  -f, --file   Path to safe (default "abc.txt")

Commands:      
  list         list accounts

Run 'vault COMMAND --help' for more information on a command.
mpldr commented 4 years ago

This bug also happens with environment-variables.