{"id":20997513,"url":"https://github.com/cdump/scfg","last_synced_at":"2025-12-29T23:19:59.041Z","repository":{"id":78470068,"uuid":"228856116","full_name":"cdump/scfg","owner":"cdump","description":"Simple config library","archived":false,"fork":false,"pushed_at":"2023-03-22T06:38:27.000Z","size":39,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T09:12:28.847Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdump.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.inih.txt","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":"2019-12-18T14:22:40.000Z","updated_at":"2022-09-21T23:54:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"d243d191-afa2-47a4-a8e5-7b7f97fc4ffb","html_url":"https://github.com/cdump/scfg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdump%2Fscfg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdump%2Fscfg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdump%2Fscfg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdump%2Fscfg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdump","download_url":"https://codeload.github.com/cdump/scfg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243410491,"owners_count":20286424,"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":[],"created_at":"2024-11-19T07:40:01.303Z","updated_at":"2025-12-29T23:19:59.014Z","avatar_url":"https://github.com/cdump.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Config\n\nhttps://github.com/cdump/scfg\n\n## How to start\n\n1. Add to your bazel `WORKSPACE`:\n```\nhttp_archive(\n    name = \"com_github_cdump_scfg\",\n    strip_prefix = \"scfg-\u003cgithash\u003e\",\n    urls = [\n        \"https://github.com/cdump/scfg/archive/\u003cgithash\u003e.tar.gz\",\n    ],\n)\n\nload(\"@com_github_cdump_scfg//:scfg_deps.bzl\", \"scfg_deps\")\n\nscfg_deps()\n```\n\n\n2. add the following code in your file with main function:\n```\n#include \"scfg/scfg_types.hpp\"\n// clang-format off\n#define SCFG_APP_CONFIG(XX)                                                            \\\n  XX((input),              std::string,  'i', SCFG_NO_DEFAULT, \"required string arg\")  \\\n  XX((num),                unsigned, 0,  8,                    \"num with default val\") \\\n  /**/                                                                                 \\\n  XX((enabled,   filter),  bool,     0,  false,                \"filter on/off\")        \\\n  XX((threshold, filter),  double,   0,  1.4,                  \"filter threhsold\")     \\\n  /**/                                                                                 \\\n// clang-format on\n\n#include \"scfg/scfg.hpp\"\nscfg::config cfg;\n\n...\n\nint\nmain(int argc, char **argv)\n{\n    try {\n        cfg = scfg::init(argc, argv);\n    } catch(std::exception \u0026ex) {\n        printf(\"Err: %s\\n\", ex.what());\n        return 1;\n    }\n    ...\n}\n```\n\nNow you can use parsed params as `cfg.input` (std::string), `cfg.num` (unsigned), `cfg.filter_enabled` (bool), `cfg.filter_threshold` (double)\n\n## Options priority\n0. Default values\n1. Values from config file\n2. Values from ENV\n3. Values from command line\n\nFor example, command line option overwrites the config value, ENV var overwrites config value and so on\n\n## Example\nSee full example in example.cc\n\n* Compile:\n\n```sh\n$ bazel build '@//:example'\n```\n\n* Show help:\n\n```sh\n$ ./bazel-bin/example --help\nUsage: ./bazel-bin/example [options]\n  -h, --help                 {bool}     - display this help and exit\n  -c, --config               {string}   - path to config file\n  -C, --config-template      {bool}     - echo default config to stdout\n  -i, --input                {string}   - required string arg\n      --file                 {string}   - string arg default\n      --num                  {number}   - num with default val\n      --filter-enabled       {bool}     - filter on/off\n      --filter-threshold     {double}   - filter threhsold\n      --filter-subgroup-val  {double}   - filter subgroup\n```\n\n* Run without args:\n\n```sh\n$ ./bazel-bin/example\nOption -i (--input) must be set\nErr: not all required options provided\n```\n\n* Run with required arg:\n\n```sh\n$ ./bazel-bin/example --input xxx \nConfig values, config-file: (not specified)\n  .input = xxx\n  .file = /etc/passwd\n  .num = 8\n  filter.enabled = false\n  filter.threshold = 1.500000\n  filter.subgroup_val = 1.200000\n\ninput='xxx', filter: [0 ; 1.500000; 1.200000]\n```\n\n* Generate default config:\n\n```sh\n$ ./bazel-bin/example -i defaultinput --config-template \u003e config.yaml \u0026\u0026 cat config.yaml\n\n---\ninput: defaultinput\nfile: /etc/passwd\nnum: 8\nfilter:\n  enabled: false\n  threshold: 1.5\n  subgroup:\n    val: 1.2\n...\n```\n\n* Run with config \u0026 override config params:\n\n```sh\n$ CFG_NUM=41 ./bazel-bin/example --config config.yaml --input aaa\nConfig values, config-file: config.yaml\n  .input = aaa\n  .file = /etc/passwd\n  .num = 41\n  filter.enabled = false\n  filter.threshold = 1.500000\n  filter.subgroup_val = 1.200000\n\ninput='aaa', filter: [0 ; 1.500000; 1.200000]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdump%2Fscfg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdump%2Fscfg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdump%2Fscfg/lists"}