{"id":19282225,"url":"https://github.com/theskyinflames/cmdarchetype","last_synced_at":"2025-02-23T22:21:25.947Z","repository":{"id":137365653,"uuid":"174608184","full_name":"theskyinflames/cmdarchetype","owner":"theskyinflames","description":"An archetype of command line tool using Cobra and Viper","archived":false,"fork":false,"pushed_at":"2019-03-14T07:07:53.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-05T17:11:52.417Z","etag":null,"topics":["archetype","cobra","command-line-tool","golang","golang-tools","theskyinflames","viper"],"latest_commit_sha":null,"homepage":null,"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/theskyinflames.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-03-08T20:55:35.000Z","updated_at":"2019-03-14T07:07:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1734db1-48c4-44e5-bf23-a6a1db1807cd","html_url":"https://github.com/theskyinflames/cmdarchetype","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/theskyinflames%2Fcmdarchetype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theskyinflames%2Fcmdarchetype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theskyinflames%2Fcmdarchetype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theskyinflames%2Fcmdarchetype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theskyinflames","download_url":"https://codeload.github.com/theskyinflames/cmdarchetype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240386530,"owners_count":19793193,"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":["archetype","cobra","command-line-tool","golang","golang-tools","theskyinflames","viper"],"created_at":"2024-11-09T21:25:50.790Z","updated_at":"2025-02-23T22:21:25.914Z","avatar_url":"https://github.com/theskyinflames.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cmdarchetype\nThis is an example of archetype of command line tool using [cobra](https://github.com/spf13/cobra) and [viper](https://github.com/spf13/viper). The command parameters can be loaded from a file, specified inline, or a mix of the two options. \n\n## How it works\nThis is the sequence to set the parameters values:\n\n1. If a parameter value is specified in the command line, this value will be taken\n2. If a config file is specified, and it contais a value for the parameter, it will be taken\n3. Otherwise, if a default value for the parameter has been set, it will be taken\n\nThere is a config file as example:\n```yalm\ndo-async: false\nsource-data: https://data.safe.net:443\nresult-receivers: \n  - receiver1\n  - receiver2\n  - receiver3\ndb-connection-params:\n  user: myuser\n  password: mypassword\n  db-url: https://db.safe.net:443\n```\n\n## Environment used to build this archetype\n* Go: go1.11.5 linux/amd64\n* Make: GNU Make 4.2.1\n\n## Execute the command\nAs I've said above, if a config file is specified, its parameters will be loaded. In adition, we can specify some different value for a given paraemter:\n```sh\n❯ go run main.go -c=./example-config.yml --do-async=true --db-url=myDB\n```\n\nWith the above showed config file, this is the config loaded:\n```sh\nINFO[0000] loading config from [./example-config.yml] file \nINFO[0000] loaded config: (*config.Config)(0xc000098900)({\n SourceData: (string) (len=25) \"https://data.safe.net:443\",\n ResultReceivers: ([]string) (len=3 cap=3) {\n  (string) (len=9) \"receiver1\",\n  (string) (len=9) \"receiver2\",\n  (string) (len=9) \"receiver3\"\n },\n DBConnectionParams: (config.DBConnectionParams) {\n  User: (string) (len=6) \"myuser\",\n  Password: (string) (len=10) \"mypassword\",\n  DBURL: (string) (len=4) \"myDB\"\n },\n DoAsynchronously: (bool) true\n})\n \nINFO[0000] starting the command at 2019-03-11 20:30:14.50096253 +0100 CET m=+0.001722683 \nINFO[0001] Action done sucessfully !!!, in 1.000157953s \n  \n```\n\nAs you can see, in the config file, the parameter *db-url* value is *https://db.safe.net:443*, but executing the tool on this way, I've forced the value for this parameter to *myDB*\n\nOf course, passing a config file is not mandatory. I such case, you'll have to pass all of parameters by command line. Otherwise, the default values will be taken.\n\nEnjoy it !!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheskyinflames%2Fcmdarchetype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheskyinflames%2Fcmdarchetype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheskyinflames%2Fcmdarchetype/lists"}