Skip to content

Commit

Permalink
Merge pull request #20 from Tyrannican/list-all-envs
Browse files Browse the repository at this point in the history
List all environments
  • Loading branch information
Tyrannican authored Nov 21, 2024
2 parents dbedd65 + f857719 commit 15f282e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Documenting changes between versions beginning from v0.3.0

## v0.10.3

* `safir env` now lists all existing environments and indicates the currently loaded one

## v0.10.2

* Reduced binary size - no other changes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "safir"
version = "0.10.2"
version = "0.10.3"
edition = "2021"
authors = ["Graham Keenan <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ async fn main() -> Result<()> {
}
Commands::Env => {
let cfg = safir.get_config();
let env = cfg.environment;
println!("Currently loaded environment: '{env}'");
let current_env = cfg.environment;
let envs = safir.environments().await?;

println!("Safir environments:");
for env in envs {
let penv = if env == current_env {
format!("{env} <- Currently loaded")
} else {
env
};
println!("- {penv}");
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/store/db_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl SafirStore for SqliteStore {
Ok(())
}

async fn environments(&self) -> Result<Vec<String>> {
let query = format!("select distinct environment from safir");
let result: Vec<String> = sqlx::query_scalar(&query).fetch_all(&self.pool).await?;
Ok(result)
}

fn get_config(&self) -> SafirConfig {
self.config.clone()
}
Expand Down
4 changes: 4 additions & 0 deletions src/store/file_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ impl SafirStore for KVStore {
Ok(())
}

async fn environments(&self) -> Result<Vec<String>> {
Ok(self.store.keys().map(|e| e.to_string()).collect())
}

fn get_config(&self) -> SafirConfig {
self.config.clone()
}
Expand Down
1 change: 1 addition & 0 deletions src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub trait SafirStore {
async fn remove(&mut self, keys: Vec<String>) -> Result<()>;
async fn clear(&mut self) -> Result<()>;
async fn purge(&mut self) -> Result<()>;
async fn environments(&self) -> Result<Vec<String>>;
fn get_config(&self) -> SafirConfig;
}

Expand Down

0 comments on commit 15f282e

Please sign in to comment.