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
No related merge requests found
Showing with 26 additions and 4 deletions
+26 -4
...@@ -18,7 +18,6 @@ import ( ...@@ -18,7 +18,6 @@ import (
"github.com/briandowns/spinner" "github.com/briandowns/spinner"
"github.com/eiannone/keyboard" "github.com/eiannone/keyboard"
"github.com/pkg/browser"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
...@@ -50,6 +49,7 @@ type EvaluationPrinter interface { ...@@ -50,6 +49,7 @@ type EvaluationPrinter interface {
PrintWarnings(warnings []printer.Warning) PrintWarnings(warnings []printer.Warning)
PrintSummaryTable(summary printer.Summary) PrintSummaryTable(summary printer.Summary)
PrintMessage(messageText string, messageColor string) PrintMessage(messageText string, messageColor string)
PrintPromptMessage(promptMessage string)
PrintEvaluationSummary(evaluationSummary printer.EvaluationSummary, k8sVersion string) PrintEvaluationSummary(evaluationSummary printer.EvaluationSummary, k8sVersion string)
SetTheme(theme *printer.Theme) SetTheme(theme *printer.Theme)
} }
...@@ -261,11 +261,17 @@ func test(ctx *TestCommandContext, paths []string, flags TestCommandFlags) error ...@@ -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) 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 { if len(createEvaluationResponse.PromptMessage) > 0 {
fmt.Println(createEvaluationResponse.PromptMessage + " (Y/n)") ctx.Printer.PrintPromptMessage(createEvaluationResponse.PromptMessage)
answer, _, _ := keyboard.GetSingleKey() answer, _, err := keyboard.GetSingleKey()
if err != nil {
fmt.Println("Failed to get prompt answer")
return err
}
if strings.ToLower(string(answer)) != "n" { 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) { ...@@ -94,6 +94,10 @@ func (p *PrinterMock) PrintMessage(messageText string, messageColor string) {
p.Called(messageText, messageColor) p.Called(messageText, messageColor)
} }
func (p *PrinterMock) PrintPromptMessage(promptMessage string) {
p.Called(promptMessage)
}
func (p *PrinterMock) SetTheme(theme *printer.Theme) { func (p *PrinterMock) SetTheme(theme *printer.Theme) {
p.Called(theme) p.Called(theme)
} }
...@@ -151,6 +155,7 @@ func TestTestCommand(t *testing.T) { ...@@ -151,6 +155,7 @@ func TestTestCommand(t *testing.T) {
printerMock.On("PrintSummaryTable", mock.Anything) printerMock.On("PrintSummaryTable", mock.Anything)
printerMock.On("PrintEvaluationSummary", mock.Anything, mock.Anything) printerMock.On("PrintEvaluationSummary", mock.Anything, mock.Anything)
printerMock.On("PrintMessage", mock.Anything, mock.Anything) printerMock.On("PrintMessage", mock.Anything, mock.Anything)
printerMock.On("PrintPromptMessage", mock.Anything)
readerMock := &ReaderMock{} readerMock := &ReaderMock{}
readerMock.On("FilterFiles", mock.Anything).Return([]string{"file/path"}, nil) readerMock.On("FilterFiles", mock.Anything).Return([]string{"file/path"}, nil)
......
package test package test
import ( import (
"fmt"
"time" "time"
"github.com/briandowns/spinner" "github.com/briandowns/spinner"
"github.com/datreeio/datree/bl/validation" "github.com/datreeio/datree/bl/validation"
"github.com/datreeio/datree/pkg/extractor" "github.com/datreeio/datree/pkg/extractor"
"github.com/pkg/browser"
) )
func createSpinner(text string, color string) *spinner.Spinner { func createSpinner(text string, color string) *spinner.Spinner {
...@@ -39,3 +41,8 @@ func countConfigurations(filesConfigurations []*extractor.FileConfigurations) in ...@@ -39,3 +41,8 @@ func countConfigurations(filesConfigurations []*extractor.FileConfigurations) in
return totalConfigs 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) { ...@@ -211,6 +211,10 @@ func (p *Printer) PrintMessage(messageText string, messageColor string) {
p.printInColor(messageText, colorPrintFn) 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() { func (p *Printer) printPassedYamlValidation() {
p.printInColor("[V] YAML validation\n", p.Theme.Colors.Green) 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