(
Hello everybody,
i’d like to present an new tool,
it’s created with progressive disclosure of complexity in mind,
so that everybody can get going as needed ![]()
There is nothing new to learn, to use it ![]()
It builds on what we already know for programming in mojo,
and map that to an C.L.I app !
Frankly, i hope many people find it useful,
because this got built for you all.
The approach is unusual,
the goal was to make it very seamless,
and as easy to use as possible ![]()
(no imports, no “here are the commands”, ..)
cli_structs: a personal CLI toolkit builder 
Folders and Mojo structs become a command line program.
@fieldwise_init
struct AddNumbers:
"""[App.Command].
Adds two numbers.
"""
var A: Int
"""The first number."""
var B: Int
"""The second number."""
def Do(self) raises -> String:
return String(self.A + self.B)
$ ./app MyTools.Math.AddNumbers --A 1 --B 2
3
$ ./app MyTools.Math.AddNumbers --help
MyTools.Math.AddNumbers
Adds two numbers.
--A Int The first number.
--B Int The second number.
$ ./app
example
The example app: commands to try cli_structs with.
+ Items Items: one command with every kind of argument.
+ MyTools MyTools: small tools, grouped in a package.
More: <name> --help
folders and files are scopes
structs are commands
fields are arguments
docstrings are the help
Nothing to import, no main to write.
A command can also print as it goes,
with a Writer.
It is early and small:
one Python file that reads mojo doc json output and writes plain Mojo.
Tested with Mojo 1.2.0, on macOS.
Feedback is very welcome, especially:
does it work on Linux ?
Btw, it works with sub-folders,
so that the cli too uses the tree, which is an toolkit !
(Many commands neatly organized)
It also have an Writer Do to print as it goes.
(instead of an returning result Do)