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

feat: add info package subcommand #2960

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

plobsing
Copy link

Provides one of the commands discussed in
https://github.com/orgs/aquaproj/discussions/2641

Output looks like

❯ aqua info package sigstore/cosign
{
  "type": "github_release",
  "repo_owner": "sigstore",
  "repo_name": "cosign",
  "description": "Container Signing",
  "asset": "cosign-{{.OS}}-{{.Arch}}",
  "format": "raw",
  "supported_envs": [
    "darwin",
    "linux",
    "amd64"
  ],
  "checksum": {
    "type": "github_release",
    "asset": "cosign_checksums.txt",
    "algorithm": "sha256"
  }
}

plobsing added 2 commits June 17, 2024 22:11
Provides one of the commands discussed in
https://github.com/orgs/aquaproj/discussions/2641

Output looks like

```
❯ aqua info package sigstore/cosign
{
  "type": "github_release",
  "repo_owner": "sigstore",
  "repo_name": "cosign",
  "description": "Container Signing",
  "asset": "cosign-{{.OS}}-{{.Arch}}",
  "format": "raw",
  "supported_envs": [
    "darwin",
    "linux",
    "amd64"
  ],
  "checksum": {
    "type": "github_release",
    "asset": "cosign_checksums.txt",
    "algorithm": "sha256"
  }
}
```
This commit generated by running the command:

```
(cd pkg/controller; go generate)
```
@suzuki-shunsuke suzuki-shunsuke added the enhancement New feature or request label Jun 18, 2024
@suzuki-shunsuke
Copy link
Member

Thank you for your contribution!

continue
}

if err := encoder.Encode(pkgInfo); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This command accepts multiple package names and outputs them as JSON independently.
I think it's weird because the output can't be parsed as JSON.

{
  // ...
}
{
  // ...
}

I think there are several options.

  1. Accept only one package
  2. Return a list of packages
[
  {
    // ...
  },
  {
    // ...
  }
]

Copy link
Author

@plobsing plobsing Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON is a self-delimiting format. There is no parsing ambiguity in a stream of messages. Tools like jq and libraries such as Go's encoding/json have no issues working with such streams.

For example, with the current implementation, I'm able to aggregate a count of installed packages by owner using jq:

❮ ./aqua info package $(./aqua list --installed | awk '{print $3 "," $1}') | jq -r '.repo_owner' | sort | uniq -c 
   1 golangci
   1 goreleaser
   1 int128
   1 reviewdog
   1 rhysd
   1 sigstore
   2 suzuki-shunsuke

Of the alternatives you suggest, I think I prefer "accept only one package". Its got what seems to me like an unnecessary restriction, but the output is direct and simple to work with. It is a subset of the stream-of-objects output format I proposed: just pass a single name if you want a single message of output. If we do choose to restrict the caller to requesting only one package, what should happen if they pass more than one in argv? What about zero packages in argv?

I'd really prefer to avoid the list format. I find it over-encapsulated, less human-readable, and a bit less convenient to work with. There's not really an upside.

plobsing and others added 3 commits June 18, 2024 07:28
Co-authored-by: Shunsuke Suzuki <[email protected]>
Writing directly to `os.Stdout` ignores any alternate output destinations that may have been injected.

Co-authored-by: Shunsuke Suzuki <[email protected]>
Co-authored-by: Shunsuke Suzuki <[email protected]>
@plobsing plobsing requested a review from suzuki-shunsuke June 18, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants