{"id":18044596,"url":"https://gitlab.com/tardi/medusa","last_synced_at":"2025-04-10T01:06:33.405Z","repository":{"id":57637718,"uuid":"16653667","full_name":"tardi/medusa","owner":"tardi","description":"General template for building command line interface (CLI) using (and written in) Rust","archived":false,"fork":false,"pushed_at":null,"size":null,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":null,"default_branch":"master","last_synced_at":"2025-04-10T01:06:26.818Z","etag":null,"topics":["binary","cli","command-line","command-line-interface","command-line-tool","command-line-utilities","crate","executable","libraty","rust","rust-crate","rust-lang","rust-library","scratch"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":null,"metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-02T10:07:50.089Z","updated_at":"2020-03-21T13:45:23.032Z","dependencies_parsed_at":"2022-09-02T03:23:02.823Z","dependency_job_id":null,"html_url":"https://gitlab.com/tardi/medusa","commit_stats":null,"previous_names":[],"tags_count":6,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/tardi%2Fmedusa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/tardi%2Fmedusa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/tardi%2Fmedusa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/tardi%2Fmedusa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/owners/tardi","download_url":"https://gitlab.com/tardi/medusa/-/archive/master/medusa-master.zip","host":{"name":"gitlab.com","url":"https://gitlab.com","kind":"gitlab","repositories_count":4518607,"owners_count":6922,"icon_url":"https://github.com/gitlab.png","version":null,"created_at":"2022-05-30T11:31:42.605Z","updated_at":"2024-07-18T11:24:13.055Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/owners"}},"keywords":["binary","cli","command-line","command-line-interface","command-line-tool","command-line-utilities","crate","executable","libraty","rust","rust-crate","rust-lang","rust-library","scratch"],"created_at":"2024-10-30T18:09:32.484Z","updated_at":"2025-04-10T01:06:33.384Z","avatar_url":null,"language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# medusa\n\nGeneral template for building command line interface (CLI) using (and written in) Rust\n\n## Running the example\n\n- Run the example without arguments\n\n```bash\ncargo run --example simple\n```\n\n- Run the example with arguments\n\n```bash\ncargo run --example simple -- --echo \"hello universe\"\n```\n\n- Run the example with stateful arguments\n\n```bash\ncargo run --example stateful -- --echo \"hello universe\" --twice\n```\n\n## How to use\n\n- Add crates dependencies in your `Cargo.toml`\n\n```toml\n...\n[dependencies]\nmedusa = \"0.3.0\"\n...\n```\n\n- Import the library\n\n```rust\n...\nuse medusa::{ArgType, CommandLine, Handler, Variant};\n...\n```\n\n- Create example function as your CLI option handler\n\n```rust\n...\nfn hello(handler: \u0026Handler) {\n  println!(\"Hello, world!\");\n}\n\nfn echo(handler: \u0026Handler, payload: String) {\n  println!(\"payload : {}\", payload);\n}\n\nfn print_twice(handler: \u0026Handler) {\n  if let Some(argtype) = handler.get_arg(\"--echo\") {\n    if let ArgType::Content(payload) = argtype {\n      println!(\"printed once more : {}\", payload);\n    }\n  }\n}\n...\n```\n\n- Create your handler and add some actions\n\n```rust\n...\nlet mut handler: Handler = Handler::new();\nhandler.add(\n  String::from(\"--hello\"),\n  Variant::Plain(hello),\n  String::from(\"Print hello world for testing purpose.\")\n);\nhandler.add(\n  String::from(\"--echo\"),\n  Variant::WithArg(echo),\n  String::from(\"Print string passed to this parameter to output.\")\n);\nhandler.add(\n  String::from(\"--twice\"),\n  Variant::Plain(print_twice),\n  String::from(\"Print again the payload \\\"--echo\\\" have.\"),\n);\n...\n```\n\n- Register your handler into CLI command\n\n```rust\n...\nuse std::env;\n\nlet mut command: CommandLine = CommandLine::new();\ncommand.set_handler(handler);\ncommand.set_name(\"mycli\");\ncommand.set_version(\"1.0.0\");\ncommand.run(env::args());\n...\n```\n\n- Test your Rust code if it's really works\n\n```bash\ncargo run -- --hello\ncargo run -- --echo something\ncargo run -- --echo greatstring --twice\n```\n\n- Compile your code\n\n```bash\ncargo build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/gitlab.com%2Ftardi%2Fmedusa","html_url":"https://awesome.ecosyste.ms/projects/gitlab.com%2Ftardi%2Fmedusa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/gitlab.com%2Ftardi%2Fmedusa/lists"}