beef331 / website

Code for the official Nim programming language website
https://nim-lang.org
19 stars 1 forks source link

This month with Nim: Climate #78

Closed moigagoo closed 1 year ago

moigagoo commented 1 year ago

Name: Climate

Author: moigagoo

Posting:

There are several CLI libs for Nim. However, when I was choosing the one to use for my Sauer package, I found out that the existing ones were either quite complex or too low-level. I wanted a package that would allow me to think with commands and subcommands instead of parsers, while still not use a ton of macros.

Working on Kraut, I was surprised with how productive its approach to routing turned out to be and I decided to apply it to CLI. And this is how Climate was born.

Climate is like a router but for command line. You define your commands and subcommands like paths and define handlers for them:

let commands = {"command subcommand": handlerProc}

Options and arguments extracted from the command line are passed inside a Context instance.

I can see how Climate could evolve from here, adding argument validation, type casting, and help generation but it's worth noting that it's already quite handy as it is.

See the docs and a full demo in the repo: https://github.com/moigagoo/climate