#derive #proc-macro #dialoguer #prompt #dialog #dialoguer-trait

macro dialoguer_macro

Derive macro based on Dialoguer crate. To use only with 'dialoguer_trait'

3 unstable releases

0.2.0 Jul 14, 2021
0.1.2 Jul 14, 2021
0.1.1 Jul 14, 2021

#7 in #dialoguer

Download history 8/week @ 2024-02-17 9/week @ 2024-02-24 2/week @ 2024-03-02 8/week @ 2024-03-09 1/week @ 2024-03-16 49/week @ 2024-03-30 12/week @ 2024-04-06 1/week @ 2024-04-20

62 downloads per month
Used in dialoguer_trait

Custom license

175 lines

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.


Add dialoguer_trait to your Cargo.toml:

dialoguer_trait = "0.2.0" 

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

use dialoguer_trait::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.


~34K SLoC