dialoguer_trait

Crates.iodialoguer_trait
lib.rsdialoguer_trait
version0.2.0
sourcesrc
created_at2020-11-18 23:17:24.024787
updated_at2021-07-14 22:00:37.97548
descriptionTrait helper (and derive macro) for constructing interactive message prompts using `dialoguer`
homepage
repositoryhttps://github.com/luke-biel/dialoguer_macro
max_upload_size
id313830
size17,454
luke-biel (luke-biel)

documentation

README

Dialoguer trait

It's simple wrapper trait over dialoguer crate. It's target is to remove necessity of providing explicit code when building interactive CLI apps. It comes with nifty derive macro, that turns (almost) any struct into command prompt configuration.

Usage

Add dialoguer_trait to your Cargo.toml:

[dependencies]
dialoguer_trait = "0.2.0" 

import trait to your namespace and derive it onto some struct:

use dialoguer_trait::Dialogue;

#[derive(Dialogue)]
struct Config {
    #[dialogue(prompt = "An option")]
    an_option: String,
    #[dialogue(prompt = "Please input a number")]
    number: isize,
    #[dialogue(prompt = "Are you having a good day?")]
    is_day_good: bool,
}

and then all you need to do is compose your struct:

let config = Config::compose("Give me config... please!").unwrap();

Notes to end user

Project is pretty much WIP.

You have to add #[dialoguer] attribute to EACH field in your structs, and they must have prompt set.
Deriving Dialogue on enum requires that its variants have EXACTLY ONE UNNAMED field.
Support for some types is still missing (eg. PathBuf, UUID, Uri).
No configuration of CLI that is generated is provided.
API can change at any point (I'm not fully sure about trait method name).

Help will be much appreciated.

Commit count: 7

cargo fmt