Skip to content

fix: add NoArgs on root command and use cmd.Println in version #54

Description

@pageton

Summary

Two small correctness issues:

1. Root command accepts arbitrary arguments silently

main.go:13-16:

rootCmd := &cobra.Command{
    Use:   "gorm",
    Short: "GORM CLI Tool",
}

Running gorm foo bar silently does nothing instead of reporting an error. Add:

Args: cobra.NoArgs,

Or cobra.MaximumNArgs(0) if that reads better.

2. version command uses fmt.Printf instead of cmd.Printf

main.go:31-39:

Run: func(cmd *cobra.Command, args []string) {
    fmt.Printf("gorm-cli version %s\n", ...)
}

Using cmd.Println or cmd.Printf allows tests to capture output via cmd.OutOrStdout(). Also, the command uses Run instead of RunE — inconsistent with the gen command.

RunE: func(cmd *cobra.Command, args []string) error {
    // ...
    cmd.Printf("gorm-cli version %s\n", version)
    return nil
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions