diff --git a/Cargo.lock b/Cargo.lock index 9ebd84ca4..894df20e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4486,6 +4486,7 @@ dependencies = [ "spfs", "spk-cli-common", "spk-cli-group2", + "spk-config", "spk-schema", "spk-solve", "spk-storage", diff --git a/crates/spk-cli/group4/Cargo.toml b/crates/spk-cli/group4/Cargo.toml index 4eaff3fcd..b4f97647e 100644 --- a/crates/spk-cli/group4/Cargo.toml +++ b/crates/spk-cli/group4/Cargo.toml @@ -27,6 +27,7 @@ itertools = { workspace = true } spfs = { workspace = true } spk-cli-common = { workspace = true } spk-cli-group2 = { workspace = true } +spk-config = { workspace = true } spk-schema = { workspace = true } spk-solve = { workspace = true } spk-storage = { workspace = true } diff --git a/crates/spk-cli/group4/src/cmd_config.rs b/crates/spk-cli/group4/src/cmd_config.rs new file mode 100644 index 000000000..050519151 --- /dev/null +++ b/crates/spk-cli/group4/src/cmd_config.rs @@ -0,0 +1,30 @@ +// Copyright (c) Contributors to the SPK project. +// SPDX-License-Identifier: Apache-2.0 +// https://github.com/spkenv/spk + +use clap::Args; +use miette::{IntoDiagnostic, Result}; +use spk_cli_common::{CommandArgs, Run}; + +/// Output the current configuration of spk +#[derive(Args)] +pub struct Config {} + +#[async_trait::async_trait] +impl Run for Config { + type Output = i32; + + async fn run(&mut self) -> Result { + let config = spk_config::get_config()?; + let out = serde_json::to_string_pretty(&*config).into_diagnostic()?; + println!("{out}"); + Ok(0) + } +} + +impl CommandArgs for Config { + fn get_positional_args(&self) -> Vec { + // There are no important positional args for a config command + vec![] + } +} diff --git a/crates/spk-cli/group4/src/lib.rs b/crates/spk-cli/group4/src/lib.rs index 9ad90b6cc..be6f85d1e 100644 --- a/crates/spk-cli/group4/src/lib.rs +++ b/crates/spk-cli/group4/src/lib.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // https://github.com/spkenv/spk +pub mod cmd_config; pub mod cmd_lint; pub mod cmd_search; pub mod cmd_version; diff --git a/crates/spk/src/cli.rs b/crates/spk/src/cli.rs index 40ef65cd0..d663709f2 100644 --- a/crates/spk/src/cli.rs +++ b/crates/spk/src/cli.rs @@ -15,7 +15,7 @@ use spk_cli_common::{CommandArgs, Error, Run, configure_logging}; use spk_cli_group1::{cmd_bake, cmd_completion, cmd_deprecate, cmd_undeprecate}; use spk_cli_group2::{cmd_ls, cmd_new, cmd_num_variants, cmd_publish, cmd_remove, cmd_stats}; use spk_cli_group3::{cmd_export, cmd_import}; -use spk_cli_group4::{cmd_lint, cmd_search, cmd_version, cmd_view}; +use spk_cli_group4::{cmd_config, cmd_lint, cmd_search, cmd_version, cmd_view}; use spk_cmd_build::cmd_build; use spk_cmd_convert::cmd_convert; use spk_cmd_debug::cmd_debug; @@ -160,6 +160,7 @@ pub enum Command { Bake(cmd_bake::Bake), Build(cmd_build::Build), Completion(cmd_completion::Completion), + Config(cmd_config::Config), Convert(cmd_convert::Convert), Debug(cmd_debug::Debug), Deprecate(cmd_deprecate::DeprecateCmd), @@ -201,6 +202,7 @@ impl Run for Command { Command::Bake(cmd) => cmd.run().await, Command::Build(cmd) => cmd.run().await.map(Into::into), Command::Completion(cmd) => cmd.run(Opt::command()), + Command::Config(cmd) => cmd.run().await, Command::Convert(cmd) => cmd.run().await, Command::Debug(cmd) => cmd.run().await, Command::Deprecate(cmd) => cmd.run().await, @@ -238,6 +240,7 @@ impl CommandArgs for Command { Command::Build(cmd) => cmd.get_positional_args(), Command::Convert(cmd) => cmd.get_positional_args(), Command::Completion(cmd) => cmd.get_positional_args(), + Command::Config(cmd) => cmd.get_positional_args(), Command::Debug(cmd) => cmd.get_positional_args(), Command::Deprecate(cmd) => cmd.get_positional_args(), Command::Du(cmd) => cmd.get_positional_args(), diff --git a/docs/admin/config.md b/docs/admin/config.md index 38f95a016..5789e8ac7 100644 --- a/docs/admin/config.md +++ b/docs/admin/config.md @@ -15,6 +15,11 @@ For spk: `/etc/spk.toml`, which can be overridden by `~/.config/spk/spk.toml` All spfs and spk configuration values can be overridden in the environment. The name of the variable will be the upper-cased name of the config value, separated by underscores, and prefixed with either `SPFS_` or `SPK_`, eg: `SPFS_STORAGE_ROOT`. In cases where the name of the config value contains an underscore, two underscores can be used to disambiguate separators from names, eg: `SPFS_STORAGE__TAG_NAMESPACE`. +### Viewing the Current Configuration + +The effective configuration, after all files and environment variables have been +loaded, can be printed as json with the `spfs config` and `spk config` commands. + ### SPFS Configuration ```toml