{"id":17132242,"url":"https://github.com/bitsofinfo/gitops-argparser","last_synced_at":"2025-10-25T10:02:59.260Z","repository":{"id":146759081,"uuid":"221285326","full_name":"bitsofinfo/gitops-argparser","owner":"bitsofinfo","description":"Simple utility for parsing and enforcing cd/cd control arguments embedded in commit or tag messages","archived":false,"fork":false,"pushed_at":"2019-11-12T21:26:10.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-24T07:19:18.229Z","etag":null,"topics":["azure-devops","azure-pipelines","cicd","continuous-integration","devops"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitsofinfo.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":"2019-11-12T18:31:16.000Z","updated_at":"2024-06-19T12:34:13.013Z","dependencies_parsed_at":null,"dependency_job_id":"5d997ca9-c1c3-458f-a3b3-f3aadc5dc516","html_url":"https://github.com/bitsofinfo/gitops-argparser","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"purl":"pkg:github/bitsofinfo/gitops-argparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fgitops-argparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fgitops-argparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fgitops-argparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fgitops-argparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitsofinfo","download_url":"https://codeload.github.com/bitsofinfo/gitops-argparser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fgitops-argparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280936360,"owners_count":26416544,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["azure-devops","azure-pipelines","cicd","continuous-integration","devops"],"created_at":"2024-10-14T19:26:28.622Z","updated_at":"2025-10-25T10:02:59.244Z","avatar_url":"https://github.com/bitsofinfo.png","language":"Go","readme":"# gitops-argparser\n\n[![Build Status](https://travis-ci.org/bitsofinfo/gitops-argparser.svg?branch=master)](https://travis-ci.org/bitsofinfo/gitops-argparser)\n\nThis project provides a simple utility that can be used in gitops driven CI/CD processes which support setting variables via echoing and/or writing specific syntaxes to STDOUT. The utility was created to support the idea of defining and enforcing custom CI/CD *arguments* that developers can decorate within git commit messages which would then be used to alter default CI/CD behavior. \n\n`gitops-argparser` permits you to define your available arguments, expected types, default values etc in a YAML file, and then be invoked with any set of those arguments, and it will emit custom output using a golang template with [Sprig functions support](https://github.com/Masterminds/sprig).\n\n## Azure DevOps example\n\nAzure DevOps pipelines supports [Logging Commands](https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md) which detect various commands in STDOUT and then take further action based on those commands in a pipeline; one of which is `##vso[task.setvariable variable=varname]varvalue`\n\n### Lets define our supported commit message arguments\n\nCreate a file called `config.yaml`, the location of this file defaults to the local dir but can be overriden with the ENV var: `COMMIT_MSG_ARGPARSER_CONFIG_FILE`\n\n```\narguments:\n  - long: arg1\n    dataType: string\n    help: This is argument number one\n    defaultValue: arg1default\n  - long: arg2\n    dataType: string\n    help: This is argument number two\n    defaultValue: \"hi\"\n  - long: arg3\n    dataType: int\n    help: This is argument number three\n    defaultValue: 2\n  - long: arg4\n    dataType: bool\n    help: This is argument number four\n    defaultValue: true\n```\n\n### Lets define how we will handle the args in a template\n\nCreate a file called `output.tmpl`. This is a [golang text/template](https://golang.org/pkg/text/template/) with [Sprig functions support](https://github.com/Masterminds/sprig). The location of this file defaults to the local dir but can be overriden with the ENV var: `COMMIT_MSG_ARGPARSER_OUTPUT_TMPL_FILE`\n```\n{{ range $arg := .Arguments }}\n##vso[task.setvariable variable={{$arg.Name}}]{{$arg.Value}}\n{{ end }}\n```\n\n### Lets run it manually to simulate a commit message being processed\n\n```\n\u003e ./gitops-argparser some raw commit message value -arg1 arg1value -arg2 arg2val -arg3 9999 -arg4=true\n\n{\"level\":\"debug\",\"msg\":\"loadArgumentsConf(): reading argparser arguments conf from: config.yaml\",\"time\":\"2019-11-12T13:59:09-05:00\"}\n{\"level\":\"debug\",\"msg\":\"loadOutputTemplateFile(): reading argparser output template from: output.tmpl\",\"time\":\"2019-11-12T13:59:09-05:00\"}\n\n##vso[task.setvariable variable=arg1]arg1value\n\n##vso[task.setvariable variable=arg2]arg2val\n\n##vso[task.setvariable variable=arg3]9999\n\n##vso[task.setvariable variable=arg4]true\n```\n\nWe can see it validates the arguments and converts them to Azure *log commands* which will set variables in a pipeline.\n\nIf you call it with nothing you get the defaults:\n```\n\u003e ./gitops-argparser \n\n{\"level\":\"debug\",\"msg\":\"loadArgumentsConf(): reading argparser arguments conf from: config.yaml\",\"time\":\"2019-11-12T13:59:20-05:00\"}\n{\"level\":\"debug\",\"msg\":\"loadOutputTemplateFile(): reading argparser output template from: output.tmpl\",\"time\":\"2019-11-12T13:59:20-05:00\"}\n\n##vso[task.setvariable variable=arg1]arg1default\n\n##vso[task.setvariable variable=arg2]hi\n\n##vso[task.setvariable variable=arg3]2\n\n##vso[task.setvariable variable=arg4]true\n```\n\n### Hook it up in an Azure pipeline task\n\nProcess a normal a commit message:\n```\n...\n\n- task: Bash@3\n    displayName: Parse commit message args\n    targetType: 'Inline'\n    script: ./gitops-argparser $(Build.SourceVersionMessage)\n\n- task: Bash@3\n    displayName: Print pipeline vars from commit message args\n    targetType: 'Inline'\n    script: | \n        echo $(arg1)\n        echo $(arg2)\n        echo $(arg3)\n        echo $(arg4)\n```\n\nProcess an annotated tag message:\n```\n...\n\n- task: Bash@3\n    displayName: Parse commit message args\n    targetType: 'Inline'\n    script: |\n      export GIT_TAG_MSG=`git tag -l --format='%(contents:lines=1)' $(Build.SourceBranchName)`\n      echo \"GIT_TAG_MSG=$GIT_TAG_MSG\"\n      ./gitops-argparser $GIT_TAG_MSG\n\n- task: Bash@3\n    displayName: Print pipeline vars from commit message args\n    targetType: 'Inline'\n    script: | \n        echo $(arg1)\n        echo $(arg2)\n        echo $(arg3)\n        echo $(arg4)\n```\n\n## Important behavior notes\n\nParsing starts at the first token after the command that begins with a dash/hypen `-` character\n```\n# OK: gets all args\n./gitops-argparser whatever text -arg1 x -arg2 y\n\n# OK: gets all args\n./gitops-argparser whatever text -arg1 x -arg2 y some trailing text\n\n# NOT OK: stops parsing on first NON argument (only captures -arg1)\n./gitops-argparser whatever text -arg1 x other-non-quoted-text -arg2 y some trailing text\n```\n\nAlso note golangs [flag](https://golang.org/pkg/flag/) documentation; in particular how `bool` arguments are interpreted. Its important you set them w/ `-arg=[boolvalue]` syntax as `-arg [boolvalue]` does not work w/ them.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fgitops-argparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitsofinfo%2Fgitops-argparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fgitops-argparser/lists"}