Skip to content

Commit 2524864

Browse files
committed
chore: release v0.7.3
1 parent 48b4069 commit 2524864

4 files changed

Lines changed: 106 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.7.3] - 2025-11-02
11+
12+
### Added
13+
- **`comet output --json` flag** - Output values in JSON format for easier processing with tools like jq
14+
- Works with all output modes (all components, single component, or specific key)
15+
- Outputs pretty-printed JSON with proper indentation
16+
- Example: `comet output production gke --json | jq -r '.cluster_endpoint'`
17+
18+
### Changed
19+
- **`comet output` with key filter now outputs plain values** - String values no longer wrapped in quotes for easier scripting
20+
- Before: `"https://example.com"`
21+
- After: `https://example.com`
22+
- Makes it easier to use in shell scripts: `ENDPOINT=$(comet output prod gke cluster_endpoint)`
23+
1024
## [0.7.2] - 2025-11-01
1125

1226
### Added

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.7.2
1+
VERSION=v0.7.3
22

33
.PHONY: build
44
build:

cmd/output.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@ import (
1111
)
1212

1313
var (
14+
outputJSON bool
15+
1416
outputCmd = &cobra.Command{
1517
Use: "output <stack> [component] [key]",
1618
Short: "Show output values from components",
1719
Long: `Show output values from components.
1820
1921
If only stack is provided, shows outputs from all components.
2022
If stack and component are provided, shows outputs from that component.
21-
If stack, component, and key are provided, shows only that specific output value.`,
23+
If stack, component, and key are provided, shows only that specific output value.
24+
25+
The --json flag formats the output as JSON, which can be piped to tools like jq.`,
2226
Run: output,
2327
Args: cobra.RangeArgs(1, 3),
2428
}
2529
)
2630

2731
func init() {
32+
outputCmd.Flags().BoolVar(&outputJSON, "json", false, "Output in JSON format")
2833
rootCmd.AddCommand(outputCmd)
2934
}
3035

@@ -43,30 +48,66 @@ func output(cmd *cobra.Command, args []string) {
4348
log.Fatal(err)
4449
}
4550

51+
// JSON output mode
52+
if outputJSON {
53+
// If a specific key is requested, output only that value as JSON
54+
if keyFilter != "" {
55+
if v, ok := out[keyFilter]; ok {
56+
var rawValue interface{}
57+
if err := json.Unmarshal(v.Value, &rawValue); err == nil {
58+
jsonBytes, _ := json.MarshalIndent(rawValue, "", " ")
59+
fmt.Println(string(jsonBytes))
60+
} else {
61+
// Fallback to string
62+
jsonBytes, _ := json.MarshalIndent(v.String(), "", " ")
63+
fmt.Println(string(jsonBytes))
64+
}
65+
} else {
66+
log.Fatal(fmt.Errorf("output key '%s' not found in component '%s'", keyFilter, component.Name))
67+
}
68+
return
69+
}
70+
71+
// Output all values as JSON object
72+
result := make(map[string]interface{})
73+
for k, v := range out {
74+
var rawValue interface{}
75+
if err := json.Unmarshal(v.Value, &rawValue); err == nil {
76+
result[k] = rawValue
77+
} else {
78+
result[k] = v.String()
79+
}
80+
}
81+
jsonBytes, _ := json.MarshalIndent(result, "", " ")
82+
fmt.Println(string(jsonBytes))
83+
return
84+
}
85+
86+
// Plain text output mode
4687
// If a specific key is requested, only show that
4788
if keyFilter != "" {
4889
if v, ok := out[keyFilter]; ok {
4990
var rawValue interface{}
5091
if err := json.Unmarshal(v.Value, &rawValue); err == nil {
5192
switch val := rawValue.(type) {
5293
case string:
53-
fmt.Printf("\"%s\"\n", val)
94+
fmt.Println(val)
5495
case []interface{}, map[string]interface{}:
5596
jsonBytes, _ := json.Marshal(val)
56-
fmt.Printf("%s\n", string(jsonBytes))
97+
fmt.Println(string(jsonBytes))
5798
default:
5899
fmt.Printf("%v\n", val)
59100
}
60101
} else {
61-
fmt.Printf("\"%s\"\n", v.String())
102+
fmt.Println(v.String())
62103
}
63104
} else {
64105
log.Fatal(fmt.Errorf("output key '%s' not found in component '%s'", keyFilter, component.Name))
65106
}
66107
return
67108
}
68109

69-
// Show all outputs
110+
// Show all outputs in human-readable format
70111
for k, v := range out {
71112
// Try to unmarshal to detect the actual type
72113
var rawValue interface{}

website/docs/guides/cli-reference.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ comet output production gke cluster_endpoint
256256

257257
**Example Output:**
258258
```
259-
"https://35.123.45.67"
259+
https://35.123.45.67
260260
```
261261

262262
This is useful for scripting and automation:
263263
```bash
264264
ENDPOINT=$(comet output production gke cluster_endpoint)
265+
# ENDPOINT now contains: https://35.123.45.67 (no quotes)
265266
```
266267

267268
### Show All Outputs from All Components
@@ -275,6 +276,49 @@ comet output <stack>
275276
comet output production
276277
```
277278

279+
### JSON Output Format
280+
281+
Use the `--json` flag to output in JSON format, which can be piped to tools like `jq`:
282+
283+
```bash
284+
comet output <stack> <component> --json
285+
```
286+
287+
**Example:**
288+
```bash
289+
comet output production gke --json
290+
```
291+
292+
**Example Output:**
293+
```json
294+
{
295+
"cluster_endpoint": "https://35.123.45.67",
296+
"cluster_ca_certificate": "LS0tLS1CRU...",
297+
"cluster_name": "prod-gke-cluster"
298+
}
299+
```
300+
301+
You can also get a specific key in JSON format:
302+
```bash
303+
comet output production gke cluster_endpoint --json
304+
```
305+
306+
**Example Output:**
307+
```json
308+
"https://35.123.45.67"
309+
```
310+
311+
**Piping to jq:**
312+
```bash
313+
# Extract a specific field
314+
comet output production gke --json | jq -r '.cluster_endpoint'
315+
316+
# Get all cluster names from all components
317+
comet output production --json | jq -r '.cluster_name'
318+
```
319+
320+
**Note:** When using the `--json` flag, sensitive values are displayed in plain text.
321+
278322
## comet destroy
279323

280324
Destroy previously-created infrastructure.

0 commit comments

Comments
 (0)