canonical / chisel

GNU Affero General Public License v3.0
248 stars 39 forks source link

feat: add find command #99

Closed rebornplusplus closed 3 weeks ago

rebornplusplus commented 9 months ago

This PR adds the find command which can be used to query the chisel releases for available slices.

Usage:
  chisel find [find-OPTIONS] [<query>...]

The find command queries the chisel releases for available slices.

With the --release flag, it queries for slices in a particular branch
of chisel-releases repository[1] or a particular directory. If left
unspecified, it queries with the release info found in /etc/lsb-release.

[1] https://github.com/canonical/chisel-releases

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

Examples

$ chisel find --release ubuntu-20.04 python3 2>/dev/null
Slice                                    Package               Release
libpython3.8-minimal_config              libpython3.8-minimal  ubuntu-20.04
libpython3.8-minimal_libs                libpython3.8-minimal  ubuntu-20.04
libpython3.8-stdlib_all-os               libpython3.8-stdlib   ubuntu-20.04
...
... (trimmed) ...
...
python3.8_core                           python3.8             ubuntu-20.04
python3.8_standard                       python3.8             ubuntu-20.04
python3.8_utils                          python3.8             ubuntu-20.04
$ chisel find libc6_libs 2>/dev/null
Slice       Package  Release
libc6_libs  libc6    ubuntu-22.04
$ chisel find foo bar 2>/dev/null
No matching slices for "foo bar"

Please let me know what you think of the changes. I think I could use some suggestions with naming overall, and particularly the value of maxStrDist constant and logic in matchSlice in /cmd/chisel/cmd_find.go.


rebornplusplus commented 7 months ago

We could say above what the available releases are or point the user to the repository so he can see the branch names. Because the error messages were not introduced as part of this PR, I think it is best to create an issue and address it in the future, do you agree?

I agree. I will create an issue for this after this PR is closed.

letFunny commented 1 month ago

Had a high level discussion with @niemeyer about the search functionality. We agreed that for the first iteration we should try to keep things simple but also make the UX feel natural to the user.

To achieve that we are going to use a string distance of 1 to see if two strings match. Additionally, we are going to take each term passed to the CLI (i.e. chisel find <term1> <term2> ...) and try to match those against package name or slice name but the important thing is that all of the terms have to match in order to add that slice to the results.