@@ -15,6 +15,7 @@ import (
1515var shortFindHelp = "Find existing slices"
1616var longFindHelp = `
1717The find command queries the slice definitions for matching slices.
18+ Globs are allowed in the query.
1819
1920By default it fetches the slices for the latest Ubuntu
2021version, unless the --release flag is used.
@@ -67,27 +68,26 @@ func (cmd *cmdFind) Execute(args []string) error {
6768
6869// match reports whether a slice (partially) matches the query.
6970func match (slice * setup.Slice , query string ) bool {
70- const maxStrDist = 1
71- fuzzyMatch := func (str , query string ) bool {
72- return strdist .Distance (str , query , strdist .StandardCost , maxStrDist + 1 ) <= maxStrDist
71+ if ! strings .HasPrefix (query , "*" ) {
72+ query = "*" + query
7373 }
74- return strings .Contains ( slice . String (), query ) ||
75- fuzzyMatch ( slice . Name , query ) ||
76- fuzzyMatch ( slice . Package , query ) ||
77- fuzzyMatch (slice .String (), query )
74+ if ! strings .HasSuffix ( query , "*" ) {
75+ query += "*"
76+ }
77+ return strdist . GlobPath (slice .String (), query )
7878}
7979
80- // findSlices goes through the release searching for any slices that match
81- // the query string. It returns a list of slices that match the query .
82- func findSlices (release * setup.Release , queries []string ) (slices []* setup.Slice , err error ) {
80+ // findSlices returns slices from the provided release that match all of the
81+ // query strings (AND) .
82+ func findSlices (release * setup.Release , query []string ) (slices []* setup.Slice , err error ) {
8383 for _ , pkg := range release .Packages {
8484 for _ , slice := range pkg .Slices {
8585 if slice == nil {
8686 continue
8787 }
8888 allMatch := true
89- for _ , query := range queries {
90- if ! match (slice , query ) {
89+ for _ , term := range query {
90+ if ! match (slice , term ) {
9191 allMatch = false
9292 break
9393 }
0 commit comments