From 6deb0fb2474a5a250ac2a98e933fb2c79127a7ef Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 8 Sep 2024 18:58:04 +0300 Subject: [PATCH] Remove redundant log Signed-off-by: Michael Sverdlov --- general/ai/cli.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/general/ai/cli.go b/general/ai/cli.go index c8a07f302..3aaa16d50 100644 --- a/general/ai/cli.go +++ b/general/ai/cli.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/jedib0t/go-pretty/v6/table" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli/utils/cliutils" "github.com/jfrog/jfrog-client-go/artifactory/services/utils" @@ -41,7 +42,7 @@ func HowCmd(c *cli.Context) error { if c.NArg() > 0 { return cliutils.WrongNumberOfArgumentsHandler(c) } - log.Output(coreutils.PrintTitle("This AI-based interface converts your natural language inputs into fully functional JFrog CLI commands.\n" + + log.Output(coreutils.PrintLink("This AI-based interface converts your natural language inputs into fully functional JFrog CLI commands.\n" + "NOTE: This is an experimental version and it supports mostly Artifactory and Xray commands.\n")) for { @@ -57,13 +58,16 @@ func HowCmd(c *cli.Context) error { break } } - fmt.Print("\nšŸ¤– Generated command:\n ") + fmt.Print("\nšŸ¤– Generated command:\n") llmAnswer, err := askQuestion(question) if err != nil { return err } - log.Output(coreutils.PrintLink(llmAnswer)) + // Print the generated command within a styled table frame. + // TODO: Use this from jfrog-cli-core + PrintMessageInsideFrame(coreutils.PrintBoldTitle(llmAnswer), " ") + log.Output() if err = sendFeedback(); err != nil { return err } @@ -72,6 +76,21 @@ func HowCmd(c *cli.Context) error { } } +func PrintMessageInsideFrame(message, marginLeft string) { + tableWriter := table.NewWriter() + tableWriter.SetOutputMirror(os.Stdout) + if log.IsStdOutTerminal() { + tableWriter.SetStyle(table.StyleLight) + } + // Set padding left for the whole frame (for example, " "). + tableWriter.Style().Box.Left = marginLeft + tableWriter.Style().Box.Left + tableWriter.Style().Box.TopLeft = marginLeft + tableWriter.Style().Box.TopLeft + tableWriter.Style().Box.BottomLeft = marginLeft + tableWriter.Style().Box.BottomLeft + // Remove emojis from non-supported terminals + tableWriter.AppendRow(table.Row{message}) + tableWriter.Render() +} + type questionBody struct { Question string `json:"question"` } @@ -102,7 +121,7 @@ func getUserFeedback() (bool, error) { } prompt := promptui.Select{ - Label: "Rate this response:", + Label: "ā­ Rate this response:", Items: []string{"šŸ‘ Good response!", "šŸ‘Ž Could be better..."}, Templates: templates, HideHelp: true,