Skip to content

Commit

Permalink
Cleaning up console output
Browse files Browse the repository at this point in the history
making banner universal, removing tests that don't need to be there.
  • Loading branch information
daveshanley committed Jul 6, 2022
1 parent dde826c commit 5a41952
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 70 deletions.
2 changes: 2 additions & 0 deletions cmd/generate_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func GetGenerateRulesetCommand() *cobra.Command {
Example: "vacuum generate-ruleset recommended | all <ruleset-output-name>",
RunE: func(cmd *cobra.Command, args []string) error {

PrintBanner()

// check for file args
if len(args) < 1 {
errText := "please supply 'recommended' or 'all' and a file path to output the ruleset."
Expand Down
2 changes: 2 additions & 0 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func GetHTMLReportCommand() *cobra.Command {
Example: "vacuum html-report <my-awesome-spec.yaml> <report.html>",
RunE: func(cmd *cobra.Command, args []string) error {

PrintBanner()

// check for file args
if len(args) == 0 {
errText := "please supply an OpenAPI specification to generate an HTML Report"
Expand Down
10 changes: 2 additions & 8 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/daveshanley/vacuum/motor"
"github.com/daveshanley/vacuum/rulesets"
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
"github.com/spf13/cobra"
"io/ioutil"
"os"
Expand All @@ -34,18 +33,13 @@ func GetLintCommand() *cobra.Command {
rulesetFlag, _ := cmd.Flags().GetString("ruleset")
silent, _ := cmd.Flags().GetBool("silent")

pterm.Println()

if !silent {
_ = pterm.DefaultBigText.WithLetters(
putils.LettersFromStringWithRGB("vacuum", pterm.NewRGB(153, 51, 255))).Render()
pterm.Printf("version: %s\n\n", Version)
pterm.Println()
PrintBanner()
}

// check for file args
if len(args) != 1 {
pterm.Error.Println("please supply OpenAPI specification(s) to lint")
pterm.Error.Println("Please supply OpenAPI specification(s) to lint")
pterm.Println()
return fmt.Errorf("no files supplied")
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
"github.com/spf13/cobra"
"os"
)
Expand All @@ -24,11 +23,7 @@ var (
Long: `vacuum is a very, very fast OpenAPI linter. It will suck all the lint off your spec in milliseconds`,
RunE: func(cmd *cobra.Command, args []string) error {

pterm.Println()

pterm.DefaultBigText.WithLetters(
putils.LettersFromStringWithRGB("vacuum", pterm.NewRGB(153, 51, 255))).Render()
pterm.Printf("version: %s\n\n", Version)
PrintBanner()

pterm.Println("To see something useful, try 'vacuum lint <my-openapi-spec.yaml>'")

Expand Down
9 changes: 9 additions & 0 deletions cmd/shared_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"github.com/daveshanley/vacuum/rulesets"
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
"os"
"time"
)
Expand Down Expand Up @@ -34,3 +35,11 @@ func RenderTime(timeFlag bool, duration time.Duration, fi os.FileInfo) {
pterm.Println()
}
}

func PrintBanner() {
pterm.Println()
_ = pterm.DefaultBigText.WithLetters(
putils.LettersFromStringWithRGB("vacuum", pterm.NewRGB(153, 51, 255))).Render()
pterm.Printf("version: %s | compiled: %s\n\n", Version, Date)
pterm.Println()
}
56 changes: 0 additions & 56 deletions cmd/shared_functions_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions cmd/spectral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func GetSpectralReportCommand() *cobra.Command {
Example: "vacuum report my-awesome-spec.yaml <vacuum-spectral-report.json>",
RunE: func(cmd *cobra.Command, args []string) error {

PrintBanner()

// check for file args
if len(args) == 0 {
errText := "please supply an OpenAPI specification to generate a report"
Expand Down
2 changes: 2 additions & 0 deletions cmd/vacuum_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func GetVacuumReportCommand() *cobra.Command {
Example: "vacuum report <my-awesome-spec.yaml> <report-prefix>",
RunE: func(cmd *cobra.Command, args []string) error {

PrintBanner()

// check for file args
if len(args) == 0 {
errText := "please supply an OpenAPI specification to generate a report"
Expand Down
7 changes: 7 additions & 0 deletions vacuum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/daveshanley/vacuum/cmd"
"time"
)

var version string
Expand All @@ -12,5 +13,11 @@ func main() {
if version == "" {
version = "latest"
}
if commit == "" {
commit = "latest"
}
if date == "" {
date = time.Now().Format("2006-01-02 15:04:05 MST")
}
cmd.Execute(version, commit, date)
}

0 comments on commit 5a41952

Please sign in to comment.