-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: add commands for managing version tags (#283)
These changes add commands for managing version tags: - `esc env version tag` creates, describes, or updates a version tag - `esc env version rm` deletes a version tag - `esc env version ls` lists version tags
- Loading branch information
Showing
10 changed files
with
574 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023, Pulumi Corporation. | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newEnvVersionCmd(env *envCommand) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Manage version tags", | ||
Long: "Manage version tags\n" + | ||
"\n" + | ||
"This command creates, inspects, updates, deletes, and lists version tags.\n" + | ||
"A version tag is a name that refers to a specific revision of an environment.\n" + | ||
"Once created, version tags can be updated to refer to new reversions\n" + | ||
"of an environment. Version tags can be used to refer to a particular logical\n" + | ||
"version of an environment rather than a specific revision.\n", | ||
SilenceUsage: true, | ||
} | ||
|
||
cmd.AddCommand(newEnvVersionTagCmd(env)) | ||
cmd.AddCommand(newEnvVersionRmCmd(env)) | ||
cmd.AddCommand(newEnvVersionLsCmd(env)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2023, Pulumi Corporation. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/pulumi/esc/cmd/esc/cli/client" | ||
"github.com/pulumi/esc/cmd/esc/cli/style" | ||
) | ||
|
||
func newEnvVersionLsCmd(env *envCommand) *cobra.Command { | ||
var pagerFlag string | ||
var utc bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "ls [<org-name>/]<environment-name>", | ||
Short: "List version tags.", | ||
Long: "List version tags\n" + | ||
"\n" + | ||
"This command lists the version tags for an environment.\n", | ||
SilenceUsage: true, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
|
||
if err := env.esc.getCachedClient(ctx); err != nil { | ||
return err | ||
} | ||
|
||
orgName, envName, revisionOrTag, args, err := env.getEnvName(args) | ||
if err != nil { | ||
return err | ||
} | ||
if revisionOrTag != "" { | ||
return fmt.Errorf("the ls command does not accept revisions or tags") | ||
} | ||
_ = args | ||
|
||
st := style.NewStylist(style.Profile(env.esc.stdout)) | ||
|
||
after := "" | ||
return env.esc.pager.Run(pagerFlag, env.esc.stdout, env.esc.stderr, func(ctx context.Context, stdout io.Writer) error { | ||
count := 500 | ||
for { | ||
options := client.ListEnvironmentRevisionTagsOptions{ | ||
After: after, | ||
Count: &count, | ||
} | ||
tags, err := env.esc.client.ListEnvironmentRevisionTags(ctx, orgName, envName, options) | ||
if err != nil { | ||
return err | ||
} | ||
if len(tags) == 0 { | ||
break | ||
} | ||
after = tags[len(tags)-1].Name | ||
|
||
for _, t := range tags { | ||
printRevisionTag(stdout, st, t, utc) | ||
fmt.Fprintf(stdout, "\n") | ||
} | ||
} | ||
return nil | ||
}) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&pagerFlag, "pager", "", "the command to use to page through the environment's version tags") | ||
cmd.Flags().BoolVar(&utc, "utc", false, "display times in UTC") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.