canonical / chisel

GNU Affero General Public License v3.0
270 stars 42 forks source link

feat: add info command #101

Closed rebornplusplus closed 1 week ago

rebornplusplus commented 11 months ago

This PR adds a new info command which shows detailed information about package slices.

It accepts a white-space-separated list of strings. The list can be composed of package names, slice names, or a combination of both. The default output format is YAML. When multiple package or slice names are provided, the output is a list of YAML documents, separated by three dashes (“---”).

Slice definitions are shown verbatim according to their definition in the Chisel releases. For example, "globs" are not expanded.

Usage:
  chisel info [info-OPTIONS] [<pkg|slice>...]

[info command options]
      --release=<branch|dir>      Chisel release branch or directory

Expand to see full specification #### Command ``` chisel info ``` #### Usage ``` chisel info [info-OPTIONS] [...] ``` #### Description The info command shows detailed information about package slices in a Chisel release. It accepts a white-space separated list of strings. The list can be composed of package names, slice names, or a combination of both.The package slices are then looked for within the upstream [chisel-releases repository](https://github.com/canonical/chisel-releases). The default output format is YAML. When multiple package/slice names are provided, the output is a list of YAML documents, separated by three dashes (“---”). * If no pkgs/slices are provided, it returns an error. At least one pkg/slicename is required. * If one or more pkgs/slices are provided, it returns a list of their slice definitions. * For slice names, it returns the corresponding package’s SDF, excluding any other package slices which have not been requested. * If multiple slices of the same package are provided, it returns the corresponding package’s SDF just once (i.e. the output can only have one YAML document per package, regardless of how many slices are specified). * If not all pkgs/slices can be found, it returns a list with slice definitions AND an error (to stderr), listing the pkgs/slices that could not be found. * If no packages can be found, it returns an error. * Slice definitions are shown verbatim according to their definition in the Chisel releases. E.g. expressions like globs are not expanded. #### [info-OPTIONS] ``` --release ```` (Optional) The `--release` option filters the search. It behaves similar to the `--release` option to chisel cut. If unspecified, the ubuntu release will be parsed from the host OS. If an ubuntu-release is passed as the argument, the find command only searches for slices in that release branch. If a path to a chisel-release directory is passed as the argument, it parses the directory as a chisel-release and only searches for available slices in that directory.

Examples

$ chisel info openssl_config libssl3_libs 2>/dev/null
package: openssl
archive: ubuntu
slices:
    config:
        contents:
            /etc/ssl/openssl.cnf: {}
            /etc/ssl/private/: {}
            /usr/lib/ssl/certs: {}
            /usr/lib/ssl/openssl.cnf: {}
            /usr/lib/ssl/private: {}
---
package: libssl3
archive: ubuntu
slices:
    libs:
        essential:
            - libc6_libs
        contents:
            /usr/lib/*-linux-*/engines-3/afalg.so: {}
            /usr/lib/*-linux-*/engines-3/loader_attic.so: {}
            /usr/lib/*-linux-*/engines-3/padlock.so: {}
            /usr/lib/*-linux-*/libcrypto.so.*: {}
            /usr/lib/*-linux-*/libssl.so.*: {}
            /usr/lib/*-linux-*/ossl-modules/legacy.so: {}
$ chisel info foo_bar
2023/10/20 11:48:23 Consulting release repository...
2023/10/20 11:48:24 Cached ubuntu-22.04 release is still up-to-date.
2023/10/20 11:48:24 Processing ubuntu-22.04 release...
error: no slice definitions found for: "foo_bar"

Additional information


rebornplusplus commented 11 months ago

ping @cjdcordeiro @woky @niemeyer

letFunny commented 3 months ago

As discussed with @niemeyer, we will change the output so that the YAML matches the style that we write for the slice definitions. Basically, what was raised in https://github.com/letFunny/chisel/issues/9.

rebornplusplus commented 2 months ago

Updated the PR!

I remember we talked about adding the spread tests that were missing, can you add those? I think some kind of smoke test will be enough. For example, one of the tests can be to print some slices and diff it against the sdf. For that we can grep for some lines using yq to check that a path exists, that a essential is there, etc. but something that is not very complex, we have the Go tests for that.

Added a new spread task: tests/info/task.yaml. Additionally, merged your commits from #147 to make the workflow pass.