diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0df8b02 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,65 @@ +use std::path::PathBuf; + +use clap::{Args, Parser, Subcommand}; + +mod bindings; +mod cli; +mod make_nar; +mod path_info; +pub mod push; +pub mod store; +mod uploader; + +#[derive(Parser, Debug)] +#[command(version)] +#[command(name = "nixcp")] +#[command(about = "Upload store paths to a s3 binary cache")] +#[command(long_about = None)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, + + /// Whether to enable tokio-console + #[arg(long)] + pub tokio_console: bool, +} + +#[derive(Debug, Subcommand)] +pub enum Commands { + #[command(arg_required_else_help = true)] + Push(PushArgs), +} + +#[derive(Debug, Args)] +pub struct PushArgs { + /// The s3 bucket to upload to + #[arg(long, value_name = "bucket name")] + bucket: String, + + /// Upstream cache to check against. Can be specified multiple times. + /// cache.nixos.org is always included. + #[arg(long = "upstream", short, value_name = "nixcache.example.com")] + upstreams: Vec, + + /// Path to the file containing signing key + /// e.g. ~/cache-priv-key.pem + #[arg(long)] + signing_key: String, + + /// If unspecified, will get it form AWS_DEFAULT_REGION envar or default to us-east-1 + #[arg(long)] + region: Option, + + /// If unspecifed, will get it from AWS_ENDPOINT envar + /// e.g. https://s3.example.com + #[arg(long)] + endpoint: Option, + + #[arg(long)] + skip_signature_check: bool, + + /// Path to upload + /// e.g. ./result or /nix/store/y4qpcibkj767szhjb58i2sidmz8m24hb-hello-2.12.1 + #[arg(value_name = "PATH")] + pub paths: Vec, +} diff --git a/src/main.rs b/src/main.rs index 0fefdf5..1afe4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,76 +1,10 @@ -#![feature(let_chains)] -#![feature(exit_status_error)] - -use std::path::PathBuf; - use anyhow::{Context, Result}; -use clap::{Args, Parser, Subcommand}; +use clap::Parser; use tracing_subscriber::{EnvFilter, prelude::*}; -use push::Push; -use store::Store; - -mod bindings; -mod cli; -mod make_nar; -mod path_info; -mod push; -mod store; -mod uploader; - -#[derive(Parser, Debug)] -#[command(version)] -#[command(name = "nixcp")] -#[command(about = "Upload store paths to a s3 binary cache")] -#[command(long_about = None)] -struct Cli { - #[command(subcommand)] - command: Commands, - - /// Whether to enable tokio-console - #[arg(long)] - tokio_console: bool, -} - -#[derive(Debug, Subcommand)] -enum Commands { - #[command(arg_required_else_help = true)] - Push(PushArgs), -} - -#[derive(Debug, Args)] -pub struct PushArgs { - /// The s3 bucket to upload to - #[arg(long, value_name = "bucket name")] - bucket: String, - - /// Upstream cache to check against. Can be specified multiple times. - /// cache.nixos.org is always included. - #[arg(long = "upstream", short, value_name = "nixcache.example.com")] - upstreams: Vec, - - /// Path to the file containing signing key - /// e.g. ~/cache-priv-key.pem - #[arg(long)] - signing_key: String, - - /// If unspecified, will get it form AWS_DEFAULT_REGION envar or default to us-east-1 - #[arg(long)] - region: Option, - - /// If unspecifed, will get it from AWS_ENDPOINT envar - /// e.g. https://s3.example.com - #[arg(long)] - endpoint: Option, - - #[arg(long)] - skip_signature_check: bool, - - /// Path to upload - /// e.g. ./result or /nix/store/y4qpcibkj767szhjb58i2sidmz8m24hb-hello-2.12.1 - #[arg(value_name = "PATH")] - paths: Vec, -} +use nixcp::push::Push; +use nixcp::store::Store; +use nixcp::{Cli, Commands}; #[tokio::main] async fn main() -> Result<()> {