Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes multiple help issues #959

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
01bcd67
fix help for 'atmos about non-existent'
samtholiya Jan 20, 2025
0470a32
Add invalid flag error handler
samtholiya Jan 21, 2025
3d3ebbc
Ignore update messages in tests
samtholiya Jan 21, 2025
1badbc8
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Jan 21, 2025
284db86
fix test cases
samtholiya Jan 22, 2025
d21e412
Add Markdown usage capability
samtholiya Jan 22, 2025
06353a5
usage markdowns
samtholiya Jan 22, 2025
bb9705b
example hint updated
samtholiya Jan 23, 2025
6317c43
fix tests
samtholiya Jan 23, 2025
5ddbc4d
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Jan 24, 2025
8b74647
Update usage display to markdown glamour
samtholiya Jan 26, 2025
7f9fbb3
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Jan 26, 2025
f0fcf3c
CheckTTYSupport should be in term package
samtholiya Jan 26, 2025
08153a5
atmost about usage and workflow usage
samtholiya Jan 26, 2025
b1cc112
Improved flag usage example
samtholiya Jan 26, 2025
370e982
update workflow error message
samtholiya Jan 26, 2025
045ab19
updated usage
samtholiya Jan 26, 2025
e8fbcaf
Add custom alias to help
samtholiya Jan 28, 2025
3e4563e
Fix asci render logic for error
samtholiya Jan 28, 2025
d65a24e
fix testcases
samtholiya Jan 28, 2025
dbb87ba
Merge branch 'main' of https://github.com/cloudposse/atmos into featu…
samtholiya Jan 28, 2025
9731347
test updated
samtholiya Jan 28, 2025
f801cff
Add --help suggestion to help
samtholiya Jan 28, 2025
2ecd83a
removed examples from md
samtholiya Jan 28, 2025
0087493
fix doubledash suggestion
samtholiya Jan 28, 2025
e9fce14
fix test case
samtholiya Jan 28, 2025
28a2f65
fix no valid subcommands
samtholiya Jan 28, 2025
0d0fb70
updated stack required and component errors to new error render format
samtholiya Jan 28, 2025
a3443fe
fix tests
samtholiya Jan 28, 2025
f1fc80f
fix logger
samtholiya Jan 28, 2025
6c7a191
test fixes
samtholiya Jan 29, 2025
0a0434e
added test for alias subcommand
samtholiya Jan 29, 2025
7fc52ed
Valid subcommands should be on next line
samtholiya Jan 29, 2025
b08659a
Update cmd/workflow.go
samtholiya Jan 30, 2025
f3decf2
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Jan 30, 2025
dc77e1f
added assertion back
samtholiya Jan 30, 2025
3972f82
update error messages for atlantis to markdown
samtholiya Jan 30, 2025
8013318
Merge branch 'main' of https://github.com/cloudposse/atmos into featu…
samtholiya Jan 31, 2025
f6d5a19
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 31, 2025
fbddec2
fix log level error
samtholiya Jan 31, 2025
d1ce9ef
Merge branch 'feature/dev-2953-update-help-and-usageyaml-with-snapsho…
samtholiya Jan 31, 2025
8f0e37c
fix rendering of examples
samtholiya Jan 31, 2025
78fbefc
Add markdown util
samtholiya Feb 2, 2025
a644478
Update pkg/ui/markdown/renderer.go
samtholiya Feb 2, 2025
f90abf5
remove unwanted renderError function
samtholiya Feb 2, 2025
7d6bff2
Merge branch 'feature/dev-2953-update-help-and-usageyaml-with-snapsho…
samtholiya Feb 2, 2025
6aede13
fix tests
samtholiya Feb 2, 2025
f5cba9a
added more error checks
samtholiya Feb 3, 2025
d714ab6
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Feb 3, 2025
68cec78
added description comment
samtholiya Feb 3, 2025
2954d72
Merge branch 'feature/dev-2953-update-help-and-usageyaml-with-snapsho…
samtholiya Feb 3, 2025
3c15f4c
fix ascii render logic and use consistent functions
samtholiya Feb 4, 2025
c0dd9ae
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Feb 4, 2025
2881ff4
fix manual render issue
samtholiya Feb 4, 2025
eeeb4cb
Update cmd/validate_component.go
samtholiya Feb 4, 2025
66116ab
Update internal/exec/atlantis_generate_repo_config.go
samtholiya Feb 4, 2025
f90e81e
Update cmd/docs.go
samtholiya Feb 4, 2025
cd58e7b
Update cmd/cmd_utils.go
samtholiya Feb 4, 2025
5a4068a
updated error message for stack and components missing
samtholiya Feb 4, 2025
faa862f
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Feb 4, 2025
e1fba8a
fix flag help
samtholiya Feb 4, 2025
f1f598f
Merge branch 'feature/dev-2953-update-help-and-usageyaml-with-snapsho…
samtholiya Feb 4, 2025
7b038f1
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Feb 4, 2025
1d95b24
Update pkg/ui/markdown/renderer.go
samtholiya Feb 4, 2025
5506308
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 4, 2025
5faaa7d
fix the snapshots
samtholiya Feb 4, 2025
de042b9
fixed workflow error message format
samtholiya Feb 4, 2025
8738804
workflow UX updated
samtholiya Feb 4, 2025
c66dbfa
Update cmd/cmd_utils.go
samtholiya Feb 5, 2025
652751b
Merge branch 'main' of https://github.com/cloudposse/atmos into featu…
samtholiya Feb 5, 2025
c0ab2d4
small updates
samtholiya Feb 5, 2025
316fc49
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 5, 2025
7dc5ec7
fix tests
samtholiya Feb 5, 2025
d3790d0
make error condition for custom command invalid config usefull
samtholiya Feb 5, 2025
ffc48a3
fix custom command invalid error sentence
samtholiya Feb 5, 2025
e71cb8d
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
aknysh Feb 6, 2025
d4a5a5c
Merge branch 'main' into feature/dev-2953-update-help-and-usageyaml-w…
samtholiya Feb 6, 2025
865db1e
update tests
samtholiya Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions cmd/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ var aboutMarkdown string

// aboutCmd represents the about command
var aboutCmd = &cobra.Command{
Use: "about",
Short: "Learn about Atmos",
Long: `Display information about Atmos, its features, and benefits.`,
Args: cobra.NoArgs,
DisableSuggestions: true,
SilenceUsage: true,
SilenceErrors: true,
Use: "about",
Short: "Learn about Atmos",
Long: `Display information about Atmos, its features, and benefits.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
renderer, err := glamour.NewTermRenderer(
glamour.WithAutoStyle(),
Expand Down
15 changes: 14 additions & 1 deletion cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,17 @@ func handleHelpRequest(cmd *cobra.Command, args []string) {
}
}

// showUsageAndExit we display the markdown usage or fallback to our custom usage
// Markdown usage is not compatible with all outputs. We should therefore have fallback option.
func showUsageAndExit(cmd *cobra.Command, args []string) {

if len(args) == 0 {
showErrorExampleFromMarkdown(cmd.CommandPath(), "")
}
var suggestions []string
unknownCommand := fmt.Sprintf("Error: Unknown command: %q\n\n", cmd.CommandPath())

if len(args) > 0 {
showErrorExampleFromMarkdown(cmd.CommandPath(), args[0])
suggestions = cmd.SuggestionsFor(args[0])
unknownCommand = fmt.Sprintf("Error: Unknown command %q for %q\n\n", args[0], cmd.CommandPath())
}
Expand Down Expand Up @@ -587,6 +592,14 @@ func showUsageAndExit(cmd *cobra.Command, args []string) {
os.Exit(1)
}

func showFlagUsageAndExit(cmd *cobra.Command, err error) error {
unknownCommand := fmt.Sprintf("Error: %v for command %q\n\n", err.Error(), cmd.CommandPath())
u.PrintErrorInColor(unknownCommand)
u.PrintMessage(fmt.Sprintf("Run '%s --help' for usage", cmd.CommandPath()))
os.Exit(1)
return nil
}

// getConfigAndStacksInfo gets the
func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []string) schema.ConfigAndStacksInfo {
// Check Atmos configuration
Expand Down
8 changes: 8 additions & 0 deletions cmd/markdown/atmos_terraform_apply_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Examples:

– Execute a terraform apply
samtholiya marked this conversation as resolved.
Show resolved Hide resolved

$ atmos terraform apply <component-name> -s <stack-name>
osterman marked this conversation as resolved.
Show resolved Hide resolved

For more information, refer to the **docs**:
https://atmos.tools/cli/commands/terraform/usage
8 changes: 8 additions & 0 deletions cmd/markdown/atmos_terraform_plan_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Examples:
samtholiya marked this conversation as resolved.
Show resolved Hide resolved

– Execute a terraform plan

$ atmos terraform plan <component-name> -s <stack-name>
osterman marked this conversation as resolved.
Show resolved Hide resolved

osterman marked this conversation as resolved.
Show resolved Hide resolved
For more information, refer to the **docs**:
https://atmos.tools/cli/commands/terraform/usage
osterman marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions cmd/markdown/atmos_terraform_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Examples:
samtholiya marked this conversation as resolved.
Show resolved Hide resolved

– Execute a terraform

$ atmos terraform [sub-command] <component-name> -s <stack-name>
osterman marked this conversation as resolved.
Show resolved Hide resolved

For more information, refer to the **docs**:
https://atmos.tools/cli/commands/terraform/usage
34 changes: 34 additions & 0 deletions cmd/markdown_help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import _ "embed"

//go:embed markdown/atmos_terraform_usage.md
var terraform string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep that variables similar to the filenames. That way we support more than just usage, since this package is not only for usage


//go:embed markdown/atmos_terraform_plan_usage.md
var terraformPlan string

//go:embed markdown/atmos_terraform_apply_usage.md
var terraformApply string

type ExampleContent struct {
Content string
Suggestion string
}

var examples map[string]ExampleContent = map[string]ExampleContent{
osterman marked this conversation as resolved.
Show resolved Hide resolved
"atmos_terraform": {
Content: terraform,
Suggestion: "https://atmos.tools/cli/commands/terraform/usage",
},
"atmos_terraform_plan": {
Content: terraformPlan,
// TODO: We should update this once we have a page for terraform plan
samtholiya marked this conversation as resolved.
Show resolved Hide resolved
Suggestion: "https://atmos.tools/cli/commands/terraform/usage",
},
"atmos_terraform_apply": {
Content: terraformApply,
// TODO: We should update this once we have a page for terraform plan
Suggestion: "https://atmos.tools/cli/commands/terraform/usage",
},
}
23 changes: 23 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func initCobraConfig() {
styles := boa.DefaultStyles()
b := boa.New(boa.WithStyles(styles))
oldUsageFunc := RootCmd.UsageFunc()
RootCmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error {
return showFlagUsageAndExit(c, err)
})
RootCmd.SetUsageFunc(func(c *cobra.Command) error {
if c.Use == "atmos" {
return b.UsageFunc(c)
Expand Down Expand Up @@ -215,3 +218,23 @@ func initCobraConfig() {
// https://pkg.go.dev/github.com/c-bata/go-prompt
// https://pkg.go.dev/github.com/spf13/cobra
// https://scene-si.org/2017/04/20/managing-configuration-with-viper/

func showErrorExampleFromMarkdown(commandPath string, arg string) {
contentName := strings.ReplaceAll(commandPath, " ", "_")
if exampleContent, ok := examples[contentName]; ok {
details := fmt.Sprintf("The command `%s` is not valid\n\n%s", commandPath, exampleContent.Content)

if len(arg) > 0 {
details = fmt.Sprintf("The command `%s` is not valid\n\n%s", commandPath+" "+arg, exampleContent.Content)
}

if err := renderError(ErrorMessage{
Title: "Invalid Command",
Details: details,
Suggestion: exampleContent.Suggestion,
}); err != nil {
return
}
os.Exit(1)
}
}
7 changes: 6 additions & 1 deletion cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ func renderError(msg ErrorMessage) error {
}

termWriter := termwriter.NewResponsiveWriter(os.Stdout)
screenWidth := termWriter.(*termwriter.TerminalWriter).GetWidth()
var wr *termwriter.TerminalWriter
var ok bool
if wr, ok = termWriter.(*termwriter.TerminalWriter); !ok {
return fmt.Errorf("unsupported output")
}
screenWidth := wr.GetWidth()

if atmosConfig.Settings.Docs.MaxWidth > 0 {
screenWidth = uint(min(atmosConfig.Settings.Docs.MaxWidth, int(screenWidth)))
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/templates/base_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getSection(section HelpTemplateSections) string {
case SubCommandAliases:
return `{{if (isAliasesPresent .Commands)}}

{{HeadingStyle "SubCommand Aliases:"}}
{{HeadingStyle "Subcommand Aliases:"}}

{{formatCommands .Commands "subcommandAliases"}}{{end}}`
case AvailableCommands:
Expand Down
3 changes: 1 addition & 2 deletions internal/tui/templates/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,13 @@ func SetCustomUsageFunc(cmd *cobra.Command) error {
UsageTemplate: GenerateFromBaseTemplate([]HelpTemplateSections{
Usage,
Aliases,
Examples,
AvailableCommands,
NativeCommands,
SubCommandAliases,
Flags,
GlobalFlags,
AdditionalHelpTopics,
DoubleDashHelp,
Examples,
Footer,
}),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/markdown/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *Renderer) RenderError(title, details, suggestion string) (string, error

if suggestion != "" {
if strings.HasPrefix(suggestion, "http") {
samtholiya marked this conversation as resolved.
Show resolved Hide resolved
content += fmt.Sprintf("For more information, refer to the **docs**\n%s\n", suggestion)
content += fmt.Sprintf("For more information, refer to the **docs**:\n%s\n", suggestion)
} else {
content += suggestion
}
Expand Down
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading