-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial CLI skeleton - top level & cert
- Loading branch information
Showing
10 changed files
with
667 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))), | ||
) | ||
} |