Skip to content

Commit

Permalink
Merge pull request #8 from collabora/wip/refi64/url-env
Browse files Browse the repository at this point in the history
Rename URL/token CLI options and read $APTLY_API_URL
  • Loading branch information
sjoerdsimons authored Jun 22, 2023
2 parents 52b4f3d + bf695cf commit 005dd29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
19 changes: 12 additions & 7 deletions aptly-rest/examples/aptlyrestcli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ enum Action {

#[derive(clap::Parser, Debug)]
struct Opts {
#[clap(short, long, default_value = "http://localhost:8080")]
url: Url,
#[clap(
short = 'u',
long,
env = "APTLY_API_URL",
default_value = "http://localhost:8080"
)]
api_url: Url,
/// Authentication token for the API
#[clap(short, long, env = "APTLY_AUTH_TOKEN")]
auth_token: Option<String>,
#[clap(long, env = "APTLY_API_TOKEN")]
api_token: Option<String>,
#[clap(subcommand)]
action: Action,
}
Expand All @@ -171,10 +176,10 @@ struct Opts {
async fn main() -> Result<()> {
let opts = Opts::parse();

let aptly = if let Some(token) = opts.auth_token {
AptlyRest::new_with_token(opts.url, &token)?
let aptly = if let Some(token) = opts.api_token {
AptlyRest::new_with_token(opts.api_url, &token)?
} else {
AptlyRest::new(opts.url)
AptlyRest::new(opts.api_url)
};

match opts.action {
Expand Down
19 changes: 12 additions & 7 deletions aptlyctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ struct Opts {
#[clap(subcommand)]
command: Command,
/// Url for the aptly rest API endpoint
#[clap(short, long, default_value = "http://localhost:8080")]
url: url::Url,
#[clap(
short = 'u',
long,
env = "APTLY_API_URL",
default_value = "http://localhost:8080"
)]
api_url: url::Url,
/// Authentication token for the API
#[clap(short, long, env = "APTLY_AUTH_TOKEN")]
auth_token: Option<String>,
#[clap(long, env = "APTLY_API_TOKEN")]
api_token: Option<String>,
}

#[tokio::main]
Expand All @@ -63,10 +68,10 @@ async fn main() -> Result<ExitCode> {
.init();
color_eyre::install().unwrap();
let opts = Opts::parse();
let aptly = if let Some(token) = opts.auth_token {
AptlyRest::new_with_token(opts.url, &token)?
let aptly = if let Some(token) = opts.api_token {
AptlyRest::new_with_token(opts.api_url, &token)?
} else {
AptlyRest::new(opts.url)
AptlyRest::new(opts.api_url)
};

match opts.command {
Expand Down
19 changes: 12 additions & 7 deletions obs2aptly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ use tracing_subscriber::prelude::*;
#[derive(Parser, Debug)]
struct Opts {
/// Url for the aptly rest api endpoint
#[clap(short, long, default_value = "http://localhost:8080")]
url: url::Url,
#[clap(
short = 'u',
long,
env = "APTLY_API_URL",
default_value = "http://localhost:8080"
)]
api_url: url::Url,
/// Authentication token for the API
#[clap(short, long, env = "APTLY_AUTH_TOKEN")]
auth_token: Option<String>,
#[clap(long, env = "APTLY_API_TOKEN")]
api_token: Option<String>,
/// Repo in aptly
aptly_repo: String,
/// Directory with obs repositories
Expand All @@ -33,10 +38,10 @@ async fn main() -> Result<()> {
.init();
color_eyre::install().unwrap();
let opts = Opts::parse();
let aptly = if let Some(token) = opts.auth_token {
AptlyRest::new_with_token(opts.url, &token)?
let aptly = if let Some(token) = opts.api_token {
AptlyRest::new_with_token(opts.api_url, &token)?
} else {
AptlyRest::new(opts.url)
AptlyRest::new(opts.api_url)
};

let aptly_contents = AptlyContent::new_from_aptly(&aptly, opts.aptly_repo).await?;
Expand Down

0 comments on commit 005dd29

Please sign in to comment.