Unverified Commit e2639003 authored by Yishay Mendelsohn's avatar Yishay Mendelsohn Committed by GitHub
Browse files

Merge pull request #181 from datreeio/fix-prompt-message

fix: prompt message color + error haneling
parents 7ff93a83 ba40be6a
Showing with 26 additions and 4 deletions
+26 -4
......@@ -18,7 +18,6 @@ import (
"github.com/briandowns/spinner"
"github.com/eiannone/keyboard"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)
......@@ -50,6 +49,7 @@ type EvaluationPrinter interface {
PrintWarnings(warnings []printer.Warning)
PrintSummaryTable(summary printer.Summary)
PrintMessage(messageText string, messageColor string)
PrintPromptMessage(promptMessage string)
PrintEvaluationSummary(evaluationSummary printer.EvaluationSummary, k8sVersion string)
SetTheme(theme *printer.Theme)
}
......@@ -261,11 +261,17 @@ func test(ctx *TestCommandContext, paths []string, flags TestCommandFlags) error
err = evaluation.PrintResults(results, invalidYamlFiles, invalidK8sFiles, evaluationSummary, fmt.Sprintf("https://app.datree.io/login?cliId=%s", localConfigContent.CliId), flags.Output, ctx.Printer, createEvaluationResponse.K8sVersion, createEvaluationResponse.PolicyName)
if len(createEvaluationResponse.PromptMessage) > 0 {
fmt.Println(createEvaluationResponse.PromptMessage + " (Y/n)")
answer, _, _ := keyboard.GetSingleKey()
ctx.Printer.PrintPromptMessage(createEvaluationResponse.PromptMessage)
answer, _, err := keyboard.GetSingleKey()
if err != nil {
fmt.Println("Failed to get prompt answer")
return err
}
if strings.ToLower(string(answer)) != "n" {
browser.OpenURL(fmt.Sprintf("https://app.datree.io/promptLogin?cliId=%s", localConfigContent.CliId))
promptLoginUrl := fmt.Sprintf("https://app.datree.io/promptLogin?cliId=%s", localConfigContent.CliId)
openBrowser(promptLoginUrl)
}
}
......
......@@ -94,6 +94,10 @@ func (p *PrinterMock) PrintMessage(messageText string, messageColor string) {
p.Called(messageText, messageColor)
}
func (p *PrinterMock) PrintPromptMessage(promptMessage string) {
p.Called(promptMessage)
}
func (p *PrinterMock) SetTheme(theme *printer.Theme) {
p.Called(theme)
}
......@@ -151,6 +155,7 @@ func TestTestCommand(t *testing.T) {
printerMock.On("PrintSummaryTable", mock.Anything)
printerMock.On("PrintEvaluationSummary", mock.Anything, mock.Anything)
printerMock.On("PrintMessage", mock.Anything, mock.Anything)
printerMock.On("PrintPromptMessage", mock.Anything)
readerMock := &ReaderMock{}
readerMock.On("FilterFiles", mock.Anything).Return([]string{"file/path"}, nil)
......
package test
import (
"fmt"
"time"
"github.com/briandowns/spinner"
"github.com/datreeio/datree/bl/validation"
"github.com/datreeio/datree/pkg/extractor"
"github.com/pkg/browser"
)
func createSpinner(text string, color string) *spinner.Spinner {
......@@ -39,3 +41,8 @@ func countConfigurations(filesConfigurations []*extractor.FileConfigurations) in
return totalConfigs
}
func openBrowser(url string) {
fmt.Printf("Opening %s in your browser.\n", url)
browser.OpenURL(url)
}
......@@ -211,6 +211,10 @@ func (p *Printer) PrintMessage(messageText string, messageColor string) {
p.printInColor(messageText, colorPrintFn)
}
func (p *Printer) PrintPromptMessage(promptMessage string) {
fmt.Fprint(out, color.HiCyanString("\n\n"+promptMessage+" (Y/n)\n"))
}
func (p *Printer) printPassedYamlValidation() {
p.printInColor("[V] YAML validation\n", p.Theme.Colors.Green)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment