FLI
A library for creating command line apps in rust inspired by the like of commander.js
NOTE: Check out sample code
Changes
For stable changes check the CHANGELOG.md file
For unstable changes check the CHANGELOG.md file
use Fli;
then run it like this
Getting started
Installtion
OR
[]
= "0.0.5"
Import
extern crate fli;
use Fli;
Create an App Instance
OR
Adding Options
// callback for the greet param
Run your app
Adding a new Command Set
You can also add a new command set using the command method
Then you would run the command like this
$ cargo run -- greet -n "codad5"
> Hello Codad5
Doing it in a procedual way
Like commander.js you can also do it in a procedual way
use Fli;
Explaining all app : Fli methods
Note:
All
app : Flimethods are avaliable asapp : &Flimethods
-
app.option(arg_and_data, callback): This method takes in 2 param- First
arg_and_data: This is a format template of how the avaliable arguments for a command would be being in a format-a --argor-a --arg, datawhere-ais the short form of the argument and--argis the long form of the argument.--datais the acceptable data type and it is seperated by a comma,, if not passed then the arg does not need a data type
symbol meaning [] This means it needs one optional data <> This means it needs one required data [...] This means it can take in many optional data <...> This means it needs at least one data, can take more - First
-
app.commad(command_name): This is to create a new command with its own option and param like -
app.default(callback): The default callback incase no args or command is being passed but ano_param_valueis being passed -
app.allow_duplicate_callback(bool): To prevent duplicate callbacks as a result of same callback of anargor as a result of theargbeen passed multiple times- True : Turns it on i.e the code below would work fine
-
app.allow_inital_no_param_values(bool): This is to allow values to a command with no params -
app.run()(!important) : To run the app , -
app.has_a_value(arg_flag): Check if an arg has a value -
app.get_values(arg_flag): get the value(s) of an expect required param, this returns aResultType with a vector of string as the Ok valueVec<String>and&stras the error value
NOTE the method
get_valueswould return theErrEnum if the arg does not expect or require a value
app.is_passed(bool): Check if an arg flag is passed.
NOTE : using the methods
has_a_value,get_valuesandis_passedyou can pass-n , --name , n , nameand they would all return same expected value
app.get_arg_at(u8): Get Arg at a specific position
NOTE : The runner is not included as part of the arg list . ie if a command like this
my-app > greet > helloexist the position 1 for the commandgreetis greet and notmy-app
app.print_help(message): Prints a well descriptive message.
Printing default help thisGet the app general help option
$ my-app --help
Get the move command help option
$ my-app move --help # a new command called