Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Datree
Commits
df0b5885
Commit
df0b5885
authored
3 years ago
by
myishay
Browse files
Options
Download
Email Patches
Plain Diff
refactor: add helper functions
parent
e21e0cbb
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/test/main.go
+3
-5
cmd/test/main.go
cmd/test/testCommandHelper.go
+7
-0
cmd/test/testCommandHelper.go
pkg/printer/printer.go
+4
-0
pkg/printer/printer.go
with
14 additions
and
5 deletions
+14
-5
cmd/test/main.go
+
3
-
5
View file @
df0b5885
...
...
@@ -15,11 +15,9 @@ import (
"github.com/datreeio/datree/pkg/extractor"
"github.com/datreeio/datree/pkg/localConfig"
"github.com/datreeio/datree/pkg/printer"
"github.com/fatih/color"
"github.com/briandowns/spinner"
"github.com/eiannone/keyboard"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)
...
...
@@ -51,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
)
}
...
...
@@ -262,7 +261,7 @@ 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
.
Fprint
(
color
.
Output
,
color
.
HiCyanString
(
"
\n\n
"
+
createEvaluationResponse
.
PromptMessage
+
" (Y/n)
\n
"
)
)
ctx
.
Printer
.
PrintPromptMessage
(
createEvaluationResponse
.
PromptMessage
)
answer
,
_
,
err
:=
keyboard
.
GetSingleKey
()
if
err
!=
nil
{
...
...
@@ -272,8 +271,7 @@ func test(ctx *TestCommandContext, paths []string, flags TestCommandFlags) error
if
strings
.
ToLower
(
string
(
answer
))
!=
"n"
{
promptLoginUrl
:=
fmt
.
Sprintf
(
"https://app.datree.io/promptLogin?cliId=%s"
,
localConfigContent
.
CliId
)
fmt
.
Printf
(
"Opening %s in your browser.
\n
"
,
promptLoginUrl
)
browser
.
OpenURL
(
promptLoginUrl
)
openBrowser
(
promptLoginUrl
)
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/test/testCommandHelper.go
+
7
-
0
View file @
df0b5885
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
)
}
This diff is collapsed.
Click to expand it.
pkg/printer/printer.go
+
4
-
0
View file @
df0b5885
...
...
@@ -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
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help