diff --git a/gctx/src/arguments.rs b/gctx/src/arguments.rs index f505c4a..837d602 100644 --- a/gctx/src/arguments.rs +++ b/gctx/src/arguments.rs @@ -77,8 +77,8 @@ pub enum SubCommand { /// Describe all the properties in a configuration Describe { - /// Name of the configuration - name: String, + /// Name of the configuration, defaults to current + name: Option, }, /// List all available configurations diff --git a/gctx/src/commands.rs b/gctx/src/commands.rs index 4618999..9e5dcdd 100644 --- a/gctx/src/commands.rs +++ b/gctx/src/commands.rs @@ -109,8 +109,9 @@ pub fn delete(name: &str) -> Result<()> { } /// Describe all the properties in the given configuration -pub fn describe(name: &str) -> Result<()> { +pub fn describe(name: Option<&str>) -> Result<()> { let store = ConfigurationStore::with_default_location().context("Opening configuration store")?; + let name = name.unwrap_or(store.active()); let properties = store.describe(name)?; properties diff --git a/gctx/src/main.rs b/gctx/src/main.rs index a471afb..9c693a5 100644 --- a/gctx/src/main.rs +++ b/gctx/src/main.rs @@ -121,7 +121,7 @@ pub fn run(opts: Opts) -> Result<()> { } SubCommand::Current => commands::current()?, SubCommand::Delete { name } => commands::delete(&name)?, - SubCommand::Describe { name } => commands::describe(&name)?, + SubCommand::Describe { name } => commands::describe(name.as_deref())?, SubCommand::List => commands::list()?, SubCommand::Rename { old_name, diff --git a/gctx/tests/cli.rs b/gctx/tests/cli.rs index 0a55bf6..ebfe772 100644 --- a/gctx/tests/cli.rs +++ b/gctx/tests/cli.rs @@ -425,7 +425,7 @@ fn create_without_force_fails() { } #[test] -fn describe_shows_supported_properties() { +fn describe_with_name_shows_supported_properties() { let (mut cli, tmp) = TempConfigurationStore::new() .unwrap() .with_config_activated("foo") @@ -452,6 +452,35 @@ fn describe_shows_supported_properties() { tmp.close().unwrap(); } +#[test] +fn describe_without_name_shows_active_configuration() { + let (mut cli, tmp) = TempConfigurationStore::new() + .unwrap() + .with_config_activated("foo") + .with_config("bar") + .build() + .unwrap(); + + let contents = [ + "[core]", + "project=my-project", + "account=a.user@example.org", + "[compute]", + "zone=europe-west1-d", + "region=us-east1", + "", + ] + .join("\n"); + + tmp.child("configurations/config_foo").write_str(&contents).unwrap(); + + cli.arg("describe"); + + cli.assert().success().stdout(contents); + + tmp.close().unwrap(); +} + #[test] fn describe_unknown_configuration_fails() { let (mut cli, tmp) = TempConfigurationStore::new()