{"id":13410452,"url":"https://github.com/cosiner/flag","last_synced_at":"2026-02-15T04:37:23.534Z","repository":{"id":55609362,"uuid":"70079873","full_name":"cosiner/flag","owner":"cosiner","description":"Flag is a simple but powerful command line option parsing library for Go support infinite level subcommand","archived":false,"fork":false,"pushed_at":"2020-12-27T11:14:27.000Z","size":126,"stargazers_count":131,"open_issues_count":2,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-07-31T20:42:39.148Z","etag":null,"topics":["commandline","option-parser"],"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/cosiner.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}},"created_at":"2016-10-05T16:49:41.000Z","updated_at":"2024-04-19T09:21:24.000Z","dependencies_parsed_at":"2022-08-15T04:20:30.384Z","dependency_job_id":null,"html_url":"https://github.com/cosiner/flag","commit_stats":null,"previous_names":["zhuah/flag"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/cosiner/flag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fflag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fflag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fflag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fflag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosiner","download_url":"https://codeload.github.com/cosiner/flag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fflag/sbom","scorecard":{"id":305547,"data":{"date":"2025-08-11","repo":{"name":"github.com/cosiner/flag","commit":"d925800a740358080d75d29590a1e793473124ca"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/cosiner/flag/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/cosiner/flag/go.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T21:56:23.841Z","repository_id":55609362,"created_at":"2025-08-17T21:56:23.841Z","updated_at":"2025-08-17T21:56:23.841Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29469711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T04:35:06.950Z","status":"ssl_error","status_checked_at":"2026-02-15T04:33:41.357Z","response_time":118,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["commandline","option-parser"],"created_at":"2024-07-30T20:01:07.012Z","updated_at":"2026-02-15T04:37:23.517Z","avatar_url":"https://github.com/cosiner.png","language":"Go","readme":"# Flag\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/cosiner/flag) \n\nFlag is a simple but powerful commandline flag parsing library for [Go](https://golang.org).\n\n# Documentation\nDocumentation can be found at [Godoc](https://godoc.org/github.com/cosiner/flag)\n\n# Supported features\n* bool\n  * `-f`, `-f=false`, `-f=true`, there is no `-f true` and `-f false` to avoid conflicting \n    with positional flag and non-flag values\n* string,number\n  * `-f a.go -n 100`\n* slice:\n  * `-f a.go -f b.go -f c.go`\n* hint flag as value\n  * `--` to hint next argument is value: `rm -- -a.go`, \n    `rm -- -a.go -b.go` will throws error for `-b.go` is invalid flag\n  * `--*` to hint latter all arguments are value: `rm -- -a.go -b.go -c.go`\n* useful tricks:\n  * `-f a.go`, `-f=a.go`, `--file=a.go`\n  * `-zcf=a.go`, `-zcf a.go`\n  * `-I/usr/include`: only works for `-[a-zA-Z][^a-zA-Z].+`\n* catch non-flag arguments:\n  * `rm -rf a.go b.go c.go`, catchs `[a.go, b.go, c.go]` \n* positional flag:\n  * `cp -f src.go dst.go`, catchs `SOURCE=a.go DESTINATION=dst.go`\n  * This is implemented as a special case of non-flag arguments, positional flags will be applied first, and remain values\n* value apply/checking\n  * default value\n  * environment value\n  * value list for user selecting\n* multiple flag names for one flag\n* subcommand.\n\n# Definition via structure field tag\n* `names`: flag/command names, comma-speparated, default uses camelCase of field name(with a `-` prefix for flag)\n  * `-` to skip this field\n  * `@` to indicate that this is a positional flag\n  * support multiple name and formats: eg: `-f, --file, -file'\n* `arglist`: argument list for command or argument name for flag\n  * for positional flag, this will also be used as it's display name if defined, otherwise field name is used.\n  * command example: eg: `[OPTION]... SOURCE DESTINATION`, or `[FLAG]... FILE [ARG}...` \n  * flag example: eg: 'FILE', 'DESTINATION'\n* `version`: version message for command\n* `usage`: short description\n* `desc`: long description\n* `env`: environment name for flag, if user doesn't passed this flag, environment value will be used\n* `default`: default value for flag, if user doesn't passed this flag and environment value not defined, it will be used \n* `args`: used to catching non-flag arguments, it's type must be `[]string`\n\n* special cases\n  * `Enable`, there must be a `Enable` field inside command to indicate whether user are using this command.\n  * `Args`: this field will be used to store non-flag arguments if `args` tag is not defined\n  * `Metadata`: structure could implement this interface to override settings defined by tags\n  ```Go\n    type Metadata interface {\n\t    // the key is comma-separated flag name to find command/flag,\n        // each component represents a level, \"\" represents root command\n        Metadata() map[string]Flag\n    }\n  ```\n  \n# Example\n## Flags\n```Go\npackage flag\n\nimport \"fmt\"\n\ntype Tar struct {\n\tGZ          bool     `names:\"-z, --gz\" usage:\"gzip format\"`\n\tBZ          bool     `names:\"-j, --bz\" usage:\"bzip2 format\"`\n\tXZ          bool     `names:\"-J, --xz\" usage:\"xz format\"`\n\tCreate      bool     `names:\"-c\" usage:\"create tar file\"`\n\tExtract     bool     `names:\"-x\" usage:\"extract tar file\"`\n\tFile        string   `names:\"-f\" usage:\"output file for create or input file for extract\"`\n\tDirectory   string   `names:\"-C\" usage:\"extract directory\"`\n\tSourceFiles []string `args:\"true\"`\n}\n\nfunc (t *Tar) Metadata() map[string]Flag {\n\tconst (\n\t\tusage   = \"tar is a tool for manipulate tape archives.\"\n\t\tversion = `\n\t\t\tversion: v1.0.0\n\t\t\tcommit: 10adf10dc10\n\t\t\tdate:   2017-01-01 10:00:01\n\t\t`\n\t\tdesc = `\n\t\ttar creates and manipulates streaming archive files.  This implementation can extract\n\t\tfrom tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images and can create tar, pax,\n\t\tcpio, ar, and shar archives.\n\t\t`\n\t)\n\treturn map[string]Flag{\n\t\t\"\": {\n\t\t\tUsage:   usage,\n\t\t\tVersion: version,\n\t\t\tDesc:    desc,\n\t\t},\n\t\t\"--gz\": {\n\t\t\tDesc: \"use gzip format\",\n\t\t},\n\t}\n}\n\nfunc ExampleFlagSet_ParseStruct() {\n\tvar tar Tar\n\n\tNewFlagSet(Flag{}).ParseStruct(\u0026tar, \"tar\", \"-zcf\", \"a.tgz\", \"a.go\", \"b.go\")\n\tfmt.Println(tar.GZ)\n\tfmt.Println(tar.Create)\n\tfmt.Println(tar.File)\n\tfmt.Println(tar.SourceFiles)\n\n\t// Output:\n\t// true\n\t// true\n\t// a.tgz\n\t// [a.go b.go]\n}\n\n```\n## Help message\n```\ntar is a tool for manipulate tape archives.\n\nUsage:\n      flag.test [FLAG]...\n\nVersion:\n      version: v1.0.0\n      commit: 10adf10dc10\n      date:   2017-01-01 10:00:01\n\nDescription:\n      tar creates and manipulates streaming archive files.  This implementation can extract\n      from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images and can create tar, pax,\n      cpio, ar, and shar archives.\n\nFlags:\n      -z, --gz     gzip format (bool)\n            use gzip format\n      -j, --bz     bzip2 format (bool)\n      -J, --xz     xz format (bool)\n      -c           create tar file (bool)\n      -x           extract tar file (bool)\n      -f           output file for create or input file for extract (string)\n      -C           extract directory (string)\n```\n\n## FlagSet\n```Go\n\ntype GoCmd struct {\n\tBuild struct {\n\t\tEnable  bool\n\t\tAlready bool   `names:\"-a\" important:\"1\" desc:\"force rebuilding of packages that are already up-to-date.\"`\n\t\tRace    bool   `important:\"1\" desc:\"enable data race detection.\\nSupported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64.\"`\n\t\tOutput  string `names:\"-o\" arglist:\"output\" important:\"1\" desc:\"only allowed when compiling a single package\"`\n\n\t\tLdFlags  string   `names:\"-ldflags\" arglist:\"'flag list'\" desc:\"arguments to pass on each go tool link invocation.\"`\n\t\tPackages []string `args:\"true\"`\n\t} `usage:\"compile packages and dependencies\"`\n\tClean struct {\n\t\tEnable bool\n\t} `usage:\"remove object files\"`\n\tDoc struct {\n\t\tEnable bool\n\t} `usage:\"show documentation for package or symbol\"`\n\tEnv struct {\n\t\tEnable bool\n\t} `usage:\"print Go environment information\"`\n\tBug struct {\n\t\tEnable bool\n\t} `usage:\"start a bug report\"`\n\tFix struct {\n\t\tEnable bool\n\t} `usage:\"run go tool fix on packages\"`\n\tFmt struct {\n\t\tEnable bool\n\t} `usage:\"run gofmt on package sources\"`\n}\n\nfunc (*GoCmd) Metadata() map[string]Flag {\n\treturn map[string]Flag{\n\t\t\"\": {\n\t\t\tUsage:   \"Go is a tool for managing Go source code.\",\n\t\t\tArglist: \"command [argument]\",\n\t\t},\n\t\t\"build\": {\n\t\t\tArglist: \"[-o output] [-i] [build flags] [packages]\",\n\t\t\tDesc: `\n\t\tBuild compiles the packages named by the import paths,\n\t\talong with their dependencies, but it does not install the results.\n\t\t...\n\t\tThe build flags are shared by the build, clean, get, install, list, run,\n\t\tand test commands:\n\t\t\t`,\n\t\t},\n\t}\n}\n\nfunc TestSubset(t *testing.T) {\n\tvar g GoCmd\n\n\tset := NewFlagSet(Flag{})\n\tset.StructFlags(\u0026g)\n\tset.Help(false)\n\tfmt.Println()\n\tbuild, _ := set.FindSubset(\"build\")\n\tbuild.Help(false)\n}\n```\n##Help Message\n```\nGo is a tool for managing Go source code.\n\nUsage:\n      flag.test command [argument]\n\nSets:\n      build        compile packages and dependencies\n      clean        remove object files\n      doc          show documentation for package or symbol\n      env          print Go environment information\n      bug          start a bug report\n      fix          run go tool fix on packages\n      fmt          run gofmt on package sources\n```\n```\ncompile packages and dependencies\n\nUsage:\n      build [-o output] [-i] [build flags] [packages]\n\nDescription:\n      Build compiles the packages named by the import paths,\n      along with their dependencies, but it does not install the results.\n      ...\n      The build flags are shared by the build, clean, get, install, list, run,\n      and test commands:\n\nFlags:\n      -a                  \n            force rebuilding of packages that are already up-to-date.\n      -race               \n            enable data race detection.\n            Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64.\n      -o output           \n            only allowed when compiling a single package\n\n      -ldflags 'flag list'\n            arguments to pass on each go tool link invocation.\n```\n# LICENSE\nMIT.\n","funding_links":[],"categories":["Command Line","命令行","Build Automation","\u003cspan id=\"命令行-command-line\"\u003e命令行 Command Line\u003c/span\u003e","命令行工具### 标准 CLI`用于创建一个标准命令行应用程序的库`","命令行工具"],"sub_categories":["Standard CLI","标准CLI","标准 CLI","標準命令行交互","标准命令行交互"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosiner%2Fflag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosiner%2Fflag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosiner%2Fflag/lists"}