{"id":22170400,"url":"https://github.com/speed2exe/subcommander","last_synced_at":"2025-03-24T17:30:36.819Z","repository":{"id":265933584,"uuid":"743595253","full_name":"speed2exe/subcommander","owner":"speed2exe","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-19T04:51:56.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T22:24:29.878Z","etag":null,"topics":["zig","zig-lib","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/speed2exe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-01-15T15:12:45.000Z","updated_at":"2025-01-19T04:51:58.000Z","dependencies_parsed_at":"2025-01-19T05:23:48.178Z","dependency_job_id":"a5841e28-5f41-483e-b9c7-220aa939f060","html_url":"https://github.com/speed2exe/subcommander","commit_stats":null,"previous_names":["speed2exe/subcommander"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speed2exe%2Fsubcommander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speed2exe%2Fsubcommander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speed2exe%2Fsubcommander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speed2exe%2Fsubcommander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/speed2exe","download_url":"https://codeload.github.com/speed2exe/subcommander/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245318752,"owners_count":20595826,"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":["zig","zig-lib","zig-library","zig-package"],"created_at":"2024-12-02T06:47:38.017Z","updated_at":"2025-03-24T17:30:36.792Z","avatar_url":"https://github.com/speed2exe.png","language":"Zig","readme":"# Subcommander\n- command line parser with sub commands\n\n## Features\n- No heap allocation\n- Declarative\n\n## Add as dependency to your Zig project\n\n- `build.zig.zon`\n```\n.{\n    .dependencies = .{\n        .subcommander = .{\n            // use a commit hash\n            .url = \"https://github.com/speed2exe/subcommander/archive/52c42f27cc888d3a9a0fbda6889b8a931ca673be.tar.gz\",\n            // upon compilation, you will get an error with the correct hash,\n            // replace the following hash with the correct hash\n            .hash = \"1220cea02c171a09873b197687c80a0e1a632e58ab99b779d2d5b0090c116efe5348\",\n        },\n    },\n}\n```\n\n- `build.zig`\n```zig\n    //...\n    const subcommander_dep = b.dependency(\"subcommander\", .{});\n    const subcommander = subcommander_dep.module(\"subcommander\");\n    exe.addModule(\"subcommander\", subcommander);\n    //...\n```\n\n## Compatibility\n- not compatible with windows (yet)\n\n## Usage\n\n```zig\nconst std = @import(\"std\");\nconst subcommander = @import(\"subcommander\");\n\nfn main() !void {\n    // build your commands and flags here\n    // define what flags to parse\n    const mycommands: subcommander.Command = .{\n        // if not specified, will parse the flags, then subcommands (if any)\n        // this will be the name of the program.\n        // e.g. \"greet --name=world\"\n        // usually you would want to skip this (dont specify) since the name of executable will not be consistent\n        // for majority of use cases.\n        //\n        // .match = \"greet\",\n\n        // fn to execute when the command is matched\n        .execute = greetHandler,\n\n        // flags are local to the command \"greet\"\n        .flags = \u0026.{\n            .{\n                .short = \"n\",\n                .long = \"name\",\n                .description = \"name to greet\",\n            },\n            .{\n                .short = \"h\",\n                .long = \"help\",\n                .description = \"print help\",\n            },\n        },\n\n        // subcommands are command that follows after `match`\n        .subcommands = \u0026.{\n            .{\n                .match = \"tom\",\n                .execute = greetTomHandler,\n                .flags = \u0026.{\n                    // addition flags after \"tom\"\n                    // e.g. args; \"greet tom --tomflag=5 ...\"\n                    //\n                },\n            },\n        },\n\n    };\n\n    // run commands with args from the command line\n    // Flag value type: ?[*:0]const u8\n    // Success:\n    // ./mygreet --name=world    # Flag value for name: \"world\"\n    // ./mygreet --name=         # Flag value for name: \"\"\n    // ./mygreet --name          # Flag value for name: null\n    // ./mygreet\n    //\n    // We are skipping the first argument since it is the name of the program\n    // therefore flags are parsed first, then subcommands\n    try mycommands.run(std.os.argv[1..]);\n}\n\n// function signature for greetHandler\nfn greetHandler(input: *const subcommander.InputCommand) void {\n    // get the command that was matched\n    std.debug.print(\"{s}\", .{input.name.?}); // prints \"greet\"\n\n    // iterate over the flags for \"greet\"\n    var flag_iter = input.flagIterRec();\n    while (flag_iter.next()) |flag| {\n        const value: ?[*:0]const u8 = flag.value;\n        // do something with the flag\n    }\n\n    // call next() to get the subcommand (if any)\n    if (input.next) |next_input| {\n        // `next_input` is same type as `input`\n    }\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeed2exe%2Fsubcommander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspeed2exe%2Fsubcommander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeed2exe%2Fsubcommander/lists"}