Skip to content

Commit

Permalink
http: Add version and help flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Jun 21, 2024
1 parent b68ea53 commit abcf8f3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions radicle-httpd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@ use std::num::NonZeroUsize;
use std::{collections::HashMap, process};

use radicle::prelude::RepoId;
use radicle::version::Version;
use radicle_httpd as httpd;

pub const VERSION: Version = Version {
name: "radicle-httpd",
commit: env!("GIT_HEAD"),
version: env!("RADICLE_VERSION"),
timestamp: env!("SOURCE_DATE_EPOCH"),
};

pub const HELP_MSG: &str = r#"
Usage
radicle-httpd [<option>...]
Options
--listen <address> Address to listen on (default: 0.0.0.0:8080)
--alias, -a <alias> <rid> Provide alias and RID pairs to shorten git clone commands for repositories,
e.g. heartwood and rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5 to produce https://seed.radicle.xyz/heartwood.git
--cache <number> Max amount of items in cache for /tree endpoints (default: 100)
--version, -v Print program version
--help, -h Print help
"#;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let options = parse_options()?;

// SAFETY: The logger is only initialized once.
httpd::logger::init().unwrap();
tracing::info!("version {}-{}", env!("RADICLE_VERSION"), env!("GIT_HEAD"));
tracing::info!("starting http daemon..");
tracing::info!("version {} ({})", env!("RADICLE_VERSION"), env!("GIT_HEAD"));

match httpd::run(options).await {
Ok(()) => {}
Expand Down Expand Up @@ -43,12 +67,19 @@ fn parse_options() -> Result<httpd::Options, lexopt::Error> {

aliases.insert(alias, id);
}
Long("version") | Short('v') => {
if let Err(e) = VERSION.write(std::io::stdout()) {
eprintln!("error: {e}");
process::exit(1);
};
process::exit(0);
}
Long("cache") => {
let size = parser.value()?.parse()?;
cache = NonZeroUsize::new(size);
}
Long("help") | Short('h') => {
println!("usage: radicle-httpd [--listen <addr>] [--alias <name> <rid>] [--cache <size>]..");
println!("{HELP_MSG}");
process::exit(0);
}
_ => return Err(arg.unexpected()),
Expand Down

0 comments on commit abcf8f3

Please sign in to comment.