This commit adds the `goheader` rule to `golangci-lint` to enforce that
all our Go source code includes appropriate licence headers, fixing up
files that currently fail that check.
---------
Co-authored-by: Will Jones <will@sacharissa.co.uk>
The helper method exported here uses an internal terminal,
"SimpleTerminal", which ignores terminal control sequences and writes
its output directly to a buffer. The wrapper retains a similar API as
`ShowProgressEvents` to enable streaming events, though performance may
be suboptimal as a subset of events must be buffered as rows to render
the tree.
For cleaner output in this mode, the `CarriageReturn` operation is added
to the internal terminal interface to conditionally render it.
Ordinarily this is used along with cursor movement to render the tree in
place, and is not needed for this mode. This removes spurious `\r`
(rendered as "^M") characters from the diff for the plain rendering
tests.
The latest version of golangci-lint (1.60.3) flags a bunch of new issues
in our code base. This PR addresses part of them ahead of the upgrade.
* A dynamic string passed to printf style functions as first argument,
this can lead to bad `%` interpolations. The fix is typically to use
`"%s"` as first argument and pass the dynamic string as 2nd argument.
* Using `os.ModePerm` in tests instead of more restricted file
permissions. The fix is to use 0o600 for files, or 0o700 for
directories.
* Int conversion overflows. The fix has to be done case by case,
checking that no overflow can occur.
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
Updates the terminal support for the tree view in Pulumi CLI
This adds the vim shortcuts :
`j` – down
`k` – up
`Ctrl+F` – page down
`Ctrl+B` – page up
`g` – home
`G` – end
Also adds Home and End key support
Fixes # (issue)
## Checklist
- [X] I have run `make tidy` to update any new dependencies
- [X] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [X] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [X] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
Co-authored-by: Paul Roberts <proberts@pulumi.com>
Turn on the golangci-lint exhaustive linter. This is the first step
towards catching more missing cases during development rather than
in tests, or in production.
This might be best reviewed commit-by-commit, as the first commit turns
on the linter with the `default-signifies-exhaustive: true` option set,
which requires a lot less changes in the current codebase.
I think it's probably worth doing the second commit as well, as that
will get us the real benefits, even though we end up with a little bit
more churn. However it means all the `switch` statements are covered,
which isn't the case after the first commit, since we do have a lot of
`default` statements that just call `assert.Fail`.
Fixes#14601
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
Add support for using Ctrl+O to open the current update in the browser
for backends that support permalinks.
The keybinding is advertised in the interactive display as part of the
message that displays the permalink:
```
Previewing update (dev)
View in Browser (Ctrl+O): https://<some-url>
Type Name Plan
+ pulumi:pulumi:Stack vpc-dev create
+ ├─ aws:ec2:Vpc vpc create
+ ├─ aws:ec2:SecurityGroup secgroup create
+ ├─ aws:ec2:SecurityGroupRule rule-2 create
+ ├─ aws:ec2:SecurityGroupRule rule-0 create
+ ├─ aws:ec2:SecurityGroupRule rule-1 create
+ └─ aws:ec2:SecurityGroupRule rule-3 create
```
In order to maintain backwards compatibility with older versions of the
Automation API, the message is not changed for non-interactive
scenarios.
- If the display is scrolled to the bottom, autoscroll it as new lines are
added to the output.
- Add support for scrolling the interactive display using page-down and
page-up. These keys scroll the display N lines at a time, where N is the
height of the terminal.
Instead of clearing the contents of the display with each frame,
overwrite its contents by clearing to the end of each line prior to a
newline. This should eliminate flickering in the interactive display.
This also eliminates a couple of off-by-one errors that were hampering
usability.
Replace direct interaction with the terminal with an abstraction. This
abstraction is tightly constrained to the capabilities needed for the
CLI's display. Using this abstraction allows for straightforward testing
of the interactive renderers.