Open IniterWorker opened 2 years ago
That is a very good idea.
In my opinion this should be a separate package that builds prompts via the public API only. What do you think?
Also, would this be something you'd be willing to implement?
Finally, I love the idea.
The pros of integrating it into the same lib, it's easier for the final user to use it. And, it's a handy feature to be ignored by a developer. It could stream a lot of things very quickly in a cli design. What do you think about it?
After thought is very nice to have a default value from the current in-memory structure data versus the Default::default.
PS: the holiday keeps me busy :-)
Hi @mikaelmello,
Hope you're doing well,
I started a new crate to work on inquire's proc-macro derive, and I'd like your advise.
pub trait InquireInvoke {
fn inquire() -> InquireResult<()>;
}
pub enum FieldType {
Text {
prompt_message: Option<String>,
help_message: Option<String>,
default_value: Option<String>,
initial_value: Option<String>,
placeholder_value: Option<String>,
validators: Option<Vec<String>>,
formatter: Option<String>,
suggester: Option<String>,
autocompleter: Option<String>,
},
// ...
}
What do you think about both approaches?
#[derive(InquireInvoke)
pub struct MyStruct {
#[inquire(field = "text", prompt_message = "What is your name?", default_value = "IniterWorker")]
name: String,
}
#[derive(InquireInvoke)
pub struct MyStruct {
#[inquire(text(prompt_message = "What is your name?", default_value = "IniterWorker"))]
name: String,
}
Finally, I implemented the inner approach. It seems the way to go after a lot of brainstorming in my head.
I started an experimental repository/playground. It is not perfect and not finished yet. But you might have an opinion on the proc-macro flow and testing the inquire::Text
.
Experimental/Demo - inquire_derive
Thank you,
That is so so awesome. Honestly I don't feel like I'm currently able to contribute a lot, never dove too deep on the proc-macro side of Rust although I always wanted to.
I skimmed through the repo and overall felt like everything was in place, but again I don't know much about it so I wouldn't be able to differentiate lol
My (irrelevant for now) suggestions would be to ask what you think about InquireForm
as the trait name to be derived, feels more like the end product for me.
Next weekend I'll try to dive deeper on your repo to try and have some actual suggestions/contributions on it.
And again, this is awesome.
My (irrelevant for now) suggestions would be to ask what you think about InquireForm as the trait name to be derived, feels more like the end product for me.
Done!
During the implementation of inquire_derive
two main subjects popped up:
impl ToInquire for T
)inquire
and inquire_derive
? Or do you prefer to keep things separated?
cargo workspace
on your side?Sorry for the delay! Completely lost the notification email after reading it.
Regarding merging both, I'd be more than glad to merge if that's something you're looking forward to. I'll be honest in that I haven't dedicated as much time as I wanted to inquire, so I also don't want to be a blocker for you (as I have kinda been...). Would you prefer to keep things separate? Or maybe merging and becoming a maintainer here as well?
Regarding the design questions, I'm still gonna take a dive on your repo and be able to have an opinion
No worries about it. I want to find the best way to land in your repository. Should we rework it as a workspace like serde
's crate? inquire_derive
is setup likewise.
Regarding the design questions, I'm still gonna take a dive on your repo and be able to have an opinion
It would be great! You will find out one main change from your last dive:
Parametrics macro variables are now Expr
to mitigate the issue with a no-context approach and allow custom code. But, macro's Expr
downside is that static strs are escaped.
Thanks,
Yes, let's rework it as a workspace! I'll put it in the (small amount needed of) work tomorrow.
Created: https://github.com/mikaelmello/inquire/pull/87
Want to take a look? I think that's all there is to it, so it's just a matter of porting it to this repo I think
Hi @mikaelmello, https://github.com/mikaelmello/inquire/commit/aafad1767dab24d34733a4e81317f84cc2fa6dd2 is our starting point.
inquire-derive
:unwrap
calls that provide poor error output.serde
derive, because of a missing inquire
/default
trait.inquire-derive
to generate user-friendly compiler errors.inquire
crate's trait strategyShould we create a trait for all primitives that will be implemented enough to be used in inquire-derive to generate a default inquire prompt?
inquire
#[derive(Debug, InquireForm)]
pub struct TestStruct {
#[inquire(editor(prompt_message = "\"What's your text?\"",))]
pub text: String,
}
inquire
#[derive(Debug, InquireForm)]
pub struct TestStruct {
pub text: String,
}
Should we create a trait for all primitives that will be implemented enough to be used in inquire-derive to generate a default inquire prompt?
Providing plug-n-go features is certainly my goal, so it is a direction that makes sense to me.
Hey there @mikaelmello @IniterWorker ! was reading through these issues and found this. I have a crate that is built on top of inquire and does exactly this, check it out! https://crates.io/crates/interactive-parse. It's still a very young project though is fully feature complete. It has the advantage of using a very popular preexisting derive, so you're much more likely to be able to use it with external types.
use inquire::AskUser;
#[derive(Debug, AskUser)]
struct MyConf {
#[ask(q="Please enter password:", hide_input=true, min_len=12)]
password: Option<String>,
#[ask(q="Please enter username:", min_len=3)]
username: Option<String>,
#[ask(q="Please enter age:", range=18..=85)]
age: Option<u8>,
}
fn main() -> Result<()> {
let mut conf = MyConf::default()
conf.password()?.validate()?;
conf.username()?.validate()?;
conf.age()?.validate()?;
println!("{conf#?}");
}
Copying over, this feature would be awesome!
Hi! Author of the preprocess crate here. Is there any way I can help with integrating the validation / preprocessing layer with the preprocess crate?
Feature Proposal
It can be time-consuming to maintain or create an interactive configurable struct. I have a proposal to leverage Rust's features to reduce maintenance and implementation.
Mainlines
Demo
Draft
Do you have any thoughts or derivative-features?