Documentation
¶
Overview ¶
Package fangcmd wires github.com/strongo/buildinfo into a cobra command tree fronted by charm.land/fang/v2 - the fleet's standard CLI stack.
Left to its own defaults, fang resolves the --version/-v flag from runtime/debug.ReadBuildInfo() and prints "unknown (built from source)" whenever that lookup comes up empty, while a hand-rolled `version` subcommand elsewhere in the same binary reads an entirely different, ldflags-stamped value. That is the exact bug this package closes: Wire feeds fang and the `version` subcommand the same resolved buildinfo.Info, so the two surfaces cannot disagree.
Only import this package when the binary already depends on fang - importing it links fang and its terminal-UI dependencies into the binary. A binary that just wants the --version flag and a `version` subcommand wired onto plain cobra, without paying that cost, should import github.com/strongo/buildinfo/cobracmd instead; that package never imports fang.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wire ¶
Wire adds a `version` subcommand to root (printing info.Long()) and returns the fang.Option(s) that make fang's --version/-v flag print exactly info.Short(). Pass the returned options straight into fang.Execute so both surfaces are driven by the one Info value:
info := buildinfo.Get("mycli")
root := &cobra.Command{Use: "mycli"}
// ... attach the rest of the command tree to root ...
if err := fang.Execute(ctx, root, fangcmd.Wire(root, info)...); err != nil {
os.Exit(1)
}
Wire does not call fang.Execute itself - the caller stays in control of any other fang.Option it wants (themes, signal handling, and so on). It adds the same cobracmd.VersionCommand and uses the same cobracmd.VersionTemplate as cobracmd.WireCobra, so a binary cannot get a different answer from --version and `version` no matter which of the two wiring paths (this one, or plain-cobra WireCobra) it uses.
Types ¶
This section is empty.