Skip to content

Commit 2eb6eab

Browse files
erkakpumuk
authored andcommitted
refactor: move root command into internal package
The Cobra command and Execute() function are not part of the public API and should not be imported by downstream consumers. Placing it logic under internal/cmd strengthens encapsulation and allows the CLI wiring to evolve without creating a breaking change surface. Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
1 parent b824bab commit 2eb6eab

2 files changed

Lines changed: 34 additions & 29 deletions

File tree

cmd/lazykiq/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
// Package main provides the lazykiq CLI entry point.
22
package main
33

4-
import "os"
4+
import (
5+
"os"
6+
7+
"github.com/kpumuk/lazykiq/internal/cmd"
8+
)
9+
10+
var (
11+
Version = "dev"
12+
Commit = ""
13+
Date = ""
14+
BuiltBy = ""
15+
)
516

617
func main() {
7-
if err := Execute(); err != nil {
18+
if err := cmd.Execute(Version, Commit, Date, BuiltBy); err != nil {
819
os.Exit(1)
920
}
1021
}
Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package main
1+
// Package cmd provides the entrypoint and CLI command configuration for the
2+
// lazykiq application.
3+
package cmd
24

35
import (
46
"context"
@@ -16,30 +18,6 @@ import (
1618
"github.com/kpumuk/lazykiq/internal/ui"
1719
)
1820

19-
var (
20-
Version = "dev"
21-
Commit = ""
22-
Date = ""
23-
BuiltBy = ""
24-
)
25-
26-
var rootCmd = &cobra.Command{
27-
Use: "lazykiq",
28-
Short: "A terminal UI for Sidekiq.",
29-
Long: "A terminal UI for Sidekiq.",
30-
Args: cobra.NoArgs,
31-
}
32-
33-
func Execute() error {
34-
return fang.Execute(
35-
context.Background(),
36-
rootCmd,
37-
fang.WithVersion(rootCmd.Version),
38-
fang.WithoutCompletions(),
39-
fang.WithoutManpage(),
40-
)
41-
}
42-
4321
func buildVersion(version, commit, date, builtBy string) string {
4422
result := version
4523
if commit != "" {
@@ -59,8 +37,16 @@ func buildVersion(version, commit, date, builtBy string) string {
5937
return result
6038
}
6139

62-
func init() {
63-
rootCmd.Version = buildVersion(Version, Commit, Date, BuiltBy)
40+
// Execute initializes and runs the lazykiq terminal application.
41+
func Execute(version, commit, date, builtBy string) error {
42+
rootCmd := &cobra.Command{
43+
Use: "lazykiq",
44+
Short: "A terminal UI for Sidekiq.",
45+
Long: "A terminal UI for Sidekiq.",
46+
Args: cobra.NoArgs,
47+
}
48+
49+
rootCmd.Version = buildVersion(version, commit, date, builtBy)
6450
rootCmd.SetVersionTemplate(`lazykiq {{printf "version %s\n" .Version}}`)
6551

6652
rootCmd.Flags().String(
@@ -126,4 +112,12 @@ func init() {
126112

127113
return nil
128114
}
115+
116+
return fang.Execute(
117+
context.Background(),
118+
rootCmd,
119+
fang.WithVersion(rootCmd.Version),
120+
fang.WithoutCompletions(),
121+
fang.WithoutManpage(),
122+
)
129123
}

0 commit comments

Comments
 (0)