From 48329c850c6d0526bbc0259812d3650cb6141c4b Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Sun, 27 Jul 2025 12:18:32 +0530 Subject: [PATCH 1/6] Update CI for test --- .github/workflows/test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ea1faa..00c506c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: include: - - os: macos-latest + - os: macos-13 target: x86_64-apple-darwin - os: macos-latest target: aarch64-apple-darwin @@ -17,24 +17,24 @@ jobs: target: x86_64-unknown-linux-gnu - os: ubuntu-latest target: i686-unknown-linux-gnu + - os: ubuntu-latest + target: x86_64-unknown-linux-musl - os: windows-latest target: x86_64-pc-windows-msvc - os: windows-latest target: i686-pc-windows-msvc - # - i686-pc-windows-gnu - # - x86_64-pc-windows-gnu runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v4 - name: Install rust uses: dtolnay/rust-toolchain@1.88.0 with: target: ${{ matrix.target }} - name: Install linker - if: matrix.target == 'i686-unknown-linux-gnu' + if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update - sudo apt-get install gcc-multilib + sudo apt-get install musl-tools gcc-multilib + - name: Checkout + uses: actions/checkout@v4 - name: Test run: cargo test --target ${{ matrix.target }} From dcb791b61310d4b7e98fd10397b01e84dd66dc9e Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Sat, 4 Oct 2025 08:12:26 +0530 Subject: [PATCH 2/6] Update CI --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9410531..5ab9b89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,7 +58,7 @@ jobs: fail-fast: false matrix: include: - - os: macos-13 + - os: macos-15-intel target: x86_64-apple-darwin - os: macos-latest target: aarch64-apple-darwin diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00c506c..d79daab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: include: - - os: macos-13 + - os: macos-15-intel target: x86_64-apple-darwin - os: macos-latest target: aarch64-apple-darwin From be07841a482cd7df66cb5a6f03174f2496360d20 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Tue, 11 Nov 2025 13:03:46 +0530 Subject: [PATCH 3/6] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d79f4db..35fa44a 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Download, unarchive the binary, and then put the executable in `$PATH`. ## Contributors -Here is a list of [Contributors](http://github.com/termapps/cli-clap/contributors) +Here is a list of [Contributors](https://github.com/termapps/cli-clap/contributors) ### TODO @@ -81,4 +81,4 @@ MIT/X11 ## Bug Reports -Report [here](http://github.com/termapps/cli-clap/issues). +Report [here](https://github.com/termapps/cli-clap/issues). From dc29e5c2414870a07f3b5def59d2903531ae0ab9 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Thu, 13 Nov 2025 07:44:28 +0530 Subject: [PATCH 4/6] Make CLI library first to use it programmatically --- src/{ => commands}/hello.rs | 4 +-- src/commands/mod.rs | 18 +++++++++++++ src/lib.rs | 51 +++++++++++++++++++++++++++++++++++++ src/main.rs | 44 ++------------------------------ 4 files changed, 73 insertions(+), 44 deletions(-) rename src/{ => commands}/hello.rs (90%) create mode 100644 src/commands/mod.rs create mode 100644 src/lib.rs diff --git a/src/hello.rs b/src/commands/hello.rs similarity index 90% rename from src/hello.rs rename to src/commands/hello.rs index fc075c9..42b38ab 100644 --- a/src/hello.rs +++ b/src/commands/hello.rs @@ -12,12 +12,12 @@ use crate::error::Result; #[derive(Debug, Parser)] pub struct Hello { /// The name of the person to greet - name: String, + pub name: String, } impl Hello { #[instrument(name = "hello", skip_all)] - pub fn run(self) -> Result { + pub(crate) fn run(&self) -> Result { if self.name == "world" { return Err(eyre!("You cannot use cliche")); } diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..61a47c9 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,18 @@ +use clap::Parser; + +use crate::error::Result; + +pub mod hello; + +#[derive(Debug, Parser)] +pub enum Subcommands { + Hello(hello::Hello), +} + +impl Subcommands { + pub(crate) fn run(&self) -> Result { + match self { + Self::Hello(x) => x.run(), + } + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c903622 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,51 @@ +use clap::Parser; +use clap_verbosity_flag::{InfoLevel, Verbosity}; +use colorchoice_clap::Color; + +use crate::{commands::Subcommands, error::Result}; + +pub mod error; +mod styles; + +pub mod commands; + +/// A simple CLI application using clap +#[derive(Debug, Parser)] +#[clap(name = "cli-clap", version)] +#[command(styles = styles::styles())] +pub struct App { + #[command(subcommand)] + pub cmd: Subcommands, + + #[command(flatten)] + pub color: Color, + + #[command(flatten)] + pub verbose: Verbosity, +} + +impl App { + pub fn run(self) -> Result { + self.cmd.run() + } + + pub fn new(cmd: Subcommands) -> Self { + App { + cmd, + color: Color::default(), + verbose: Verbosity::default(), + } + } +} + +#[cfg(test)] +mod test { + use super::*; + + use clap::CommandFactory; + + #[test] + fn verify_app() { + App::command().debug_assert(); + } +} diff --git a/src/main.rs b/src/main.rs index cd9a976..392d639 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,35 +2,9 @@ use std::io::stdout; use anstream::{AutoStream, ColorChoice}; use clap::Parser; -use clap_verbosity_flag::{InfoLevel, Verbosity}; -use colorchoice_clap::Color; +use cli_clap::{App, error}; use tracing_subscriber::prelude::*; -mod error; -mod styles; - -mod hello; - -/// A simple CLI application using clap -#[derive(Debug, Parser)] -#[clap(name = "cli-clap", version)] -#[command(styles = styles::styles())] -struct App { - #[command(subcommand)] - cmd: Subcommands, - - #[command(flatten)] - color: Color, - - #[command(flatten)] - verbose: Verbosity, -} - -#[derive(Debug, Parser)] -enum Subcommands { - Hello(hello::Hello), -} - fn main() { let program = App::parse(); @@ -46,21 +20,7 @@ fn main() { ) .init(); - let result = match program.cmd { - Subcommands::Hello(x) => x.run(), - }; + let result = program.run(); error::finish(result); } - -#[cfg(test)] -mod test { - use super::*; - - use clap::CommandFactory; - - #[test] - fn verify_app() { - App::command().debug_assert(); - } -} From c1e568358d05455835500cd0d0fb8564b519d9c2 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Thu, 13 Nov 2025 20:51:19 +0530 Subject: [PATCH 5/6] Error exit should return ! --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 90ad1d0..4baf861 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,7 @@ pub fn finish(result: Result) { exit(code); } -pub fn exit(code: Code) { +pub fn exit(code: Code) -> ! { stdout().flush().unwrap(); stderr().flush().unwrap(); From 823bc73151ec354aebfb31dfe6ec97a7e9aaddba Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Thu, 13 Nov 2025 21:32:11 +0530 Subject: [PATCH 6/6] Correct visibility for styles --- src/styles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles.rs b/src/styles.rs index 2038c92..3d213d8 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -1,6 +1,6 @@ use clap::builder::{Styles, styling::AnsiColor}; -pub fn styles() -> Styles { +pub(crate) fn styles() -> Styles { Styles::styled() .header(AnsiColor::BrightYellow.on_default()) .usage(AnsiColor::BrightYellow.on_default())