Skip to content

Commit

Permalink
(Fix #22) Describe command defaults to active configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrodger committed Jul 17, 2020
1 parent 6dbf8c5 commit 62545b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gctx/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
},

/// List all available configurations
Expand Down
3 changes: 2 additions & 1 deletion gctx/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gctx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 30 additions & 1 deletion gctx/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 62545b8

Please sign in to comment.