@@ -12,10 +12,15 @@ import (
1212
1313var (
1414 outputCmd = & cobra.Command {
15- Use : "output <stack> [component]" ,
15+ Use : "output <stack> [component] [key] " ,
1616 Short : "Show output values from components" ,
17- Run : output ,
18- Args : cobra .RangeArgs (1 , 2 ),
17+ Long : `Show output values from components.
18+
19+ If only stack is provided, shows outputs from all components.
20+ 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.` ,
22+ Run : output ,
23+ Args : cobra .RangeArgs (1 , 3 ),
1924 }
2025)
2126
@@ -24,12 +29,44 @@ func init() {
2429}
2530
2631func output (cmd * cobra.Command , args []string ) {
32+ // Extract the key filter if provided (3rd argument)
33+ var keyFilter string
34+ if len (args ) == 3 {
35+ keyFilter = args [2 ]
36+ // Temporarily reduce args to pass correct stack/component to run()
37+ args = args [:2 ]
38+ }
39+
2740 run (args , false , func (component * schema.Component , executor schema.Executor ) {
2841 out , err := executor .Output (component )
2942 if err != nil {
3043 log .Fatal (err )
3144 }
3245
46+ // If a specific key is requested, only show that
47+ if keyFilter != "" {
48+ if v , ok := out [keyFilter ]; ok {
49+ var rawValue interface {}
50+ if err := json .Unmarshal (v .Value , & rawValue ); err == nil {
51+ switch val := rawValue .(type ) {
52+ case string :
53+ fmt .Printf ("\" %s\" \n " , val )
54+ case []interface {}, map [string ]interface {}:
55+ jsonBytes , _ := json .Marshal (val )
56+ fmt .Printf ("%s\n " , string (jsonBytes ))
57+ default :
58+ fmt .Printf ("%v\n " , val )
59+ }
60+ } else {
61+ fmt .Printf ("\" %s\" \n " , v .String ())
62+ }
63+ } else {
64+ log .Fatal (fmt .Errorf ("output key '%s' not found in component '%s'" , keyFilter , component .Name ))
65+ }
66+ return
67+ }
68+
69+ // Show all outputs
3370 for k , v := range out {
3471 // Try to unmarshal to detect the actual type
3572 var rawValue interface {}
0 commit comments