diff --git a/Cargo.toml b/Cargo.toml index 945067a8..d092f39f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ strip-ansi-escapes = "0.1.1" anyhow = "1.0.72" [build-dependencies] +clap = {version = "4.3.19", features = ["default", "cargo"]} clap_mangen = "0.2.12" [features] diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..ba7bc800 --- /dev/null +++ b/build.rs @@ -0,0 +1,29 @@ +use std::env::var_os; +use std::fs::write; +use std::io::{ErrorKind, Result}; +use std::path::PathBuf; + +// This is a bit of a hack to not have to rewrite the cli in the build +#[path = "src/cli.rs"] +mod cli; + +fn main() -> Result<()> { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=src/cli.rs"); + + let out_dir = PathBuf::from(var_os("OUT_DIR").ok_or(ErrorKind::NotFound)?); + println!( + "cargo:warning=manpages built at {:?}", + out_dir.join("little_boxes.1") + ); + + let cmd = cli::cli(); + + let man = clap_mangen::Man::new(cmd); + let mut buffer: Vec = Default::default(); + man.render(&mut buffer)?; + + write(out_dir.join("little_boxes.1"), buffer)?; + + Ok(()) +} diff --git a/build_manpage.sh b/build_manpage.sh deleted file mode 100755 index b1d505c8..00000000 --- a/build_manpage.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cargo build -help2man --no-info --name "Adds boxes around stdin. Optionally adds a title." ./target/debug/little_boxes > little_boxes.1 diff --git a/little_boxes.1 b/little_boxes.1 index 06398f48..c5fd4a55 100644 --- a/little_boxes.1 +++ b/little_boxes.1 @@ -1,30 +1,36 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5. -.TH LITTLE_BOXES "1" "November 2021" "little_boxes 1.7.0" "User Commands" +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.TH little_boxes 1 "little_boxes 1.7.0" .SH NAME -little_boxes \- Adds boxes around stdin. Optionally adds a title. +little_boxes \- Adds boxes around stdin. Optionally adds a title +.SH SYNOPSIS +\fBlittle_boxes\fR [\fB\-t\fR|\fB\-\-title\fR] [\fB\-c\fR|\fB\-\-charset\fR] [\fB\-f\fR|\fB\-\-file\fR] [\fB\-\-all\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] .SH DESCRIPTION -little_boxes 1.7.0 -Gio d'Amelio Adds boxes around stdin. Optionally adds a title -.SS "USAGE:" -.IP -little_boxes [FLAGS] [OPTIONS] -.SS "FLAGS:" +.SH OPTIONS +.TP +\fB\-t\fR, \fB\-\-title\fR=\fITITLE\fR +Add a title to the box +.TP +\fB\-c\fR, \fB\-\-charset\fR=\fICHARSET\fR [default: thick] +The charset to draw the box with +.br + +.br +[\fIpossible values: \fRthick, thin, double, box, rounded, dot] +.TP +\fB\-f\fR, \fB\-\-file\fR=\fIFILE\fR +Read input from a file instead of stdin .TP \fB\-\-all\fR Compare all charsets .TP \fB\-h\fR, \fB\-\-help\fR -Prints help information +Print help .TP \fB\-V\fR, \fB\-\-version\fR -Prints version information -.SS "OPTIONS:" -.TP -\fB\-c\fR, \fB\-\-charset\fR -The charset to draw the box with [default: thick] -[possible values: thick, thin, double, box, -rounded, dot] -.TP -\fB\-t\fR, \fB\-\-title\fR -Add a title to the box +Print version +.SH VERSION +v1.7.0 +.SH AUTHORS +Gio d\*(AqAmelio <gio@damelio.net> diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 00000000..4fd9c29f --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,18 @@ +use std::path::PathBuf; + +use clap::{arg, command, value_parser, Command}; + +pub fn cli() -> Command { + command!() + .arg(arg!(-t --title <TITLE> "Add a title to the box").required(false)) + .arg( + arg!(-c --charset <CHARSET> "The charset to draw the box with") + .value_parser(["thick", "thin", "double", "box", "rounded", "dot"]) + .default_value("thick"), + ) + .arg( + arg!(-f --file <FILE> "Read input from a file instead of stdin") + .value_parser(value_parser!(PathBuf)), + ) + .arg(arg!(--all "Compare all charsets")) +} diff --git a/src/main.rs b/src/main.rs index e89e2732..9f77da91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,10 @@ use std::path::PathBuf; use std::process; use anyhow::{Context, Result}; -use clap::{arg, command, value_parser, ArgMatches}; +use clap::ArgMatches; +mod cli; +use self::cli::cli; mod draw_box; use self::draw_box::{DrawBox, SimpleBox, TitleBox}; mod charset; @@ -30,19 +32,7 @@ fn get_input(matches: &ArgMatches) -> Result<Vec<String>> { } fn run() -> Result<()> { - let matches = command!() - .arg(arg!(-t --title <TITLE> "Add a title to the box").required(false)) - .arg( - arg!(-c --charset <CHARSET> "The charset to draw the box with") - .value_parser(["thick", "thin", "double", "box", "rounded", "dot"]) - .default_value("thick"), - ) - .arg( - arg!(-f --file <FILE> "Read input from a file instead of stdin") - .value_parser(value_parser!(PathBuf)), - ) - .arg(arg!(--all "Compare all charsets")) - .get_matches(); + let matches = cli().get_matches(); let input = get_input(&matches)?;