Skip to content

Commit

Permalink
fix: improve CLI flags and output formatting consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerebrovinny committed Feb 1, 2025
1 parent 6923bfe commit 8ccbbc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cmd/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ var describeStacksCmd = &cobra.Command{

func init() {
describeStacksCmd.DisableFlagParsing = false
describeStacksCmd.PersistentFlags().StringP("stack", "s", "", "Filter by a specific stack")
describeStacksCmd.PersistentFlags().String("json", "", "Comma-separated list of fields to include in JSON output")
describeStacksCmd.PersistentFlags().String("jq", "", "JQ query to transform JSON output (requires --json)")
describeStacksCmd.PersistentFlags().String("template", "", "Go template to format JSON output (requires --json)")
describeStacksCmd.Flags().StringP("stack", "s", "", "Filter by a specific stack")
describeStacksCmd.Flags().String("json", "", "Comma-separated list of fields to include in JSON output")
describeStacksCmd.Flags().String("jq", "", "JQ query to transform JSON output (requires --json)")
describeStacksCmd.Flags().String("template", "", "Go template to format JSON output (requires --json)")
describeCmd.AddCommand(describeStacksCmd)
}
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ func init() {

RootCmd.PersistentFlags().String("logs-level", "Info", "Logs level. Supported log levels are Trace, Debug, Info, Warning, Off. If the log level is set to Off, Atmos will not log any messages")
RootCmd.PersistentFlags().String("logs-file", "/dev/stdout", "The file to write Atmos logs to. Logs can be written to any file or any standard file descriptor, including '/dev/stdout', '/dev/stderr' and '/dev/null'")
RootCmd.PersistentFlags().String("jq", "", "JQ query to transform the output (e.g. '.[] | {name: .name}')")
RootCmd.PersistentFlags().String("template", "", "Go template to format the output (supports Go templates, Sprig functions, and additional helpers)")

// Set custom usage template
err := templates.SetCustomUsageFunc(RootCmd)
Expand Down
11 changes: 8 additions & 3 deletions internal/exec/format_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func FormatStacksOutput(stacksMap map[string]any, jsonFields string, jqQuery str
// Use HighlightCodeWithConfig for YAML output
highlighted, err := u.HighlightCodeWithConfig(string(yamlBytes), atmosConfig, "yaml")
if err != nil {
return string(yamlBytes), nil
return string(yamlBytes) + "\n", nil
}
// For YAML output, preserve the original formatting including newlines
if !strings.HasSuffix(highlighted, "\n\n") {
highlighted += "\n"
}
return highlighted, nil
}
Expand Down Expand Up @@ -75,9 +79,10 @@ func FormatStacksOutput(stacksMap map[string]any, jsonFields string, jqQuery str
// Use HighlightCodeWithConfig for JSON output
highlighted, err := u.HighlightCodeWithConfig(string(jsonBytes), atmosConfig, "json")
if err != nil {
return string(jsonBytes), nil
return string(jsonBytes) + "\n", nil
}
return highlighted, nil
// For JSON output, ensure exactly one newline at the end
return strings.TrimRight(highlighted, "\n") + "\n", nil
}

// filterFields filters the input data to only include specified fields
Expand Down

0 comments on commit 8ccbbc0

Please sign in to comment.