{"id":18746490,"url":"https://github.com/nadoo/conflag","last_synced_at":"2025-04-12T22:14:59.672Z","repository":{"id":57484136,"uuid":"97579564","full_name":"nadoo/conflag","owner":"nadoo","description":"conflag is a drop-in replacement for Go's standard flag package with config file support.","archived":false,"fork":false,"pushed_at":"2022-02-09T06:01:10.000Z","size":31,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T03:48:22.033Z","etag":null,"topics":["config","flag","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nadoo.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":"2017-07-18T09:25:07.000Z","updated_at":"2023-03-22T03:05:14.000Z","dependencies_parsed_at":"2022-08-26T14:20:40.718Z","dependency_job_id":null,"html_url":"https://github.com/nadoo/conflag","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadoo%2Fconflag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadoo%2Fconflag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadoo%2Fconflag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadoo%2Fconflag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nadoo","download_url":"https://codeload.github.com/nadoo/conflag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637794,"owners_count":21137538,"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":["config","flag","go"],"created_at":"2024-11-07T16:25:41.326Z","updated_at":"2025-04-12T22:14:59.641Z","avatar_url":"https://github.com/nadoo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# conflag\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/nadoo/conflag?style=flat-square)](https://goreportcard.com/report/github.com/nadoo/conflag)\n[![GitHub tag](https://img.shields.io/github/v/tag/nadoo/conflag.svg?sort=semver\u0026style=flat-square)](https://github.com/nadoo/conflag/releases)\n[![Go Document](https://img.shields.io/badge/go-document-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/nadoo/conflag )\n\nconflag is a drop-in replacement for Go's standard flag package with config file support.\n\n## Usage\n\n### Your code:\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/nadoo/conflag\"\n)\n\nvar conf struct {\n\tName string\n\tAge  int\n\tMale bool\n}\n\nfunc main() {\n\t// get a new conflag instance\n\tflag := conflag.New()\n\n\t// setup flags as the standard flag package\n\tflag.StringVar(\u0026conf.Name, \"name\", \"\", \"your name\")\n\tflag.IntVar(\u0026conf.Age, \"age\", 0, \"your age\")\n\tflag.BoolVar(\u0026conf.Male, \"male\", false, \"your sex\")\n\n\t// parse before access flags\n\tflag.Parse()\n\n\t// now you're able to get the parsed flag values\n\tfmt.Printf(\"  Name: %s\\n\", conf.Name)\n\tfmt.Printf(\"  Age: %d\\n\", conf.Age)\n\tfmt.Printf(\"  Male: %v\\n\", conf.Male)\n}\n```\n\n### Run without config file:\ncommand:\n```bash\nexample -name Jay -age 30\n```\noutput:\n```bash\n  Name: Jay\n  Age: 30\n  Male: false\n```\n\n### Run with config file and environment variable(-config):\nexample.conf:\n```bash\nname={$NAME}\nage=20\nmale\n```\ncommand: **use \"-config\" flag to specify the config file path.**\n```bash\nNAME=Jason example -config example.conf\n```\noutput:\n```bash\n  Name: Jason\n  Age: 20\n  Male: true\n```\n\n### Run with config file and OVERRIDE a flag value using commandline:\nexample.conf:\n```bash\nname=Jason\nage=20\nmale\n```\ncommand:\n```bash\nexample -config example.conf -name Michael\n```\noutput:\n```bash\n  Name: Michael\n  Age: 20\n  Male: true\n```\n\n## Config File\n- format: KEY=VALUE\n\n**just use the command line flag name as key name**:\n\n```bash\n## config file\n# comment line starts with \"#\"\n\n# format:\n#KEY=VALUE, \n# just use the command line flag name as key name\n# use {$ENV_VAR_NAME} in VALUE to get the Environment Variable value\n\n# your name\nname={$NAME}\n\n# your age\nage=20\n\n# are you male?\nmale=true\n\n# use include to include more config files\ninclude=part1.inc.conf\ninclude=part2.inc.conf\n```\nSee [example.conf](example/example.conf)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadoo%2Fconflag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnadoo%2Fconflag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadoo%2Fconflag/lists"}