Skip to content

Commit

Permalink
initial CLI skeleton - top level & cert
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Sep 12, 2024
1 parent 288a9a8 commit 328a243
Show file tree
Hide file tree
Showing 10 changed files with 667 additions and 3 deletions.
526 changes: 526 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ package.edition = "2021"
package.authors = ["Ross Younger <[email protected]>"]
package.license = "AGPL-3.0-or-later"

[workspace.dependencies]
anyhow = "1.0.88"
clap = "4.5"
quinn = "0.11"

[workspace.lints.rust]
dead_code = "warn"
elided_lifetimes_in_paths = "deny"
Expand Down
6 changes: 5 additions & 1 deletion qcpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ license.workspace = true
rust-version = "1.74.0"

[dependencies]

anstyle = "1.0.8"
anyhow = { workspace = true }
clap = { workspace = true, features = ["wrap_help", "derive", "cargo", "help"] }
rcgen = "0.13"
#quinn = { workspace = true }
33 changes: 33 additions & 0 deletions qcpt/src/cert/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! qcpt cert command line interface
// (c) 2024 Ross Younger

#[derive(Clone, Debug, clap::Subcommand)]
//#[command(flatten_help = true)]
/// Subcommands to Cert
pub enum CertCommands {
/// Outputs the fingerprint of the local certificate
#[clap(alias = "fpr")]
Fingerprint,
/// Generates a local certificate, overwriting the existing one (if any)
Generate,
/// Ensures that a local certificate exists, generating one if necessary
Ensure,
}

/// Arguments to 'cert'
#[derive(Debug, clap::Args)]
//#[command(flatten_help = true)]
pub struct CertArgs {
#[command(subcommand)]
cmd: CertCommands,
// opt: Custom --path (default: something OS-specific e.g. ~/.qcpt.cert) ?
}

/// Implementation of 'cert' CLI
pub fn cert(_args: &CertArgs) -> anyhow::Result<()> {
match _args.cmd {
CertCommands::Fingerprint => todo!(),
CertCommands::Generate => todo!(),
CertCommands::Ensure => todo!(),
}
}
4 changes: 4 additions & 0 deletions qcpt/src/cert/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Local X509 certificate management
/// (c) 2024 Ross Younger
pub mod cli;
pub mod store;
5 changes: 5 additions & 0 deletions qcpt/src/cert/store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// X509 certificate storage
// (c) 2024 Ross Younger

// / Local X509 certificate store
//struct Local {}
41 changes: 41 additions & 0 deletions qcpt/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! qcpt command line interface base
/// (c) 2024 Ross Younger
use clap::Parser;

use crate::cert;

#[derive(Debug, Parser)]
#[command(author, version, about, long_about = "QCP transport utility")]
//#[command(author(clap::crate_authors!()), version, about, long_about = "QCP transport utility")]
#[command(help_template(
"\
{before-help}{name} {version}
(c) {author-with-newline}{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
"
))]
#[command(styles=crate::styles::get())]
/// Top-level CLI definition
pub struct Cli {
#[command(subcommand)]
/// User's chosen subcommand
pub command: Commands,
}

#[derive(Debug, clap::Subcommand)]
//#[command(flatten_help = true)]
/// Subcommands
pub enum Commands {
/// Certificate management
Cert(cert::cli::CertArgs),
}

/// Main CLI entrypoint
pub fn cli_main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Cert(args) => cert::cli::cert(&args),
}
}
4 changes: 4 additions & 0 deletions qcpt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// (c) 2024 Ross Younger
pub mod cert;
pub mod cli;
pub mod styles;
7 changes: 5 additions & 2 deletions qcpt/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fn main() {
println!("Hello, world!");
/// Transport utility for qcp - main entrypoint
/// (c) 2024 Ross Younger
fn main() -> anyhow::Result<()> {
qcpt::cli::cli_main()
}
39 changes: 39 additions & 0 deletions qcpt/src/styles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// Default styling for clap output
#[must_use]
pub fn get() -> clap::builder::Styles {
clap::builder::Styles::styled()
.usage(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))),
)
.header(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))),
)
.literal(
anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))),
)
.invalid(
anstyle::Style::new()
.bold()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))),
)
.error(
anstyle::Style::new()
.bold()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))),
)
.valid(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))),
)
.placeholder(
anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::White))),
)
}

0 comments on commit 328a243

Please sign in to comment.