7 releases (breaking)
new 0.5.0 | Nov 4, 2024 |
---|---|
0.4.0 | Nov 4, 2024 |
0.3.0 | Nov 3, 2024 |
0.2.0 | Oct 26, 2024 |
0.0.0 | Oct 19, 2024 |
#310 in Development tools
676 downloads per month
20KB
106 lines
Chief
Chief Development Tools provides versatile functionalities for managing web applications. Depending on your requirements, you can choose between different installation methods. Whether you want to utilize the command-line interface (CLI) for seamless application management or integrate logging and environment variable handling into your project, Chief offers flexible options tailored to your development needs. This empowers developers to enhance their workflow and streamline application processes efficiently.
Table of Contents
- Features
- Changelog
- Getting Started
- Commands
- Chief CLI Function
- Usage Examples
- Logging
- Environment Variables
- License
- Contributing
- Author
Features
- CLI for Application Management: Easily run applications in development or production mode and execute tests.
- Integrated Logging: Utilize the
log
crate for logging at various levels and configure with thesimplelog
crate for easy setup. - Environment Variable Management: Access standard environment variables effortlessly.
Changelog
Getting Started
Installation for Running and Testing Only
If your primary focus is to run commands (such as run dev
, run prod
) and execute tests without needing to manage environment variables or logging, you can install Chief directly using:
cargo install chief
This command installs the CLI tool, enabling you to run your application and execute tests easily.
Installation for Logging and Environment Management
For developers who only need to manage environment variables and logging functionalities, you can add Chief as a dependency to your project without the CLI commands using:
To include Environment Variable Management and Dotenv:
cargo add chief
Or add chief
to your Cargo.toml
file:
[dependencies]
chief = "MAJOR.MINOR.PATCH" # Replace with the latest version
Building from Source
To build the Chief
Development Tools from source, follow these commands:
git clone https://github.com/dr-montasir/chief.git
cd chief
cargo build --release
Commands
The following subcommands are available in the CLI:
-
run
: Runs the application.run dev
: Runs the application in development mode.run prod
: Runs the application in production mode.
-
test
: Runs the tests for the application. -
build
: Compiles the application.build --release
: Compiles the application in release mode for optimized performance.
-
clean
: Cleans the target directory, removing all generated artifacts. -
help
: Print this message or the help of the given subcommand(s).
> chief -h
A CLI for managing web applications
Usage: chief [COMMAND]
Commands:
run Runs the application
test Runs the tests
build Builds the application
clean Cleans the project
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Chief CLI Function
The chief_cli
function serves as the core entry point for the Chief CLI application. It initializes the command-line interface and processes user commands efficiently. By encapsulating the command-handling logic, it allows developers to focus on building their applications without worrying about the underlying command processing mechanics. This function enhances the usability of the CLI, making it easier for developers to manage their applications through intuitive commands.
use chief::chief_cli;
fn main() {
let app_name = "example"; // Any project name can be here.
let app_version = "0.1.0";
chief_cli(app_name, app_version);
}
Usage Examples
To run the application in development mode:
chief run dev
To run the application in production mode:
chief run prod
To execute tests:
chief test
Logging
Chief Development Tools uses the log
crate to facilitate logging functionalities. You can set up logging simply in your main application:
use chief::log::{info, warn, error};
use chief::simplelog::{Config, LevelFilter, SimpleLogger};
fn main() {
// Initialize the SimpleLogger
SimpleLogger::init(LevelFilter::Info, Config::default()).unwrap();
info!("This is an info message.");
warn!("This is a warning message.");
error!("This is an error message.");
}
Environment Variables
Accessing environment variables in your application can be done using the chief::{dotenv, env}
modules. Here is a simple way to get an environment variable:
# .env file
MY_ENV_VARIABLE=my_variable
use chief::{dotenv, env};
fn main() {
dotenv().ok();
if let Ok(value) = env::var("MY_ENV_VARIABLE") {
println!("My environment variable is: {}", value);
} else {
println!("Environment variable not set.");
}
}
// Output:
// My environment variable is: my_variable
License
This project is licensed under either of the following licenses:
- MIT License
- Apache License, Version 2.0
You may choose either license for your purposes.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any feature requests or bug reports.
Author
Dependencies
~2–9MB
~85K SLoC