-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): Add a command to list installed plugins #9140
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
plugins { | ||
// Apply precompiled plugins. | ||
id("ort-library-conventions") | ||
} | ||
|
||
dependencies { | ||
api(projects.plugins.commands.commandApi) | ||
|
||
implementation(projects.advisor) | ||
implementation(projects.plugins.api) | ||
implementation(projects.plugins.packageConfigurationProviders.packageConfigurationProviderApi) | ||
implementation(projects.plugins.packageCurationProviders.packageCurationProviderApi) | ||
|
||
implementation(libs.clikt) | ||
implementation(libs.mordant) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (C) 2024 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package org.ossreviewtoolkit.plugins.commands.plugins | ||
|
||
import com.github.ajalt.clikt.parameters.options.default | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.options.split | ||
import com.github.ajalt.mordant.widgets.HorizontalRule | ||
import com.github.ajalt.mordant.widgets.UnorderedList | ||
|
||
import org.ossreviewtoolkit.advisor.AdviceProviderFactory | ||
import org.ossreviewtoolkit.plugins.api.PluginDescriptor | ||
import org.ossreviewtoolkit.plugins.commands.api.OrtCommand | ||
import org.ossreviewtoolkit.plugins.packageconfigurationproviders.api.PackageConfigurationProviderFactory | ||
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCurationProviderFactory | ||
|
||
class PluginsCommand : OrtCommand( | ||
name = "plugins", | ||
help = "Print information about the installed ORT plugins." | ||
) { | ||
private val types by option( | ||
"--types", | ||
help = "A comma-separated list of plugin types to show." | ||
).split(",").default(PluginType.entries.map { it.optionName }) | ||
|
||
override fun run() { | ||
echo(HorizontalRule("Installed ORT Plugins", "=")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I'd omit this rule as it's clear from the command that ORT plugins are listed, and instead "promote" plugin type rules from "-" to "=", and introduce "-" rules for the individual plugins to better separate their options from the next plugin. |
||
echo() | ||
|
||
types.forEach { type -> | ||
PluginType.entries.find { it.optionName == type }?.let { pluginType -> | ||
renderPlugins(pluginType.title, pluginType.descriptors.value) | ||
} | ||
} | ||
} | ||
|
||
private fun renderPlugins(title: String, plugins: List<PluginDescriptor>) { | ||
echo(HorizontalRule(title, "-")) | ||
echo() | ||
|
||
plugins.forEach { plugin -> | ||
echo( | ||
buildString { | ||
append(plugin.displayName) | ||
if (plugin.id != plugin.displayName) append(" (id: ${plugin.id})") | ||
} | ||
) | ||
echo(plugin.description) | ||
echo() | ||
|
||
if (plugin.options.isNotEmpty()) { | ||
echo("Configuration options:") | ||
|
||
echo( | ||
UnorderedList( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using a table instead, with columns for the option name, type, and description? |
||
listEntries = plugin.options.map { option -> | ||
buildString { | ||
append("${option.name}: ${option.type.name}") | ||
option.defaultValue?.let { append(" (Default: $it)") } | ||
if (option.isRequired) append(" (Required)") | ||
appendLine() | ||
append(option.description) | ||
} | ||
}.toTypedArray(), | ||
bulletText = "*" | ||
) | ||
) | ||
|
||
echo() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private enum class PluginType( | ||
val optionName: String, | ||
val title: String, | ||
val descriptors: Lazy<List<PluginDescriptor>> | ||
) { | ||
ADVICE_PROVIDERS( | ||
"advice-providers", | ||
"Advice Providers", | ||
lazy { AdviceProviderFactory.ALL.map { it.value.descriptor } } | ||
), | ||
PACKAGE_CONFIGURATION_PROVIDERS( | ||
"package-configuration-providers", | ||
"Package Configuration Providers", | ||
lazy { PackageConfigurationProviderFactory.ALL.map { it.value.descriptor } } | ||
), | ||
PACKAGE_CURATION_PROVIDERS( | ||
"package-curation-providers", | ||
"Package Curation Providers", | ||
lazy { PackageCurationProviderFactory.ALL.map { it.value.descriptor } } | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ossreviewtoolkit.plugins.commands.plugins.PluginsCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 2024.