scaffold the CLI, logging and turn research into TODOs
This commit is contained in:
commit
6aa7e23872
17 changed files with 888 additions and 0 deletions
11
xtask/Cargo.toml
Normal file
11
xtask/Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "xtask"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
clap.workspace = true
|
||||
clap_mangen = "0.2.31"
|
||||
git-identity = { path = "../" }
|
||||
22
xtask/src/main.rs
Normal file
22
xtask/src/main.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
|
||||
mod manpage;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
Manpage(manpage::Cli),
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Command::Manpage(cli) => manpage::main(cli),
|
||||
}
|
||||
}
|
||||
25
xtask/src/manpage.rs
Normal file
25
xtask/src/manpage.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::{CommandFactory as _, Parser};
|
||||
|
||||
/// Render the manpage of git-identity from its clap definition
|
||||
#[derive(Parser)]
|
||||
pub struct Cli {
|
||||
/// The file in which to write the newly generated manpage
|
||||
///
|
||||
/// By default, this is "target/git-identity.1"
|
||||
out_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
pub fn main(cli: Cli) -> anyhow::Result<()> {
|
||||
let man = clap_mangen::Man::new(git_identity::cli::Cli::command());
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
man.render(&mut buffer)?;
|
||||
|
||||
std::fs::write(
|
||||
cli.out_file.unwrap_or_else(|| "./target/git-identity.1".into()),
|
||||
buffer,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue