go-gorm / go-gorm/cli

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

Open
#54 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
108
Forks
15
PR merge metrics
No merged PRs in 30d

Description

## Summary

Two small correctness issues:

### 1. Root command accepts arbitrary arguments silently

`main.go:13-16`:
```go
rootCmd := &cobra.Command{
Use: "gorm",
Short: "GORM CLI Tool",
}
```

Running `gorm foo bar` silently does nothing instead of reporting an error. Add:
```go
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`:
```go
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.

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.