Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 18 additions & 5 deletions rust/agama-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ use url::Url;
/// Agama's CLI global options
#[derive(Args)]
pub struct GlobalOpts {
#[clap(long, default_value = "http://localhost/api")]
/// URI pointing to Agama's remote API. If not provided, default https://localhost/api is
/// used
pub api: String,
#[clap(long, default_value = "http://localhost")]
/// URI pointing to Agama's remote host. If not provided, default http://localhost is used
pub host: String,

#[clap(long, default_value = "false")]
/// Whether to accept invalid (self-signed, ...) certificates or not
Expand Down Expand Up @@ -248,10 +247,24 @@ async fn build_http_client(
}
}

/// Build the API url from the host.
///
/// * `host`: ip or host name. The protocol is optional, using https if omitted (e.g, "myserver",
/// "http://myserver", "192.168.100.101").
fn api_url(host: String) -> String {
let sanitized_host = host.trim_end_matches('/').to_string();

if sanitized_host.starts_with("http://") || sanitized_host.starts_with("https://") {
format!("{}/api", sanitized_host)
} else {
format!("https://{}/api", sanitized_host)
}
}

pub async fn run_command(cli: Cli) -> Result<(), ServiceError> {
// somehow check whether we need to ask user for self-signed certificate acceptance

let api_url = cli.opts.api.trim_end_matches('/').to_string();
let api_url = api_url(cli.opts.host);

match cli.command {
Commands::Config(subcommand) => {
Expand Down
5 changes: 5 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Apr 16 05:40:39 UTC 2025 - José Iván López González <[email protected]>

- Replace --api option by --host (gh#agama-project/agama#2271).

-------------------------------------------------------------------
Fri Apr 11 06:53:04 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
Loading