From 30f8f7749e63b710af8a15c88bf87ad71c004b26 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 17 Apr 2026 00:55:09 +0800 Subject: Add help and version flags with external files --- help.txt | 27 +++++++++++++++++++++++++++ src/cli.rs | 12 +++++++++++- tmp.md | 0 version.txt | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 help.txt delete mode 100644 tmp.md create mode 100644 version.txt diff --git a/help.txt b/help.txt new file mode 100644 index 0000000..5145e46 --- /dev/null +++ b/help.txt @@ -0,0 +1,27 @@ +Chaos Billing (cobill) - A CLI bill splitting tool + +SYNOPSIS + cobill [--help | --version] + cobill [] + +COMMANDS + add Add a new bill item + clear Clear all bill items + edit Edit bills using a text editor + ls List all bills or show optimized split result + +EDITOR SHORTCUTS + vi Edit bills with vi + vim Edit bills with vim + nvim Edit bills with neovim + helix Edit bills with helix + nano Edit bills with nano + +EXAMPLES + cobill add -p 100 -r "Dinner" -f Alice Bob + cobill ls --optimize + cobill edit + cobill clear + +SEE ALSO + For detailed help, run `cobill --help` diff --git a/src/cli.rs b/src/cli.rs index 71936cc..a62d41c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use std::{fs::create_dir_all, io::ErrorKind, path::PathBuf}; +use std::{fs::create_dir_all, io::ErrorKind, path::PathBuf, process::exit}; use mingling::{ AnyOutput, Groupped, ShellContext, Suggest, SuggestItem, @@ -21,6 +21,16 @@ use crate::{ pub async fn entry() { let mut program = ThisProgram::new(); + if program.pick_global_flag(["-v", "--version"]) { + println!("{}", include_str!("../version.txt").trim()); + exit(0) + } + + if program.pick_global_flag(["-h", "--help"]) { + println!("{}", include_str!("../help.txt").trim()); + exit(0) + } + // Add Completion program.with_dispatcher(CompletionDispatcher); diff --git a/tmp.md b/tmp.md deleted file mode 100644 index e69de29..0000000 diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..db798f3 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +Chaos Billing v0.1.0 - By Weicao-CatilGrass -- cgit