Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions site/src/content/docs/ref/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ If you have any `default` components in a package definition you can also exclud
$ zarf package deploy ./path/to/package.tar.zst --components=optional-component-1,-default-component-1
```

For components that match multiple selectors, the last selector takes priority.

```bash
# exclude all components except component-1
$ zarf package deploy ./path/to/package.tar.zst --components=-*,component-1
```

:::

## Extensions (Removed)
Expand Down
35 changes: 16 additions & 19 deletions src/pkg/packager/filters/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,30 @@ const (
)

func includedOrExcluded(componentName string, requestedComponentNames []string) (selectState, string, error) {
// Check if the component has a leading dash indicating it should be excluded - this is done first so that exclusions precede inclusions
for _, requestedComponent := range requestedComponentNames {
if strings.HasPrefix(requestedComponent, "-") {
// If the component glob matches one of the requested components, then return true
// This supports globbing with "path" in order to have the same behavior across OSes (if we ever allow namespaced components with /)
matched, err := path.Match(strings.TrimPrefix(requestedComponent, "-"), componentName)
if err != nil {
return unknown, "", err
}
if matched {
return excluded, requestedComponent, nil
}
}
}
// Check if the component matches a glob pattern and should be included
// In unmatched cases we don't know if we should include or exclude yet
var match string
var matchType = unknown

// Check every component request, so last match get's priority
// Order is assumed to match user input
for _, requestedComponent := range requestedComponentNames {
// If the component glob matches one of the requested components, then return true
// This supports globbing with "path" in order to have the same behavior across OSes (if we ever allow namespaced components with /)
matched, err := path.Match(requestedComponent, componentName)
matched, err := path.Match(strings.TrimPrefix(requestedComponent, "-"), componentName)
if err != nil {
return unknown, "", err
}

if matched {
return included, requestedComponent, nil
match = requestedComponent
// Exclusions are requests with the leading "-"
if strings.HasPrefix(requestedComponent, "-") {
matchType = excluded
} else {
matchType = included
}
}
}

// All other cases we don't know if we should include or exclude yet
return unknown, "", nil
return matchType, match, nil
}
5 changes: 2 additions & 3 deletions src/pkg/packager/filters/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func Test_includedOrExcluded(t *testing.T) {
name: "Test when component is excluded and included",
componentName: "example",
requestedComponentNames: []string{"-example", "example"},
wantState: excluded,
wantRequestedComponent: "-example",
wantState: included,
wantRequestedComponent: "example",
},
// interesting case, excluded wins
{
name: "Test when component is included and excluded",
componentName: "example",
Expand Down