Skip to content

Commit

Permalink
feat: environments are now listed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrannican committed Nov 21, 2024
1 parent dbedd65 commit 098e390
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
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.

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 098e390

Please sign in to comment.