From 817fd5e57f1a5685a9c93c9f7221093c28766fce Mon Sep 17 00:00:00 2001 From: Hakki Date: Sun, 25 Aug 2024 20:18:16 +0000 Subject: [PATCH] cli: add help/manpages (#29) Fixes https://codeberg.org/topola/topola/issues/24 Reviewed on https://codeberg.org/topola/topola/pulls/29 Co-authored-by: Hakki Co-committed-by: Hakki --- .gitignore | 4 ++++ Cargo.toml | 6 +++++- build.rs | 14 ++++++++++++++ src/bin/topola/cli.rs | 17 +++++++++++++++++ src/bin/topola/main.rs | 16 +++------------- 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 build.rs create mode 100644 src/bin/topola/cli.rs diff --git a/.gitignore b/.gitignore index 71bfe8b..831cde5 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,7 @@ Cargo.lock # ---> Topola *.ses +dist/ + +# ignore manpages +topola.1 diff --git a/Cargo.toml b/Cargo.toml index b378ede..ac691b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "topola" -description = "Topological PCB router" +description = "Work-in-progress free and open-source topological (rubberband) router and autorouter for printed circuit boards (PCBs)" version = "0.1.0" edition = "2021" default-run = "topola" @@ -122,3 +122,7 @@ opt-level = 2 [patch.crates-io] contracts = { path = "vendored/contracts" } + +[build-dependencies] +clap_mangen = "0.2.23" +clap = {version="4.5.8", features = ["derive"] } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ca3046c --- /dev/null +++ b/build.rs @@ -0,0 +1,14 @@ +include!("src/bin/topola/cli.rs"); +use clap_mangen::Man; +use clap::CommandFactory; +use std::fs::{File, create_dir_all}; +// https://rust-cli.github.io/book/in-depth/docs.html +fn main() -> Result<(), Box> { + let cmd = Cli::command(); + let man = Man::new(cmd); + let folder = "man"; + create_dir_all(folder)?; + let mut file = File::create(format!("{}/topola.1", folder))?; + man.render(&mut file)?; + Ok(()) +} diff --git a/src/bin/topola/cli.rs b/src/bin/topola/cli.rs new file mode 100644 index 0000000..1455631 --- /dev/null +++ b/src/bin/topola/cli.rs @@ -0,0 +1,17 @@ +use clap::Parser; +use std::path::PathBuf; + + +#[derive(Parser, Debug, Default)] +#[command(about, version)] +pub struct Cli { + #[arg(value_name = "SPECCTRA DESIGN FILE", + help = "Specify the Specctra Design (*.dsn) input file for the Topola autorouter")] + pub input: PathBuf, + #[arg(short, long, value_name = "SPECCTRA SESSION FILE", + help = "Specify the output session file in Specctra-compatible format (*.ses). The input filename is used by default, with the extension changed to Specctra Session File extension") + ] + pub output: Option, + #[arg(short, long, value_name = "COMMAND FILE", help = "JSON-like file with .cmd extension, containing sequence of available commands ")] + pub commands: Option, +} diff --git a/src/bin/topola/main.rs b/src/bin/topola/main.rs index 3d1016c..64f5382 100644 --- a/src/bin/topola/main.rs +++ b/src/bin/topola/main.rs @@ -1,8 +1,6 @@ -use clap::{Error, Parser}; +use clap::Parser; use std::fs::File; -use std::io::prelude::*; use std::io::BufReader; -use std::path::PathBuf; use topola::autorouter::history::History; use topola::autorouter::invoker::Command; use topola::autorouter::invoker::Invoker; @@ -10,19 +8,11 @@ use topola::autorouter::selection::PinSelection; use topola::autorouter::Autorouter; use topola::specctra::design::SpecctraDesign; -#[derive(Parser, Debug, Default)] -#[command(about, version)] -struct Cli { - input: PathBuf, - #[arg(short, long, value_name = "FILE")] - output: Option, - #[arg(short, long, value_name = "FILE")] - commands: Option, -} +pub mod cli; +use cli::Cli; fn main() -> Result<(), std::io::Error> { let args = Cli::parse(); - let design_file = File::open(&args.input)?; let mut design_bufread = BufReader::new(design_file);