{"id":37119990,"url":"https://github.com/youta-t/flarc","last_synced_at":"2026-01-14T13:59:14.468Z","repository":{"id":224280874,"uuid":"762895618","full_name":"youta-t/flarc","owner":"youta-t","description":"commandline parser, supporting flag, args, and subcommands","archived":false,"fork":false,"pushed_at":"2024-02-25T11:24:34.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-02-28T02:25:45.946Z","etag":null,"topics":["argparser","commandlineparser","flags","flarc","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","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":"https://github.com/youta-t.png","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-25T01:38:36.000Z","updated_at":"2024-05-30T02:30:49.750Z","dependencies_parsed_at":"2024-02-25T02:34:59.343Z","dependency_job_id":"ee76363d-2a29-4bdf-95fa-517a3a08859a","html_url":"https://github.com/youta-t/flarc","commit_stats":null,"previous_names":["youta-t/flarc"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/youta-t/flarc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youta-t%2Fflarc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youta-t%2Fflarc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youta-t%2Fflarc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youta-t%2Fflarc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/youta-t","download_url":"https://codeload.github.com/youta-t/flarc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youta-t%2Fflarc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["argparser","commandlineparser","flags","flarc","go","golang"],"created_at":"2026-01-14T13:59:13.917Z","updated_at":"2026-01-14T13:59:14.461Z","avatar_url":"https://github.com/youta-t.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"flarc -- commandline parser, supports flag, arg, subcommands\n============================================================\n\nflarc is a commandline parser. With flarc, you can\n\n- declare *fl*ags, gnu style (short option `-f` and long option `--flag`)\n- declare positional *ar*guments, and\n- declare sub*c*ommands\n- get generated help texts\n\nInstall\n--------\n\n```\ngo get github.com/youta-t/flarc\n```\n\nflarc needs go1.21+.\n\nUsage\n------\n\n### Define command\n\n```go\n// ...\nimport \"github.com/youta-t/flarc\"\n// ...\n\n// declare struct for flags.\n// Flag options can be set with tag.\n//\n// Recognized tag keys are:\n//\n// - flag:    flag name. by default, field-name-in-kebab-case.\n// - alias:   aliases of the flag.\n// - help:    help message.\n// - metavar: value example in Usage section in help.\n//            By default, the default value of the flag is used.\n//\ntype Flag struct {\n    Foo string  `alias:\"f\" help:\"flag foo\" metavar:\"FOO\"`\n    Bar int     // when no tag, assumed as `flag:\"${field-name-in-kebab-case}\"` is given.\n    Fizz bool   `flag:\"F\"`  // flag name is case sensitive\n    Bazz time.Duration  `metavar:\"DURATION\"`\n}\n\nfunc main() {\n\n// ...\n\n\tcmd, err := flarc.NewCommand(\n\t\t\"short description...\",\n\n\t\t// declare default values for flags\n\t\tFlag{\n\t\t\tFoo:  \"default foo\",\n\t\t\tBar:  42,\n\t\t\tFizz: false,\n\t\t\tBazz: 3 * time.Second,\n\t\t},\n\n\t\t// declare positional args\n\t\tflarc.Args{\n\t\t\t{\n\t\t\t\tName:       \"SOURCE\", // positional arg name\n\t\t\t\tRepeatable: true,     // set true if this arg takes many items\n\t\t\t\tRequired:   true,     // require at least 1 item\n\t\t\t\tHelp:       \"help message of SOURCE\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tName: \"DEST\", Required: true,\n\t\t\t\tHelp: \"help message of DEST\",\n\t\t\t},\n\t\t},\n\n\t\tfunc(\n\t\t\tctx context.Context,\n\t\t\tcommandline flarc.Commandline[Flag],\n\t\t\tparam []any,\n\t\t) error {\n\t\t\t// parsed flag\n\t\t\tvar flag Flag = commandline.Flags()\n\n\t\t\t// key is arg's name. values are assigned commandline\n\t\t\tvar args map[string][]string = commandline.Args()\n\n\t\t\tbuf := make([]byte, 1024)\n\t\t\tio.ReadAtLeast(commandline.Stdin(), buf, 0)\n\n\t\t\tfmt.Fprintf(commandline.Stdout(), \"passed flag: %+v\\n\\n\", flag)\n\t\t\tfmt.Fprintf(commandline.Stdout(), \"passed arg: %+v\\n\\n\", args)\n\t\t\tfmt.Fprintf(commandline.Stdout(), \"passed params: %+v\\n\\n\", param)\n\n\t\t\treturn nil\n\t\t},\n\n\t\t// Description is template.\n\t\t// Placeholder {{ .Command }} will be replaced with command name at runtime.\n\t\tflarc.WithDescription(`this is example command.\n\nTo show how to declare flags and args, also genereatad help message.\n\nThis command is called \"{{ .Command }}\"\n`),\n\t)\n\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, \"unexpected error:\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// ...\n}\n```\n\n### Run command\n\n```go\nfunc main() {\n\t// ...\n\n\tctx, cancel := signal.NotifyContext(\n\t\tcontext.Background(), os.Interrupt,\n\t)\n\tdefer cancel()\n\n\ttype param struct {\n\t\tParamValue string\n\t}\n\n\tos.Exit(flarc.Run(\n\t\tctx, cmd,\n\n\t\t// (optional) extra params.\n\t\t//\n\t\t// For example, loggers can be injected with this.\n\t\tflarc.WithParams([]any{param{ParamValue: \"this is param value\"}}),\n\t))\n}\n```\n\nReturn status is selected by flarc.\n\nIf the task of command returns,\n\n- `nil`: success! exits with `0`.\n- `flarc.ErrUsage`: prints help message and exits with `2`.\n- other error: exits with `1`.\n\n\n```\n$ go run ./example/example_command -f foo -F false source1 source2 dest1\npassed flag: {Foo:foo Bar:42 Fizz:false Bazz:3s}\n\npassed arg: map[DEST:[dest1] SOURCE:[source1 source2]]\n\npassed params: [{ParamValue:this is param value}]\n\n```\n\nBy default, flarc provides `--help, -h` flag to show help message.\n\n```\n$ go run ./example/example_command --help\nexample_command -- short description...\n\nUsage:\n\n    example_command --foo=FOO --bar=0 --fizz=false --bazz=DURATION --help=false SOURCE[, ...] DEST\n\nDescription:\n\n    this is example command.\n    \n    To show how to declare flags and args, also genereatad help message.\n    \n    This command is called \"example_command\"\n    \n\nFlags:\n\n    --foo, -f   flag foo\n    --bar\n    --fizz, -F\n    --bazz\n    --help, -h  show help message\n\nArgs:\n\n    SOURCE      help message of SOURCE\n    DEST        help message of DEST\n```\n\n### Define Command Group and Subcommand\n\n```go\n// ...\n\ntype GroupFlag struct {\n\tQux  string `alias:\"q\" help:\"help for command group flag\"`\n\tQuux string `alias:\"Q\"`\n}\n\n//...\n\nfunc main() {\n\n\t// ...\n\n\tgrp, err := flarc.NewCommandGroup(\n\t\t\"description of command group\",\n\t\tGroupFlag{\n\t\t\tQux:  \"qux\",\n\t\t\tQuux: \"QUUX\",\n\t\t},\n\t\tflarc.WithGroupDescription(`command group description.\n\nThis command is called as \"{{ .Command }}\".\n`),\n\t\tflarc.WithSubcommand(\"sub\", cmd),\n\t)\n\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, \"unexpected error:\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// ...\n}\n```\n\n#### run it\n\nHelp for command group:\n\n```\n$ go run ./example/example_subcommand --help\nexample_subcommand -- description of command group\n\nUsage:\n\n    example_subcommand --qux --quux --help=false\n\nDescription:\n\n    command group description.\n    \n    This command is called as \"example_subcommand\".\n    \n\nFlags:\n\n    --qux, -q   help for command group flag\n    --quux, -Q\n    --help, -h  show help message\n\nSubcommands:\n\n    sub         short description...\n```\n\nHelp for subcommand:\n\n```\n$ go run ./example/example_subcommand sub --help\nexample_subcommand sub -- short description...\n\nUsage:\n\n    example_subcommand sub --foo=FOO --bar=0 --fizz=false --bazz=DURATION --qux --quux --help=false SOURCE[, ...] DEST\n\nDescription:\n\n    this is example command.\n    \n    To show how to declare flags and args, also genereatad help message.\n    \n\nFlags:\n\n    --foo, -f   flag foo\n    --bar\n    --fizz, -F\n    --bazz\n    --qux, -q   help for command group flag\n    --quux, -Q\n    --help, -h  show help message\n\nArgs:\n\n    SOURCE      help message of SOURCE\n    DEST        help message of DEST\n```\n\n```\n$ go run ./example/example_subcommand sub -f foo -F false -q \"queue\" -Q \"Queue\" source1 source2 dest1\npassed flag: {Foo:foo Bar:42 Fizz:false Bazz:3s}\n\npassed arg: map[DEST:[dest1] SOURCE:[source1 source2]]\n\npassed params: [{ParamValue:this is param value} {Qux:queue Quux:Queue}]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyouta-t%2Fflarc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyouta-t%2Fflarc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyouta-t%2Fflarc/lists"}