This commit is contained in:
2024-06-23 09:49:14 -05:00
parent 716b7424c4
commit d96fae1276
13 changed files with 810 additions and 568 deletions

41
cmd/init.go Normal file
View File

@@ -0,0 +1,41 @@
package cmd
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitlab.com/DeveloperDurp/DurpCLI/internal/tui"
)
func initialize() *cobra.Command {
init := &cobra.Command{
Use: "initialize",
Short: "init the rcl cfg.",
Long: "init provision the rcl configuration file.",
Example: "rkl init",
Aliases: []string{"i", "init"},
// used to overwrite/skip the parent commands persistentPreRunE func
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Bind Cobra flags with viper
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
// Environment variables are expected to be ALL CAPS
viper.AutomaticEnv()
viper.SetEnvPrefix("rkl")
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
p := tea.NewProgram(tui.InitialModel())
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
return nil
},
}
return init
}