{"id":26844948,"url":"https://github.com/moigagoo/climate","last_synced_at":"2025-04-30T20:23:40.924Z","repository":{"id":148261300,"uuid":"607868146","full_name":"moigagoo/climate","owner":"moigagoo","description":"Library to build command-line interfaces.","archived":false,"fork":false,"pushed_at":"2025-02-04T11:34:51.000Z","size":142,"stargazers_count":41,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-25T16:00:17.925Z","etag":null,"topics":["cli","nim"],"latest_commit_sha":null,"homepage":"https://moigagoo.github.io/climate/theindex.html","language":"Nim","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/moigagoo.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","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":"2023-02-28T20:54:01.000Z","updated_at":"2025-03-26T19:00:59.000Z","dependencies_parsed_at":"2025-02-04T12:34:52.492Z","dependency_job_id":null,"html_url":"https://github.com/moigagoo/climate","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fclimate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fclimate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fclimate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fclimate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moigagoo","download_url":"https://codeload.github.com/moigagoo/climate/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251775730,"owners_count":21641872,"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":["cli","nim"],"created_at":"2025-03-30T19:33:49.179Z","updated_at":"2025-04-30T20:23:40.905Z","avatar_url":"https://github.com/moigagoo.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Climate\n\n**Climate** is a library to create CLIs. It's your CLI mate 😜\n\nIt allows you to think in high-level abstractions like commands and subcommands instead of parsers and tokens.\n\n[API docs index →](https://moigagoo.github.io/climate/theindex.html)\n\n\n# Installation\n\nInstall Climate with Nimble:\n\n```\n$ nimble install -y climate\n```\n\nor add it to your .nimble file:\n\n```nim\nrequires \"climate\"\n```\n\n\n# Usage\n\nTo create CLIs with Climate, you need to learn only three terms: **route**, **handler**, and **context**.\n\n\n## Route\n\n**Route** is a unique sequence of words that correspond to a CLI command. For example, in git-flow, ``flow release start`` is a route.\n\n\n## Handler\n\n**Handler** is a Nim proc invoked when the command is called by the user. It accepts a ``Context`` object and returns an ``int``.\n\n\n## Context\n\n**Context** is an object that holds the values for the arguments and options from the command line.\n\nContext has a ``cmdArguments`` sequence and ``cmdOptions`` table.\n\n\n# Example\n\nHere's a fake git implemented with Climate:\n\n1. Define routes:\n```nim\n# git.nim\nimport climate\n\nimport commands/flow\nimport commands/flow/release\n\n\nconst commands = {\n  \"flow init\": flow.init,\n  \"flow release start\": release.start,\n  \"flow release finish\": release.finish\n}\n```\n\n2. Define handlers:\n\n```nim\n# commands/flow.nim\nimport climate/context\n\n\nproc init*(context: Context): int =\n  stdout.write \"Initializing Git flow...\"\n\n  if context.cmdOptions.hasKey(\"d\") or context.cmdOptions.hasKey(\"default\"):\n    stdout.write \"using default settings...\"\n\n  echo \"done!\"\n```\n\n3. Parse the command line by calling ``parseCommands``:\n\n```nim\n# git.nim\nquit parseCommands(commands)\n```\n\nSee the complete example in ``demo`` folder.\n\n\n# Sugar\n\nTo make it easier to work with arguments and options, Climate offers `arg(Context)`, `args(Context)`, and `opt(Context)` templates in `climate/sugar` module.\n\n\n## `arg`\n\n`arg` checks that the command has been invoked with exactly one argument and captures its value; if the command was invoked with zero or more than one arguments, the fallback code is executed:\n\n```nim\nproc start*(context: Context): int =\n  context.arg:\n    stdout.write fmt\"Starting release {arg}...\"\n    echo \"done!\"\n  do:\n    echo \"Release name is mandatory\"\n    return 1\n```\n\n\n## `args`\n\n`args` checks that the command has been invoked with at least one argument and captures the values of the passed arguments; if the command was invoked with no arguments, the fallback code is executed:\n\n```nim\nproc add*(context: Context): int =\n  context.args:\n    for filename in args:\n      echo \"Adding \" \u0026 filename\n  do:\n    echo \"No filename provided\"\n    return 1\n```\n\n\n## `opt`\n\n`opt` checks if the command has been invoked with a certain option defined by its short or long name and captures its value:\n\n```nim\nproc root*(context: Context): int =\n  context.opt \"version\", \"\":\n    echo \"Version 1.0.0\"\n\n  context.opt \"help\", \"h\":\n    echo \"Usage: ...\"\n```\n\n\n## `flag`\n\n`flag` checks if the command has been invoked with a certain flag, i.e. an option without a value, defined by its short or long name:\n\n```nim\nproc root*(context: Context): int =\n  context.opt \"version\", \"\":\n    echo \"Version 1.0.0\"\n\n  context.opt \"help\", \"h\":\n    echo \"Usage: ...\"\n```\n\n\n\n## Supersugar\n\nTo make it even sweeter, use `std/with`:\n\n```nim\nproc root*(context: Context): int =\n  echo \"Welcome to FakeGit!\"\n\n  with context:\n    opt \"version\", \"\":\n      echo \"Version 1.0.0\"\n\n    opt \"help\", \"h\":\n      echo \"Usage: ...\"\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fclimate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoigagoo%2Fclimate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fclimate/lists"}