aopt
A flexible and typed getopt like command line framwork for rust.
Features
-
Option support
-
Prefixed option support, such as
-f
,--flag
,-flag
or--/flag
. -
Option value support, such as
-f 42
,--flag 3.14
or--flag=foo
. -
Multiple style option support, such as
-f 42
,-f=42
or-f42
. -
Combing style support, such as
-abc
is same as-a
-b
-c
. -
Positional arguments support, see
Index
. -
Type support, you can validator the value of option during parsing.
See the built-in option type
AOpt
-
-
Non UTF8 arguments support
-
Callback support
Can set callback which will called during parsing, see
Parser
andInvoker
. -
Value support
By default aopt will saving the raw value and parsed value in
ValStorer
. -
Policy support
-
DelayPolicy
process positional arguments before any other option. -
FwdPolicy
process options before positional arguments. -
SeqPolicy
process all type arguments one by one.
-
-
Derive support
- Checkout
cote
crate for derive support and help message generate.
- Checkout
Setup
cargo add aopt
sync
feature
If you want the utils of current crate implement Send
and Sync
, you can enable sync
feature.
Examples
Using AFwdParser
parsing process the command line.
use *;
app.exe --depth=98 +S github --depth=42 +S gitlab gitcode
output
Adding location(github) with depth(98)
Adding location(gitlab) with depth(42)
Save destination location(gitcode)
Application target\debug\example.exe will copy location(github, depth=98) to destination(gitcode)
Application target\debug\example.exe will copy location(gitlab, depth=42) to destination(gitcode)
Using getopt!
parsing multiple sub command.
use *;
-
app.exe ls -debug
outputinvoke list command: debug=true, force=false, local-only=false, source="lib.rs"
-
app.exe update -force -source=crates.io
outputinvoke update command: debug=false, force=true, source="crates.io"
-
app.exe in software -/o -s crates.io
outputinvoke install command: debug=false, override=true, source="crates.io"
-
app.exe in aopt
outputError: command not matched
Can support different policy
use *;
use error;
use raw2str;
use Error;
Simple flow chart
+---------------------------------------+
| Policy |
| |
+--------------+ | +-----------+ +------------+ | +-------------+
| | | | | | | | Invoke | |
| Arguments +---->| | Checker | | Process |<----+----------------+ Invoker |
| | | | | | | | the callback | |
+--------------+ | +---^-------+ ++-----^-----+ | +-------------+
| | | | |
| | | | |
+------+--------------+-----+-----------+
| | |
| | |
| Save the values |Process the arguments
| | |
| | |
Check the options | |
| | |
| | |
| +----v-----+-----------+
| | |
+---------+ Option Set |
| |
+----------------------+
More examples
-
simple-find-file
A simple file search tools, try it using cargo install --path simple-find-file
.
- snowball-follow
Get the follow count of stock in xueqiu.com
, try it using cargo install --path snowball-follow
- index constituent
Search and list the constituent of index, try it using cargo install --path index-constituent
Release log
Follow the link.
LICENSE
MPL-2.0