{"id":16049991,"url":"https://github.com/codad5/fli","last_synced_at":"2025-08-31T15:04:58.742Z","repository":{"id":167783411,"uuid":"643405017","full_name":"codad5/fli","owner":"codad5","description":"A library for creating CLI apps in rust inspired by the like of commander.js","archived":false,"fork":false,"pushed_at":"2024-01-19T17:34:36.000Z","size":55,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-19T22:02:10.663Z","etag":null,"topics":["cli","crates-io","library","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codad5.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-21T03:47:17.000Z","updated_at":"2023-07-07T21:49:16.000Z","dependencies_parsed_at":"2023-11-25T11:25:10.993Z","dependency_job_id":"a1c0f9c8-1b29-44d7-b09d-930391823a11","html_url":"https://github.com/codad5/fli","commit_stats":null,"previous_names":["codad5/fli"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codad5%2Ffli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codad5%2Ffli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codad5%2Ffli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codad5%2Ffli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codad5","download_url":"https://codeload.github.com/codad5/fli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243885934,"owners_count":20363644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","crates-io","library","rust-lang"],"created_at":"2024-10-09T00:41:39.856Z","updated_at":"2025-03-17T21:31:15.037Z","avatar_url":"https://github.com/codad5.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FLI\r\n\r\nA library for creating command line apps in rust inspired by the like of [commander.js](https://github.com/tj/commander.js)\r\n\r\n\u003e NOTE: Check out [sample code](https://github.com/codad5/fli/blob/master/sample/src/main.rs)\r\n\r\n## Changes\r\nFor stable changes check the [CHANGELOG.md](https://github.com/codad5/fli/blob/master/CHANGELOG.md) file \r\n\r\nFor unstable changes check the [CHANGELOG.md](https://github.com/codad5/fli/blob/dev/CHANGELOG.md) file\r\n\r\n```rust\r\nuse fli::{Fli, init_fli_from_toml};\r\n\r\nfn main(){\r\n    let mut app : Fli = init_fli_from_toml!(); // using the toml file\r\n    app.option(\"-n --name, \u003c\u003e\", \"Name to call you\", |x : \u0026Fli| {});\r\n    app.option(\"-g --greet\", \"greeting\", |x : \u0026Fli| {\r\n        match x.get_values(\"name\".to_owned() /* passing (--name, -n or n) would work*/){\r\n            Ok(value) =\u003e {\r\n                println!(\"Good day {?}\", value[0])\r\n            },\r\n            Err(_) =\u003e {},\r\n        }\r\n    });\r\n    // required for the app  to work \r\n    app.run();\r\n}\r\n```\r\n\r\n\r\nthen run it like this\r\n```bash\r\n$ cargo run -- -g -n james\r\nGood day james\r\n```\r\n\r\n## Getting started\r\n### Installtion\r\n```bash\r\ncargo add fli\r\n```\r\nOR\r\n```toml\r\n[dependencies]\r\nfli = \"0.0.5\"\r\n```\r\n\r\n### Import\r\n```rust\r\nextern crate fli;\r\nuse fli::Fli;\r\nfn main(){\r\n    println!(\"Happy Coding\");\r\n}\r\n```\r\n### Create an App Instance \r\n\r\n```rust\r\nfn main(){\r\n    let mut app = init_fli_from_toml!(); // to init from your cargo.toml file\r\n}\r\n\r\n```\r\n\u003e OR\r\n\r\n```rust\r\nfn main(){\r\n    let mut app = Fli::init(\"app-name\", \"an app description\");\r\n    app.set_version(\"0.0.1\");\r\n}\r\n```\r\n\r\n\r\n### Adding Options\r\n\r\n```rust\r\nfn main(){\r\n    let mut app = init_fli_from_toml!();\r\n    app.option(\"-g --greet\", \"to make a greeting\", greet);\r\n    app.option(\"-n --name, \u003c\u003e\", \"to set your name\", |x|{});\r\n}\r\n\r\n// callback for the greet param\r\nfn greet(x: \u0026Fli){\r\n    match x.get_values(\"--name\".to_owned()){\r\n        Ok(option) =\u003e {\r\n            println!(\"Good day {?}\", v[0]);\r\n        },\r\n        Err(_) =\u003e {},\r\n    }\r\n}\r\n```\r\n\r\n### Run your app\r\n```rust\r\nfn main(){\r\n    //... other code\r\n    app.run();\r\n}\r\n```\r\n\r\n### Adding a new Command Set\r\nYou can also add a new command set using the command method\r\n```rust\r\nfn main(){\r\n    let mut app = init_fli_from_toml!();\r\n    app.command(\"greet\", \"An app that respects\")\r\n    .default(greet)\r\n    .allow_inital_no_param_values(false)\r\n    .option(\"-n --name, \u003c\u003e\", \"To print your name along side\", greet)\r\n    .option(\"-t --time, []\", \"For time based Greeting\", greet);\r\n    app.run();\r\n}\r\n\r\nfn greet(x){ /*code to greet \"*/ }\r\n```\r\nThen you would run the command like this\r\n```shell\r\n$ cargo run -- greet -n \"codad5\" \r\n\u003e Hello Codad5\r\n```\r\n\r\n### Doing it in a procedual way\r\nLike commander.js you can also do it in a procedual way\r\n\r\n```rust\r\nuse fli::Fli;\r\n\r\nfn main(){\r\n    //  doing it procedual way\r\n    let mut app = init_fli_from_toml!();\r\n    let moveCommand = app.command(\"move\", \"move files\");\r\n    // the [...] means accept optional multiple\r\n    moveCommand.option(\"-p --path, \u003c...\u003e\", \"path to files to be moved\", move_file);\r\n    app.option(\"-g --greet\",  \"to make a greeting\", |x|{});\r\n    app.option(\"-n --name, \u003c\u003e\", \"to set your name\", |x|{});\r\n    app.run();\r\n\r\n    if app.is_passed(\"--greet\"){\r\n        if app.has_a_value(\"-n\"){/* greet person with name*/}\r\n        else { /* freet without name*/ }\r\n    }\r\n}\r\n```\r\n\r\n## Explaining all `app : Fli` methods\r\n**Note:**\r\n\u003e All `app : Fli` methods are avaliable as `app : \u0026Fli` methods\r\n- `app.option(arg_and_data, callback)` : \r\nThis method takes in 2 param \r\n  - First `arg_and_data` : This is a format template of how the avaliable arguments for a command would be being in a format `-a --arg` or `-a --arg, data` where `-a` is the short  form of the argument and `--arg` is the long form of the argument. `--data` is the acceptable data type and it is seperated by a **comma** `,` , if not passed then the arg does not need a data type\r\n  \r\n  | symbol | meaning |\r\n  |:---:|:---|\r\n  | [] | This means it needs one optional data|\r\n  | \u003c\u003e | This means it needs one required data |\r\n  | [...] | This means it can take in many optional data |\r\n  | \u003c...\u003e | This means it needs at least one data, can take more |\r\n\r\n\r\n- `app.commad(command_name)` : \r\nThis is to create a new command with its own option and param like\r\n\r\n- `app.default(callback)` : The default callback incase no args or command is being passed but a `no_param_value` is being passed \r\n\r\n- `app.allow_duplicate_callback(bool)` : To prevent duplicate callbacks as a result of same callback of an `arg` or as a result of the `arg` been passed multiple times\r\n    - True : Turns it on i.e the code below would work fine\r\n    ```bash \r\n    $ myapp \"some ran value\"\r\n    ```\r\n\r\n- `app.allow_inital_no_param_values(bool)` : This is to allow values to a command with no params  \r\n\r\n- `app.run()` **(!important)** : To run the app , \r\n\r\n- `app.has_a_value(arg_flag)` : Check if an arg has a value \r\n- `app.get_values(arg_flag)` : get the value(s) of  an expect required param,  this returns a `Result` Type with a vector of string as the Ok value `Vec\u003cString\u003e` and `\u0026str` as the error value \r\n\u003e NOTE  the method `get_values` would return the `Err` Enum if the arg does not expect or require a value\r\n\r\n- `app.is_passed(bool)` : Check if an arg flag is passed. \r\n\r\n\u003e NOTE : using the methods `has_a_value`, `get_values` and `is_passed` you can pass `-n , --name , n , name` and they would all return same expected value\r\n\r\n- `app.get_arg_at(u8)` : Get Arg at a specific position \r\n\u003e NOTE :  The runner is not included as part of the arg list . ie if a command like this `my-app \u003e greet \u003e hello` exist the position 1 for the command `greet` is greet and not `my-app`\r\n\r\n- `app.print_help(message)` : Prints a well descriptive message.\r\n\r\n\r\n\u003ePrinting default help thisGet the app general help option\r\n\u003e ```shell\r\n\u003e $ my-app --help\r\n\u003e ```\r\nGet the move command help option\r\n```shell\r\n$ my-app move --help # a new command called\r\n```\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodad5%2Ffli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodad5%2Ffli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodad5%2Ffli/lists"}