mirror of
https://github.com/yarlson/lnk.git
synced 2025-09-01 18:02:34 +02:00
refactor(cmd): improve testability and error handling in CLI commands
This commit is contained in:
26
cmd/root.go
26
cmd/root.go
@@ -12,10 +12,12 @@ var (
|
||||
buildTime = "unknown"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "lnk",
|
||||
Short: "🔗 Dotfiles, linked. No fluff.",
|
||||
Long: `🔗 Lnk - Git-native dotfiles management that doesn't suck.
|
||||
// NewRootCommand creates a new root command (testable)
|
||||
func NewRootCommand() *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "lnk",
|
||||
Short: "🔗 Dotfiles, linked. No fluff.",
|
||||
Long: `🔗 Lnk - Git-native dotfiles management that doesn't suck.
|
||||
|
||||
Move your dotfiles to ~/.config/lnk, symlink them back, and use Git like normal.
|
||||
That's it.
|
||||
@@ -28,17 +30,29 @@ That's it.
|
||||
lnk pull # Get latest changes
|
||||
|
||||
🎯 Simple, fast, and Git-native.`,
|
||||
SilenceUsage: true,
|
||||
SilenceUsage: true,
|
||||
Version: fmt.Sprintf("%s (built %s)", version, buildTime),
|
||||
}
|
||||
|
||||
// Add subcommands
|
||||
rootCmd.AddCommand(newInitCmd())
|
||||
rootCmd.AddCommand(newAddCmd())
|
||||
rootCmd.AddCommand(newRemoveCmd())
|
||||
rootCmd.AddCommand(newStatusCmd())
|
||||
rootCmd.AddCommand(newPushCmd())
|
||||
rootCmd.AddCommand(newPullCmd())
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
// SetVersion sets the version information for the CLI
|
||||
func SetVersion(v, bt string) {
|
||||
version = v
|
||||
buildTime = bt
|
||||
rootCmd.Version = fmt.Sprintf("%s (built %s)", version, buildTime)
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
rootCmd := NewRootCommand()
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
|
Reference in New Issue
Block a user