ff icon indicating copy to clipboard operation
ff copied to clipboard

flags with multi-line help are printed incorrectly

Open thehowl opened this issue 11 months ago • 0 comments

Consider the following:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/peterbourgon/ff/v4"
	"github.com/peterbourgon/ff/v4/ffhelp"
)

const dsnDoc = `data source name to use for connecting to the database.
	sqlite and postgres are the supported databases and URI schemas. syntax:
	- sqlite://<FILE>; <FILE> may be an absolute or relative path.
	- postgres://[<USER>[:<PASS>]@][<HOST>][/<DB_NAME>]
		a postgres connection string - see: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
		environment variables are also recognized - see: https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#ParseConfig`

func main() {
	// Parse configuration
	var (
		globalFS = ff.NewFlagSet("gh-sql")
		dsn      = globalFS.StringLong("dsn", "sqlite://database.sqlite", dsnDoc)
		_        = globalFS.StringLong("config", "", "config file (optional)")
	)
	_ = dsn
	cmd := &ff.Command{
		Name:      "gh-sql",
		Usage:     "gh-sql SUBCOMMAND ...",
		ShortHelp: "a tool to locally store information about GitHub repository, query them and serve them.",
		Flags:     globalFS,
		Exec:      func(context.Context, []string) error { return ff.ErrHelp },
	}

	err := cmd.Parse(os.Args[1:],
		ff.WithEnvVarPrefix("GHSQL_"),
		ff.WithConfigFileFlag("config"),
		ff.WithConfigFileParser(ff.PlainParser),
	)
	if err != nil {
		fmt.Fprintln(os.Stderr, ffhelp.Command(cmd))
		fmt.Println(err)
	}
}

In the latest release, this renders the output of --help badly formatted:

$ go run ./poc.go --help
COMMAND
  gh-sql -- a tool to locally store information about GitHub repository, query them and serve them.

USAGE
  gh-sql SUBCOMMAND ...

FLAGS
  --dsn STRING      data source name to use for connecting to the database.
                    sqlite and postgres are the supported databases and URI schemas. syntax:

gh-sql: parse args: flag: help requested

thehowl avatar Jan 27 '25 12:01 thehowl