Fix version command and add default action with banner

- Version command now uses mfer.Version constant instead of empty build flags
- Running just 'mfer' shows banner + help
- Unknown commands still return error with exit code 1
This commit is contained in:
Jeffrey Paul 2025-12-17 15:28:14 -08:00
parent 6edc798de0
commit 9dbdcbde91
2 changed files with 12 additions and 2 deletions

View File

@ -42,7 +42,7 @@ func TestVersionCommand(t *testing.T) {
assert.Equal(t, 0, exitCode)
stdout := opts.Stdout.(*bytes.Buffer).String()
assert.Contains(t, stdout, "1.0.0")
assert.Contains(t, stdout, mfer.Version)
assert.Contains(t, stdout, "abc123")
}

View File

@ -50,7 +50,10 @@ func (mfa *CLIApp) printBanner() {
// VersionString returns the version and git revision formatted for display.
func (mfa *CLIApp) VersionString() string {
return fmt.Sprintf("%s (%s)", mfa.version, mfa.gitrev)
if mfa.gitrev != "" {
return fmt.Sprintf("%s (%s)", mfer.Version, mfa.gitrev)
}
return mfer.Version
}
func (mfa *CLIApp) setVerbosity(quiet bool, v int) {
@ -85,6 +88,13 @@ func (mfa *CLIApp) run(args []string) {
EnableBashCompletion: true,
Writer: mfa.Stdout,
ErrWriter: mfa.Stderr,
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return fmt.Errorf("unknown command %q", c.Args().First())
}
mfa.printBanner()
return cli.ShowAppHelp(c)
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",