Introducing oosh: The Annotation-Driven CLI Framework for Bash
Oosh is a revolutionary new framework for building command-line interfaces (CLIs) in Bash. It's designed to make your life easier, with features like auto-generated help text, tab completion, and flag parsing built right into the shell. In this article, we'll dive into the world of oosh and explore its many benefits.
At its core, oosh is an annotation-driven framework, which means you write annotations in your Bash code to describe your functions and flags. This allows oosh to automatically generate help text, tab completion suggestions, and flag parsing logic for you. With oosh, you can focus on building your CLI without having to worry about tedious boilerplate code.
One of the standout features of oosh is its performance. According to the authors, oosh generates a 6-17ms overhead compared to manual flag parsing in Bash, with Linux performing slightly better than macOS. This means that oosh can handle complex CLIs quickly and efficiently, without sacrificing any performance.
But what exactly does oosh look like? Let's take a closer look at its features.
### Help Text
When you create an oosh project, you'll need to add a `main.sh` file as the entry point. This file serves as the main CLI entry point, and it's where you define your functions and flags. With oosh, you can automatically generate help text for each function by adding annotations to your code.
For example, if you have a function like this: ```bash #!/bin/bash
function my_function { # Some code here... } ``` You can add an annotation like this to generate help text: ```bash #!/bin/bash
function my_function { #@description="My function description" # Some code here... } ``` This will automatically generate a help entry for `my_function` with the description "My function description".
### Tab Completion
Tab completion is another key feature of oosh. With oosh, you can enable tab completion for your CLI by adding annotations to your flags.
For example, if you have a flag like this: ```bash #!/bin/bash
function my_function { #@flag required number # Some code here... } ``` When you run `my_function --number`, oosh will automatically suggest the possible values for the `--number` flag. This makes it easy to complete your commands and avoid typos.
### Modules
Oosh also introduces a new concept called "modules". A module is essentially a separate file that contains a set of related functions and flags. With oosh, you can create modules by adding a `.sh` file to the `modules/` directory.
When you add a module to your project, oosh will automatically discover it and make its contents available as part of your CLI. This makes it easy to organize your codebase and keep your CLIs modular and maintainable.
### Colors
Oosh also comes with support for colors in its output. By default, oosh uses green for successful commands, yellow for warnings, and red for errors. You can customize the colors using environment variables or by adding custom color definitions to your `main.sh` file.
### Generator
The oosh generator is a powerful tool that allows you to create new CLIs quickly and easily. With the generator, you can scaffold entire CLIs in just a few minutes.
To use the generator, simply run it with the following command: ```bash oosh init mycli ``` This will create a new `mycli` project directory containing all the files and directories you need to get started with your new CLI.
### Performance
One of the standout features of oosh is its performance. According to the authors, oosh generates a 6-17ms overhead compared to manual flag parsing in Bash, with Linux performing slightly better than macOS.
This means that oosh can handle complex CLIs quickly and efficiently, without sacrificing any performance.
### Conclusion
Oosh is a game-changing framework for building command-line interfaces (CLIs) in Bash. With its annotation-driven approach, tab completion, and flag parsing built right into the shell, oosh makes it easy to build robust and maintainable CLIs with minimal effort.
Whether you're building a new CLI from scratch or looking to migrate an existing one to oosh, this framework is definitely worth exploring. Its performance, flexibility, and ease of use make it an ideal choice for developers looking to build fast and efficient CLIs.
So what are you waiting for? Give oosh a try today and see the difference it can make in your CLI development workflow!