-
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.
These changes add a command to the CLI that displays the revision history of an environment. This command, `esc env log`, is modeled after `git log`. If a specific version of an environment is given, the history begins at the corresponding revision. The most complicated part of these changes is the pager support. If a system pager is available, the output is sent to that pager. Like `git`, the pager defaults to `less`, but can be changed via the `--pager` flag or the `PAGER` environment variables. If no pager is available, however, we use a built-in pager. This is primarily intended to address platforms where `less` or other pagers are not present (e.g. stock Windows).
- Loading branch information
Showing
17 changed files
with
730 additions
and
27 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
### Improvements | ||
|
||
|
||
|
||
- Add support for getting or opening environments at specific revisions/tags. | ||
[#275](https://github.com/pulumi/esc/pull/275) | ||
|
||
- Add support for listing the revisions to an environment. | ||
[#277](https://github.com/pulumi/esc/pull/277) | ||
|
||
### Bug Fixes | ||
|
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,95 @@ | ||
// Copyright 2023, Pulumi Corporation. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/pulumi/esc/cmd/esc/cli/client" | ||
) | ||
|
||
func newEnvLogCmd(env *envCommand) *cobra.Command { | ||
var pagerFlag string | ||
var utc bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "log [<org-name>/]<environment-name>[:<revision-or-tag>]", | ||
Short: "Show revision logs.", | ||
Long: "Show revision logs\n" + | ||
"\n" + | ||
"This command shows the revision logs for an environment. If a revision\n" + | ||
"or tag is present, the logs will start at the given revision.\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 | ||
} | ||
_ = args | ||
|
||
before := 0 | ||
if revisionOrTag != "" { | ||
rev, err := env.esc.client.GetRevisionNumber(ctx, orgName, envName, revisionOrTag) | ||
if err != nil { | ||
return err | ||
} | ||
before = rev + 1 | ||
} | ||
|
||
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.ListEnvironmentRevisionsOptions{ | ||
Before: &before, | ||
Count: &count, | ||
} | ||
revisions, err := env.esc.client.ListEnvironmentRevisions(ctx, orgName, envName, options) | ||
if err != nil { | ||
return err | ||
} | ||
if len(revisions) == 0 { | ||
break | ||
} | ||
before = revisions[len(revisions)-1].Number | ||
|
||
for _, r := range revisions { | ||
fmt.Fprintf(stdout, "revision %v\n", r.Number) | ||
if r.CreatorLogin == "" { | ||
fmt.Fprintf(stdout, "Author: <unknown>\n") | ||
} else { | ||
fmt.Fprintf(stdout, "Author: %v <%v>\n", r.CreatorName, r.CreatorLogin) | ||
} | ||
|
||
stamp := r.Created | ||
if utc { | ||
stamp = stamp.UTC() | ||
} else { | ||
stamp = stamp.Local() | ||
} | ||
|
||
fmt.Fprintf(stdout, "Date: %v\n", stamp) | ||
fmt.Fprintf(stdout, "\n") | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&pagerFlag, "pager", "", "the command to use to page through the environment's revisions") | ||
cmd.Flags().BoolVar(&utc, "utc", false, "display times in UTC") | ||
|
||
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
Oops, something went wrong.