refactor(xtask): migrate bootstrap script to xtask subcommand#8
refactor(xtask): migrate bootstrap script to xtask subcommand#8
Conversation
|
@tisonkun |
…rust implementation
8c41a91 to
191eec0
Compare
| mod colors { | ||
| pub const RED: &str = "\x1b[31m"; | ||
| pub const GREEN: &str = "\x1b[32m"; | ||
| pub const YELLOW: &str = "\x1b[33m"; | ||
| pub const BLUE: &str = "\x1b[34m"; | ||
| pub const RESET: &str = "\x1b[0m"; | ||
| } |
There was a problem hiding this comment.
Rust ecosystem has a colored crate for generating colored string. You can add it to xtask's dependency and make use of it.
There was a problem hiding this comment.
dialoguer recommends https://github.com/console-rs/console. I don't distinguish them too much. You can read them by yourself and make the decision.
| if !Path::new("Cargo.toml").exists() || !Path::new("xtask").is_dir() { | ||
| return Err("This command must be run from the project root directory".into()); | ||
| } |
There was a problem hiding this comment.
I suppose we can resolve the path with a technique like:
- https://github.com/scopedb/percas/blob/d01db13b/xtask/src/main.rs#L22
- https://github.com/scopedb/percas/blob/d01db13b/.cargo/config.toml#L18-L19
Then we don't need this assumption.
| fn prompt_input(prompt: &str) -> String { | ||
| print!("{}: ", prompt); | ||
| stdout().flush().unwrap(); | ||
| let mut input = String::new(); | ||
| stdin().read_line(&mut input).unwrap(); | ||
| input.trim().to_owned() | ||
| } |
There was a problem hiding this comment.
For prompt interaction, you can make use of https://github.com/console-rs/dialoguer. It should simplify many code here.
There was a problem hiding this comment.
Thanks for your contribution! Comments inline. I think many existing crates can help here.
Also, after bootstrap, the related code should be able to be deleted safely (they are useless now anyway). So I suggest either move the code to a standalone file for easy deletion, or the command itself can detect if the bootstrap is finished, then delete all the related code from itself.
Never mind. Enjoy your days :D Comments above and thanks a lot for spending your time on contribution! |
@tisonkun Thanks for the suggestions, I initially hesitated to add dependencies for this subcommand, but you're right, those crates would be very helpful! Regarding cleanup: I prefer moving all bootstrap-related code to a standalone file (e.g.,
which one makes more sense to you? or is there any better way to handle this? Happy to hear your thoughs :) |
|
@gomnitrix I think we can first leave the deletion to the user. Just keep all the bootstrap setup/code as gathered as possible. So users would be easy to delete by themselves. Later we can figure out whether it's possible to delete automatically. Typically, automation is doing something you will do manually by the machine :D |
Summary
Replaces
rename-project.shwith a native rust implementation (cargo xtask bootstrap), supporting both CLI arguments and interactive mode.Usage
CLI mode:
Interactive mode: