Skip to content

Commit 8a29190

Browse files
authored
Add --definition to get to print definition (#416)
* Add --definition to get to print definition * Tests * Update changelog
1 parent 401ddcb commit 8a29190

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

CHANGELOG_PENDING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### Improvements
22

3+
- Add `--definition` flag to `esc env get` to output definition
4+
[#416](https://github.com/pulumi/esc/pull/416)
5+
36
### Bug Fixes
47

58
### Breaking changes

cmd/esc/cli/env_get.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type envGetCommand struct {
3333

3434
func newEnvGetCmd(env *envCommand) *cobra.Command {
3535
var value string
36+
var defOnly bool
3637
var showSecrets bool
3738

3839
get := &envGetCommand{env: env}
@@ -67,6 +68,10 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
6768
}
6869
}
6970

71+
if defOnly && value != "" {
72+
return fmt.Errorf("`--value` and `--definition` flags cannot be used together")
73+
}
74+
7075
switch value {
7176
case "":
7277
// OK
@@ -94,6 +99,11 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
9499
return nil
95100
}
96101

102+
if defOnly {
103+
fmt.Fprint(get.env.esc.stdout, data.Definition)
104+
return nil
105+
}
106+
97107
var markdown bytes.Buffer
98108
if err := envGetTemplate.Execute(&markdown, data); err != nil {
99109
return fmt.Errorf("internal error: rendering: %w", err)
@@ -117,9 +127,12 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
117127
},
118128
}
119129

130+
cmd.Flags().BoolVar(
131+
&defOnly, "definition", false,
132+
"Set to print just the definition.")
120133
cmd.Flags().StringVar(
121134
&value, "value", "",
122-
"set to print just the value in the given format. may be 'dotenv', 'json', 'detailed', or 'shell'")
135+
"Set to print just the value in the given format. May be 'dotenv', 'json', 'detailed', or 'shell'")
123136
cmd.Flags().BoolVar(
124137
&showSecrets, "show-secrets", false,
125138
"Show static secrets in plaintext rather than ciphertext")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
run: esc env get default/test --definition --value=json
2+
error: exit status 1
3+
stdout: |
4+
> esc env get default/test --definition --value=json
5+
stderr: |
6+
> esc env get default/test --definition --value=json
7+
Error: `--value` and `--definition` flags cannot be used together
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
run: |
2+
esc env get default/test --definition
3+
environments:
4+
test-user/default/test:
5+
imports:
6+
- a
7+
values:
8+
# comment
9+
string: esc
10+
files:
11+
FILE: ${string}
12+
stdout: |
13+
> esc env get default/test --definition
14+
imports:
15+
- a
16+
values:
17+
# comment
18+
string: esc
19+
files:
20+
FILE: ${string}
21+
stderr: |
22+
> esc env get default/test --definition

0 commit comments

Comments
 (0)