Skip to content

Commit

Permalink
Merge pull request #13 from codad5/env-test
Browse files Browse the repository at this point in the history
Init from toml fix
  • Loading branch information
codad5 authored Oct 14, 2024
2 parents 6451439 + 1612a38 commit 4cabf87
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# CHANGELOG

## 0.1.0
- Added new `init_from_toml` macro to allow initializing the app from a toml file
- `init_from_toml!` macro will read the toml file and initialize the app with the values
- Deprecated `init_from_toml` function
- `init_from_toml` function is deprecated and will be removed in the next major release

## 0.0.10
- Added auto version option to hrlp print version using `--version` or `-v`
## 0.0.9
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fli"
description = "The commander.js like CLI Parser for rust"
version = "0.0.10"
version = "0.1.0"
edition = "2021"
license = "MIT"
homepage = "https://github.com/codad5/fli"
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ For stable changes check the [CHANGELOG.md](https://github.com/codad5/fli/blob/m
For unstable changes check the [CHANGELOG.md](https://github.com/codad5/fli/blob/dev/CHANGELOG.md) file

```rust
use fli::Fli;
use fli::{Fli, init_from_toml};

fn main(){
let mut app : Fli = Fli::init_from_toml();
let mut app : Fli = init_from_toml!(); // using the toml file
app.option("-n --name, <>", "Name to call you", |x : &Fli| {});
app.option("-g --greet", "greeting", |x : &Fli| {
match x.get_values("name".to_owned() /* passing (--name, -n or n) would work*/){
Expand Down Expand Up @@ -58,7 +58,7 @@ fn main(){

```rust
fn main(){
let mut app = Fli::init_from_toml(); // to init from your cargo.toml file
let mut app = init_from_toml!(); // to init from your cargo.toml file
}

```
Expand All @@ -67,6 +67,7 @@ fn main(){
```rust
fn main(){
let mut app = Fli::init("app-name", "an app description");
app.set_version("0.0.1");
}
```

Expand All @@ -75,7 +76,7 @@ fn main(){

```rust
fn main(){
let mut app = Fli::init_from_toml();
let mut app = init_from_toml!();
app.option("-g --greet", "to make a greeting", greet);
app.option("-n --name, <>", "to set your name", |x|{});
}
Expand Down Expand Up @@ -103,7 +104,7 @@ fn main(){
You can also add a new command set using the command method
```rust
fn main(){
let mut app = Fli::init_from_toml();
let mut app = init_from_toml!();
app.command("greet", "An app that respects")
.default(greet)
.allow_inital_no_param_values(false)
Expand All @@ -128,7 +129,7 @@ use fli::Fli;

fn main(){
// doing it procedual way
let mut app = Fli::init_from_toml();
let mut app = init_from_toml!();
let moveCommand = app.command("move", "move files");
// the [...] means accept optional multiple
moveCommand.option("-p --path, <...>", "path to files to be moved", move_file);
Expand Down
2 changes: 1 addition & 1 deletion sample/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sample/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "sample"
description = "A sample project to demonstrate how to use fli"
version = "0.1.0"
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions sample/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fli::Fli;
use fli::{init_fli_from_toml, Fli};



Expand All @@ -16,7 +16,7 @@ use fli::Fli;


fn main(){
let mut app : Fli = Fli::init_from_toml();
let mut app : Fli = init_fli_from_toml!();
app.allow_inital_no_param_values(false);

let mut calc_app = app.command("calc", "perform basic 2 numeric calculation");
Expand Down
1 change: 1 addition & 0 deletions src/fli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Fli {
///
/// # Returns
/// * `Fli` - The Fli struct
#[deprecated]
pub fn init_from_toml() -> Self {
let name = env!("CARGO_PKG_NAME");
let description = env!("CARGO_PKG_DESCRIPTION");
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#[cfg(not(doctest))]
pub mod fli;
pub mod macros;

pub use fli::Fli;
use colored::Colorize;
Expand Down
12 changes: 12 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[macro_export]
macro_rules! init_fli_from_toml {
() => {{
let mut app = $crate::Fli::init(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_DESCRIPTION")
);
app.set_version(env!("CARGO_PKG_VERSION"));
app
}};
}

0 comments on commit 4cabf87

Please sign in to comment.