{"id":17718278,"url":"https://github.com/vidhanio/fncli","last_synced_at":"2025-04-28T17:06:01.390Z","repository":{"id":63910935,"uuid":"571747252","full_name":"vidhanio/fncli","owner":"vidhanio","description":"An attribute macro to simplify writing simple command line applications.","archived":false,"fork":false,"pushed_at":"2023-03-22T23:38:26.000Z","size":40,"stargazers_count":34,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-15T07:10:33.030Z","etag":null,"topics":["command-line","macro","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/fncli","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vidhanio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2022-11-28T19:56:47.000Z","updated_at":"2024-09-15T06:56:03.000Z","dependencies_parsed_at":"2024-10-26T00:27:24.880Z","dependency_job_id":null,"html_url":"https://github.com/vidhanio/fncli","commit_stats":{"total_commits":36,"total_committers":1,"mean_commits":36.0,"dds":0.0,"last_synced_commit":"80231e55ac9c25f6115843df68fcb8b6077e0a73"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidhanio%2Ffncli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidhanio%2Ffncli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidhanio%2Ffncli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidhanio%2Ffncli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vidhanio","download_url":"https://codeload.github.com/vidhanio/fncli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251352585,"owners_count":21575861,"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":["command-line","macro","rust"],"created_at":"2024-10-25T14:43:36.069Z","updated_at":"2025-04-28T17:06:01.369Z","avatar_url":"https://github.com/vidhanio.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `fncli`\n\nAn attribute macro to simplify writing simple command line applications.\n\n## Example\n\n```rust\n#[fncli::cli]\nfn main(a: i32, b: i32) {\n    println!(\"{}\", a + b);\n}\n```\n\n```rust\n$ cargo run 1 2\n3\n```\n\n```rust\n$ cargo run 1\nmissing argument: `b: i32`\n\nUSAGE:\n    target/debug/examples/add \u003ca: i32\u003e \u003cb: i32\u003e\n```\n\n```rust\n$ cargo run 1 2 3\ntoo many arguments (expected 2)\n\nUSAGE:\n    target/debug/examples/add \u003ca: i32\u003e \u003cb: i32\u003e\n```\n\n```rust\n$ cargo run 1 a\nfailed to parse argument: `b: i32`: ParseIntError { kind: InvalidDigit }\n\nUSAGE:\n    target/debug/examples/add \u003ca: i32\u003e \u003cb: i32\u003e\n```\n\nFor a more complete example, see [the time elapsed example](examples/time_elapsed.rs).\n\n## How It Works\n\n```rust\nfn main() {\n    let (a, b) = {\n        let mut args = std::env::args();\n\n        let cmd = args.next().expect(\"should have a command name\");\n\n        let exit = |err: \u0026str| -\u003e ! {\n            eprintln!(\"{err}\");\n            eprintln!();\n            eprintln!(\"USAGE:\\n\\t{cmd} \u003ca: i32\u003e \u003cb: i32\u003e\");\n            std::process::exit(1)\n        };\n\n        let tuple = (\n            i32::from_str(\n                \u0026args\n                    .next()\n                    .unwrap_or_else(|| exit(\"missing argument: `a: i32`\")),\n            )\n            .unwrap_or_else(|e| exit(\u0026format!(\"failed to parse argument `a: i32` ({e:?})\"))),\n            i32::from_str(\n                \u0026args\n                    .next()\n                    .unwrap_or_else(|| exit(\"missing argument: `b: i32`\")),\n            )\n            .unwrap_or_else(|e| exit(\u0026format!(\"failed to parse argument `b: i32` ({e:?})\"))),\n        );\n\n        if args.next().is_some() {\n            exit(\"too many arguments (expected 2)\");\n        }\n\n        tuple\n    };\n\n    {\n        println!(\"{}\", a + b);\n    }\n}\n```\n\nThe generated code is very simple, and not too different from how one would write the code by hand.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidhanio%2Ffncli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvidhanio%2Ffncli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidhanio%2Ffncli/lists"}