Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async-trait = "0.1"
keyring = "3"
semver = "1"
tempfile = "3"
dotenvy = "0.15"

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
18 changes: 10 additions & 8 deletions src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ pub enum AppSubcommands {
},
}

pub async fn handle(cmd: AppCommands, json: bool) -> Result<()> {
pub async fn handle(cmd: AppCommands, json: bool, load_env: bool) -> Result<()> {
match cmd.command {
AppSubcommands::List {
category,
provider,
page,
per_page,
} => list_apps(category, provider, page, per_page, json).await,
} => list_apps(category, provider, page, per_page, json, load_env).await,
AppSubcommands::Run {
app,
input,
input_file,
stream,
output,
} => run_app(app, input, input_file, stream, output, json).await,
AppSubcommands::Show { app } => show_app(app, json).await,
} => run_app(app, input, input_file, stream, output, json, load_env).await,
AppSubcommands::Show { app } => show_app(app, json, load_env).await,
}
}

Expand All @@ -83,9 +83,10 @@ async fn list_apps(
page: usize,
per_page: usize,
json: bool,
load_env: bool,
) -> Result<()> {
let registry = build_registry();
let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;
let catalog = Catalog::new(&registry, &app_config);

let apps = if let Some(provider_id) = &provider_filter {
Expand Down Expand Up @@ -177,6 +178,7 @@ async fn run_app(
stream: bool,
output: Option<PathBuf>,
json: bool,
load_env: bool,
) -> Result<()> {
let app_id = AppId::parse(&app_str)?;

Expand All @@ -201,7 +203,7 @@ async fn run_app(
let registry = build_registry();
let provider = registry.find_provider(&app_id.provider)?;

let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;
let prov_config = app_config
.providers
.get(&app_id.provider)
Expand Down Expand Up @@ -299,11 +301,11 @@ async fn save_images(urls: &[String], base_path: &std::path::Path) -> Result<()>
Ok(())
}

async fn show_app(app_str: String, json: bool) -> Result<()> {
async fn show_app(app_str: String, json: bool, load_env: bool) -> Result<()> {
let app_id = AppId::parse(&app_str)?;

let registry = build_registry();
let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;
let catalog = Catalog::new(&registry, &app_config);

let app = catalog
Expand Down
4 changes: 2 additions & 2 deletions src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::providers::registry::build_registry;
use crate::types::ProviderConnectionStatus;
use anyhow::Result;

pub async fn handle() -> Result<()> {
pub async fn handle(load_env: bool) -> Result<()> {
println!("infs Doctor");
println!("===========");
println!();
Expand All @@ -23,7 +23,7 @@ pub async fn handle() -> Result<()> {

// Check providers
let registry = build_registry();
let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;

println!("Providers:");
for provider in registry.list_providers() {
Expand Down
4 changes: 4 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub struct Cli {
#[arg(long, global = true)]
pub json: bool,

/// Skip loading .env files from current directory and parent directories
#[arg(long, global = true)]
pub no_env: bool,

#[command(subcommand)]
pub command: Commands,
}
Expand Down
14 changes: 7 additions & 7 deletions src/cli/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ pub enum ProviderSubcommands {
},
}

pub async fn handle(cmd: ProviderCommands, json: bool) -> Result<()> {
pub async fn handle(cmd: ProviderCommands, json: bool, load_env: bool) -> Result<()> {
match cmd.command {
ProviderSubcommands::List => list_providers(json).await,
ProviderSubcommands::List => list_providers(json, load_env).await,
ProviderSubcommands::Connect { provider } => connect_provider(&provider).await,
ProviderSubcommands::Disconnect { provider } => disconnect_provider(&provider).await,
ProviderSubcommands::Show { provider } => show_provider(&provider, json).await,
ProviderSubcommands::Show { provider } => show_provider(&provider, json, load_env).await,
}
}

async fn list_providers(json: bool) -> Result<()> {
async fn list_providers(json: bool, load_env: bool) -> Result<()> {
let registry = build_registry();
let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;

let mut rows = Vec::new();
for provider in registry.list_providers() {
Expand Down Expand Up @@ -137,11 +137,11 @@ async fn disconnect_provider(provider_id: &str) -> Result<()> {
Ok(())
}

async fn show_provider(provider_id: &str, json: bool) -> Result<()> {
async fn show_provider(provider_id: &str, json: bool, load_env: bool) -> Result<()> {
let registry = build_registry();
let provider = registry.find_provider(provider_id)?;
let d = provider.descriptor();
let app_config = config::load_config()?;
let app_config = config::load_config_with_env(load_env)?;

let prov_config = app_config.providers.get(&d.id);
let status = if prov_config.is_some_and(|c| c.connected && c.get_api_key().is_some()) {
Expand Down
Loading