diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-17 00:55:09 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-17 00:55:09 +0800 |
| commit | 30f8f7749e63b710af8a15c88bf87ad71c004b26 (patch) | |
| tree | f587518f63933ad67ed2e09431fda5638fe46d59 | |
| parent | 2374370f8ea5e2c794e4838c12ed9f799e6206c8 (diff) | |
Add help and version flags with external files
| -rw-r--r-- | help.txt | 27 | ||||
| -rw-r--r-- | src/cli.rs | 12 | ||||
| -rw-r--r-- | tmp.md | 0 | ||||
| -rw-r--r-- | version.txt | 1 |
4 files changed, 39 insertions, 1 deletions
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 <command> [<args>] + +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` @@ -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/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 |
