From 2dcbf1343320b1a5745c94e2ab0c94d4ed3a0ab5 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 5 Aug 2023 18:13:31 +0900 Subject: [PATCH 1/2] add greeting command (#28) --- cmd/greeting.go | 21 +++++++++++++++++++++ main.go | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cmd/greeting.go diff --git a/cmd/greeting.go b/cmd/greeting.go new file mode 100644 index 0000000..f755239 --- /dev/null +++ b/cmd/greeting.go @@ -0,0 +1,21 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func NewGreetingCommand() *cobra.Command { + return &cobra.Command{ + Use: "greeting", + Short: "config setting for Chatify", + Long: "config setting for Chatify", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("greeting called") + }, + } +} diff --git a/main.go b/main.go index ebb3c7e..9a8bc73 100644 --- a/main.go +++ b/main.go @@ -80,8 +80,12 @@ func main() { } heyCommand := cmd.NewHeyCommand(context.Background(), client, clientViper.GetString(OpenAIApiKeyName)) + greetingCommand := cmd.NewGreetingCommand() - rootCmd.AddCommand(heyCommand) + rootCmd.AddCommand( + heyCommand, + greetingCommand, + ) if err := rootCmd.Execute(); err != nil { log.Fatal(err) From d3c078acf41930dac2236490f32d8694d8ade990 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 5 Aug 2023 20:36:10 +0900 Subject: [PATCH 2/2] run tea program in the greeting cmd (#28) --- cmd/greeting.go | 14 ++++++++++---- main.go | 4 ---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/greeting.go b/cmd/greeting.go index f755239..812048b 100644 --- a/cmd/greeting.go +++ b/cmd/greeting.go @@ -4,8 +4,8 @@ Copyright © 2023 NAME HERE package cmd import ( - "fmt" - + "github.com/JunNishimura/Chatify/ui" + tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" ) @@ -14,8 +14,14 @@ func NewGreetingCommand() *cobra.Command { Use: "greeting", Short: "config setting for Chatify", Long: "config setting for Chatify", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("greeting called") + RunE: func(cmd *cobra.Command, args []string) error { + p := tea.NewProgram(ui.NewModel(), tea.WithAltScreen()) + + if _, err := p.Run(); err != nil { + return err + } + + return nil }, } } diff --git a/main.go b/main.go index 9a8bc73..dd5e77f 100644 --- a/main.go +++ b/main.go @@ -38,10 +38,6 @@ func main() { // check if token viper is set if !isClientInfoSet() { - if err := askClientInfo(); err != nil { - log.Fatal(err) - } - authorize() } else { ctx := context.Background()