From e765e1dc5bbaf7d22cd4d80a8e9606539c96075e Mon Sep 17 00:00:00 2001 From: Mark Granoff Date: Sun, 22 Mar 2026 15:49:46 -0400 Subject: [PATCH] Add include-package option --- .../SwiftPackageListPlugin.Configuration.swift | 1 + .../SwiftPackageListPlugin.swift | 4 ++++ README.md | 1 + .../SwiftPackageList+OutputOptions.swift | 13 +++++++++++++ 4 files changed, 19 insertions(+) diff --git a/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.Configuration.swift b/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.Configuration.swift index 0a9557a..3564bc5 100644 --- a/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.Configuration.swift +++ b/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.Configuration.swift @@ -21,6 +21,7 @@ extension SwiftPackageListPlugin.Configuration { let outputType: OutputType? let packageOrder: PackageOrder? let requiresLicense: Bool? // swiftlint:disable:this discouraged_optional_boolean + let includePackages: [String]? // swiftlint:disable:this discouraged_optional_collection let ignorePackages: [String]? // swiftlint:disable:this discouraged_optional_collection let customPackagesFilePaths: [String]? // swiftlint:disable:this discouraged_optional_collection } diff --git a/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.swift b/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.swift index cc504f7..1684640 100644 --- a/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.swift +++ b/Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.swift @@ -26,6 +26,10 @@ struct SwiftPackageListPlugin: Plugin { return ["--ignore-package", identity] } ?? [] + let includePackageArguments: [String] = targetConfiguration?.includePackages?.flatMap { identity in + return ["--include-package", identity] + } ?? [] + let customPackagesFilePathArguments: [String] = targetConfiguration?.customPackagesFilePaths?.flatMap { filePath in return ["--custom-packages-file-path", filePath] } ?? [] diff --git a/README.md b/README.md index 123f0df..1d1a7cc 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ In addition to that you can specify the following options: | --package-order \ | The order in which the packages will be listed. (values: source, name-ascending, name-descending, identity-ascending, identity-descending; default: source) | | --requires-license | Will skip the packages without a license-file. | | --ignore-package \ | Will skip a package with the specified identity. (This option may be repeated multiple times) | +| --include-package \ | Will include a package with the specified identity. Use when there are fewer to include than to ignore. (This option may be repeated multiple times) | | --version | Show the version. | | -h, --help | Show help information. | diff --git a/Sources/swift-package-list/SwiftPackageList+OutputOptions.swift b/Sources/swift-package-list/SwiftPackageList+OutputOptions.swift index 9f35d61..3a64e05 100644 --- a/Sources/swift-package-list/SwiftPackageList+OutputOptions.swift +++ b/Sources/swift-package-list/SwiftPackageList+OutputOptions.swift @@ -38,6 +38,16 @@ extension SwiftPackageList { ) ) var ignoredPackageIdentities: [String] = [] + + @Option( + name: .customLong("include-package"), + help: ArgumentHelp( + "Will include a package with the specified identity. Use when there are fewer to include than to ignore. " + + "(This option may be repeated multiple times)", + valueName: "package-identity" + ) + ) + var includedPackageIdentities: [String] = [] } } @@ -61,6 +71,9 @@ extension SwiftPackageList.OutputOptions { extension SwiftPackageList.OutputOptions { func filter(package: Package) -> Bool { if requiresLicense && !package.hasLicense { return false } + if !includedPackageIdentities.isEmpty { + return includedPackageIdentities.contains(package.identity) && !ignoredPackageIdentities.contains(package.identity) + } return !ignoredPackageIdentities.contains(package.identity) }