Wena was created by Nuno Maduro, and is a Rust Lang micro-framework that provides an elegant starting point for your console application.
This project is a work-in-progress. Code and documentation are currently under development and are subject to change.
Get Started
Requires Rust 1.61.0
First, install a recent release of Rust via the rustup:
Next, create a new binary-based Cargo project:
Once the project is created, add wena as dependency in your Cargo.yml:
[]
= "0.2.0"
After, modify your src/main.rs file, and create your CLI application:
use *;
Finally, compile and run the with cargo run.
cargo run -q --
Application
As you may have noticed, Wena applications may be created using the struct Application that gets exported at the root level of the crate wena. And, the new static method allows you to create an instance of the struct Application:
use Application;
let app = new;
The struct Application represents a command-line application, and as such, it contains a name, description, version, list of commands, an input implementation, and an output implementation.
You may run the application at any time using the method run():
use Application;
let app = new
.run;
Description
Having a description is not required. You can optionally define a description using the description() method:
use Application
let app = new
.description;
Version
By default, the application version is 1.0.0. You can optionally define a version using the version() method:
use Application
let app = new
.version;
Commands
You may run your application without any arguments to view all available commands in the application. Commands are defined using the commands method:
use ;
let app = new
.commands;
Command handler
The command's handle() method receives a closure that contains the logic you want the command to execute.
use Command
let command = new
.handler;
The closure's first argument is an Application instance. As such, you have access to the application's Input and Output at any time in your command's code:
use Command
let command = new
.handler;
In addition, the given handler should return a result with an i32 exit status. Keep in mind, that the given exit status is used internally by the framework the exit the current process.
Command input
The command's input may be defined using the command's definition method:
use ;
let command = new
.definition;
When defined, input arguments may be accessed using the method argument in your command's code:
use ;
let command = new
.definition.handler;
The trait Input is required when using methods of the struct Input.
Command output
When necessary, you may write messages to the console using the command's output write or writeln methods:
use ;
let command = new
.handler;
The trait Output is required when using methods of the struct Output.
Colors and combinatorial style
Wena lets you apply different styles to any String given to command's output methods. As such, when importing colored::*;, you may change the font color, background color, and combinatorial style such as bold, italics, dimmed, etc:
use *;
app.output.writeln;
Components
Wena gives you access the beautifully designed output components that give you everything you need to build CLI applications.
Alert
Alerts provide contextual feedback messages for typical user actions.
use ;
let command = new
.handler
Utilities
Wena offers you several utilities that you may use to customize the nitty-gritty of your CLI application.
Terminal
The Terminal struct gives you access to multiple aspects of the user's terminal:
use Terminal;
let terminal = default;
// Computes the user's terminal width...
let width = terminal.width;
License
Wena is an open-source software licensed under the MIT license.