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

Add --definition to get to print definition #416

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### Improvements

- Add `--definition` flag to `esc env get` to output definition
[#416](https://github.com/pulumi/esc/pull/416)

### Bug Fixes

### Breaking changes
Expand Down
15 changes: 14 additions & 1 deletion cmd/esc/cli/env_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type envGetCommand struct {

func newEnvGetCmd(env *envCommand) *cobra.Command {
var value string
var defOnly bool
var showSecrets bool

get := &envGetCommand{env: env}
Expand Down Expand Up @@ -67,6 +68,10 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
}
}

if defOnly && value != "" {
return fmt.Errorf("`--value` and `--definition` flags cannot be used together")
}

switch value {
case "":
// OK
Expand Down Expand Up @@ -94,6 +99,11 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
return nil
}

if defOnly {
fmt.Fprint(get.env.esc.stdout, data.Definition)
return nil
}

var markdown bytes.Buffer
if err := envGetTemplate.Execute(&markdown, data); err != nil {
return fmt.Errorf("internal error: rendering: %w", err)
Expand All @@ -117,9 +127,12 @@ func newEnvGetCmd(env *envCommand) *cobra.Command {
},
}

cmd.Flags().BoolVar(
&defOnly, "definition", false,
"Set to print just the definition.")
cmd.Flags().StringVar(
&value, "value", "",
"set to print just the value in the given format. may be 'dotenv', 'json', 'detailed', or 'shell'")
"Set to print just the value in the given format. May be 'dotenv', 'json', 'detailed', or 'shell'")
cmd.Flags().BoolVar(
&showSecrets, "show-secrets", false,
"Show static secrets in plaintext rather than ciphertext")
Expand Down
7 changes: 7 additions & 0 deletions cmd/esc/cli/testdata/env-get-definition-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
run: esc env get default/test --definition --value=json
error: exit status 1
stdout: |
> esc env get default/test --definition --value=json
stderr: |
> esc env get default/test --definition --value=json
Error: `--value` and `--definition` flags cannot be used together
22 changes: 22 additions & 0 deletions cmd/esc/cli/testdata/env-get-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run: |
esc env get default/test --definition
environments:
test-user/default/test:
imports:
- a
values:
# comment
string: esc
files:
FILE: ${string}
stdout: |
> esc env get default/test --definition
imports:
- a
values:
# comment
string: esc
files:
FILE: ${string}
stderr: |
> esc env get default/test --definition
Loading