Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya committed Feb 5, 2025
1 parent 652751b commit c0ab2d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func showUsageExample(cmd *cobra.Command, details string) {
suggestion = exampleContent.Suggestion
details += "\n## Usage Examples:\n" + exampleContent.Content
}
u.PrintErrorMarkdownAndExit("Incorrect Usage", fmt.Errorf(details), suggestion)
u.PrintInvalidUsageErrorAndExit(errors.New(details))
}

// Contains checks if a slice of strings contains an exact match for the target string.
Expand Down
2 changes: 1 addition & 1 deletion cmd/list_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var listComponentsCmd = &cobra.Command{

stackFlag, err := flags.GetString("stack")
if err != nil {
u.PrintErrorMarkdownAndExit("Invalid Usage", fmt.Errorf("Error getting the `stack` flag: `%v`", err), "")
u.PrintInvalidUsageErrorAndExit(fmt.Errorf("Error getting the `stack` flag: `%v`", err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/list_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ var listWorkflowsCmd = &cobra.Command{

fileFlag, err := flags.GetString("file")
if err != nil {
u.PrintErrorMarkdownAndExit("Invalid Usage", fmt.Errorf("Error getting the `file` flag: %v", err), "")
u.PrintInvalidUsageErrorAndExit(fmt.Errorf("Error getting the `file` flag: %v", err))
return
}

formatFlag, err := flags.GetString("format")
if err != nil {
u.PrintErrorMarkdownAndExit("Invalid Usage", fmt.Errorf("Error getting the `format` flag: %v", err), "")
u.PrintInvalidUsageErrorAndExit(fmt.Errorf("Error getting the `format` flag: %v", err))
return
}

delimiterFlag, err := flags.GetString("delimiter")
if err != nil {
u.PrintErrorMarkdownAndExit("Invalid Usage", fmt.Errorf("Error getting the `delimiter` flag: %v", err), "")
u.PrintInvalidUsageErrorAndExit(fmt.Errorf("Error getting the `delimiter` flag: %v", err))
return
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/utils/markdown_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/markdown"
"golang.org/x/text/cases"
"golang.org/x/text/language"

l "github.com/charmbracelet/log"
)
Expand All @@ -27,6 +29,7 @@ func PrintErrorMarkdown(title string, err error, suggestion string) {
if title == "" {
title = "Error"
}
title = cases.Title(language.English).String(title)
errorMarkdown, renderErr := render.RenderError(title, err.Error(), suggestion)
if renderErr != nil {
LogError(err)
Expand Down Expand Up @@ -66,6 +69,10 @@ func PrintErrorMarkdownAndExit(title string, err error, suggestion string) {
os.Exit(1)
}

func PrintInvalidUsageErrorAndExit(err error) {
PrintErrorMarkdownAndExit("Invalid Usage", err, "")
}

func PrintfMarkdown(format string, a ...interface{}) {
if render == nil {
_, err := os.Stdout.WriteString(fmt.Sprintf(format, a...))
Expand Down

0 comments on commit c0ab2d4

Please sign in to comment.