Skip to content
Draft
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
13 changes: 13 additions & 0 deletions 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 apt2aptly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ sync2aptly = { path = "../sync2aptly" }
tokio = { version = "1.45.1", features = ["full"] }
tracing = "0.1.41"
tracing-error = "0.2.1"
tracing-subscriber = "0.3.20"
tracing-subscriber = { version = "0.3.20", features = ["json"] }
url = "2.5.4"
37 changes: 31 additions & 6 deletions apt2aptly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use aptly_rest::{
api::{publish, repos, snapshots::DeleteOptions},
AptlyRest, AptlyRestError,
};
use clap::{builder::ArgPredicate, Parser};
use clap::{builder::ArgPredicate, Parser, ValueEnum};
use color_eyre::{
eyre::{bail, ensure, Context},
Result,
Expand All @@ -23,6 +23,13 @@ use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use url::Url;

#[derive(ValueEnum, Clone, Copy, Debug, Default)]
enum LogFormat {
#[default]
Pretty,
Json,
}

#[derive(Parser, Debug)]
struct Opts {
/// Url for the aptly rest api endpoint
Expand Down Expand Up @@ -86,6 +93,9 @@ struct Opts {
/// Only show changes, don't apply them
#[clap(short = 'n', long, default_value_t = false)]
dry_run: bool,
/// Log output format
#[clap(long, value_enum, default_value_t = LogFormat::Pretty)]
log_format: LogFormat,
}

const TEMPLATE_VAR_COMPONENT: &str = "component";
Expand Down Expand Up @@ -472,14 +482,29 @@ async fn sync_dist(
Ok(())
}

fn init_tracing(format: LogFormat) {
match format {
LogFormat::Pretty => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init(),
LogFormat::Json => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(
tracing_subscriber::fmt::layer()
.json()
.with_filter(LevelFilter::INFO),
)
.init(),
}
}

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init();
color_eyre::install().unwrap();
let opts = Opts::parse();
init_tracing(opts.log_format);
color_eyre::install()?;

let aptly = if let Some(token) = &opts.api_token {
AptlyRest::new_with_token(opts.api_url.clone(), token)?
} else {
Expand Down
2 changes: 1 addition & 1 deletion aptly-latest-snapshots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thiserror = "2.0.12"
tokio = { version = "1.45.1", features = ["full"] }
tracing = "0.1.41"
tracing-error = "0.2.1"
tracing-subscriber = "0.3.20"
tracing-subscriber = { version = "0.3.20", features = ["json"] }
url = "2.5.4"

[dev-dependencies]
Expand Down
38 changes: 31 additions & 7 deletions aptly-latest-snapshots/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ use std::{net::SocketAddr, time::Duration};

use aptly_latest_snapshots::{create_app, periodic_snapshot_refresh, AppState};
use aptly_rest::AptlyRest;
use clap::Parser;
use clap::{Parser, ValueEnum};
use color_eyre::{eyre::WrapErr, Result};
use tracing::info;
use tracing::metadata::LevelFilter;
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;

#[derive(ValueEnum, Clone, Copy, Debug, Default)]
enum LogFormat {
#[default]
Pretty,
Json,
}

#[derive(Parser, Debug)]
struct Opts {
/// Url for the aptly rest api endpoint
Expand All @@ -31,17 +38,34 @@ struct Opts {
default_value_t = 600,
value_parser = clap::value_parser!(u16).range(1..))]
refresh_interval_sec: u16,
/// Log output format
#[clap(long, value_enum, default_value_t = LogFormat::Pretty)]
log_format: LogFormat,
}

fn init_tracing(format: LogFormat) {
match format {
LogFormat::Pretty => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init(),
LogFormat::Json => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(
tracing_subscriber::fmt::layer()
.json()
.with_filter(LevelFilter::INFO),
)
.init(),
}
}

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init();
color_eyre::install().unwrap();

let opts = Opts::parse();
init_tracing(opts.log_format);
color_eyre::install()?;

let aptly = if let Some(token) = &opts.api_token {
AptlyRest::new_with_token(opts.api_url.clone(), token)?
} else {
Expand Down
2 changes: 1 addition & 1 deletion aptlyctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ serde-saphyr = "0.0.27"
tokio = { version = "1.45.1", features = ["full"] }
tracing = "0.1.41"
tracing-error = "0.2.1"
tracing-subscriber = "0.3.20"
tracing-subscriber = { version = "0.3.20", features = ["json"] }
url = "2.5.4"
35 changes: 30 additions & 5 deletions aptlyctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ enum OutputFormat {
Yaml,
}

#[derive(ValueEnum, Clone, Copy, Debug, Default)]
enum LogFormat {
#[default]
Pretty,
Json,
}

#[derive(Subcommand, Debug)]
enum Command {
Repo {
Expand Down Expand Up @@ -60,16 +67,34 @@ struct Opts {
/// Authentication token for the API
#[clap(long, env = "APTLY_API_TOKEN")]
api_token: Option<String>,
/// Log output format
#[clap(long, value_enum, default_value_t = LogFormat::Pretty)]
log_format: LogFormat,
}

fn init_tracing(format: LogFormat) {
match format {
LogFormat::Pretty => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init(),
LogFormat::Json => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(
tracing_subscriber::fmt::layer()
.json()
.with_filter(LevelFilter::INFO),
)
.init(),
}
}

#[tokio::main]
async fn main() -> Result<ExitCode> {
tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init();
color_eyre::install().unwrap();
let opts = Opts::parse();
init_tracing(opts.log_format);
color_eyre::install()?;

let aptly = if let Some(token) = opts.api_token {
AptlyRest::new_with_token(opts.api_url, &token)?
} else {
Expand Down
2 changes: 1 addition & 1 deletion obs2aptly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sync2aptly = { path = "../sync2aptly" }
tokio = { version = "1.45.1", features = ["full"] }
tracing = "0.1.41"
tracing-error = "0.2.1"
tracing-subscriber = "0.3.20"
tracing-subscriber = { version = "0.3.20", features = ["json"] }
url = "2.5.4"

[dev-dependencies]
Expand Down
37 changes: 31 additions & 6 deletions obs2aptly/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use aptly_rest::AptlyRest;
use clap::Parser;
use clap::{Parser, ValueEnum};
use color_eyre::Result;
use sync2aptly::{AptlyContent, PoolPackagesCache, UploadOptions};
use tracing::metadata::LevelFilter;
Expand All @@ -14,6 +14,13 @@ enum FilterKind {
Binaries,
}

#[derive(ValueEnum, Clone, Copy, Debug, Default)]
enum LogFormat {
#[default]
Pretty,
Json,
}

#[derive(Parser, Debug)]
struct Opts {
/// Url for the aptly rest api endpoint
Expand All @@ -40,16 +47,34 @@ struct Opts {
/// Only show changes, don't apply them
#[clap(short = 'n', long, default_value_t = false)]
dry_run: bool,
/// Log output format
#[clap(long, value_enum, default_value_t = LogFormat::Pretty)]
log_format: LogFormat,
}

fn init_tracing(format: LogFormat) {
match format {
LogFormat::Pretty => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init(),
LogFormat::Json => tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(
tracing_subscriber::fmt::layer()
.json()
.with_filter(LevelFilter::INFO),
)
.init(),
}
}

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(ErrorLayer::default())
.with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
.init();
color_eyre::install().unwrap();
let opts = Opts::parse();
init_tracing(opts.log_format);
color_eyre::install()?;

let aptly = if let Some(token) = opts.api_token {
AptlyRest::new_with_token(opts.api_url, &token)?
} else {
Expand Down
Loading