https://github.com/xpepermint/rawcmd-rs
Command-line application framework.
https://github.com/xpepermint/rawcmd-rs
arg argument cargo command command-line crate flag hacktoberfest input interface rust stdout
Last synced: 26 days ago
JSON representation
Command-line application framework.
- Host: GitHub
- URL: https://github.com/xpepermint/rawcmd-rs
- Owner: xpepermint
- License: mit
- Created: 2020-04-14T15:33:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T08:27:29.000Z (over 4 years ago)
- Last Synced: 2025-03-13T08:59:05.588Z (about 1 month ago)
- Topics: arg, argument, cargo, command, command-line, crate, flag, hacktoberfest, input, interface, rust, stdout
- Language: Rust
- Homepage:
- Size: 85 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
> Command-line application framework.
## Usage
The command line parser will search for the following pattern:
```sh
$ myapp --
```A simple command-line application could look something like this:
```rs
use rawcmd::{Context, Command, Flag, Intent};fn main() {
match Command::with_name("foo")
.with_description("Command 1")
.with_flag(
Flag::with_name("flag1")
.with_alias("f1")
.with_description("Flag 1")
)
.with_param(
Param::with_name("param1")
.with_description("Param 1")
)
.with_subcommand(
Command::with_name("bar")
.with_description("Command 1:1")
.with_flag(
Flag::with_name("flag2")
.with_alias("f2")
.with_description("Flag 2")
)
.with_resolver(|_intent, &mut _context| Ok(2))
)
.with_resolver(|_intent, &mut _context| Ok(3))
.with_handler(|_error, _intent, &mut _context| Ok(4))
.run(
&mut Context::default(),
)
{
Ok(code) => {
println!("Success: {:?}", code);
std::process::exit(0);
},
Err(error) => {
println!("Error: {:?}", error);
std::process::exit(1);
},
}
}
```You can use your own custom context object as well:
```rs
...
.run(
MyContext::default()
)
```