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
Changes from 1 commit
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
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
Loading