From b7c24559aa2758820039295ac0f6120dfdec550e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 15 Feb 2024 10:16:00 +0000 Subject: fix: allow optional description and web also add a default web --- src/cli_interactor.rs | 12 ++++++++++++ src/sub_commands/init.rs | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cli_interactor.rs b/src/cli_interactor.rs index c6cd4e5..693e9fd 100644 --- a/src/cli_interactor.rs +++ b/src/cli_interactor.rs @@ -19,6 +19,8 @@ impl InteractorPrompt for Interactor { fn input(&self, parms: PromptInputParms) -> Result { let input: String = Input::with_theme(&self.theme) .with_prompt(parms.prompt) + .default(parms.default) + .allow_empty(parms.optional) .interact_text()?; Ok(input) } @@ -51,6 +53,8 @@ impl InteractorPrompt for Interactor { #[derive(Default)] pub struct PromptInputParms { pub prompt: String, + pub default: String, + pub optional: bool, } impl PromptInputParms { @@ -58,6 +62,14 @@ impl PromptInputParms { self.prompt = prompt.into(); self } + pub fn with_default>(mut self, default: S) -> Self { + self.default = default.into(); + self + } + pub fn optional(mut self) -> Self { + self.optional = true; + self + } } #[derive(Default)] diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 9fdcca5..3a0ff55 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -43,6 +43,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let repo_config_result = get_repo_config_from_yaml(&git_repo); // TODO: check for other claims + let identifier = root_commit.to_string()[..7].to_string(); + let name = match &args.title { Some(t) => t.clone(), None => Interactor::default().input(PromptInputParms::default().with_prompt("name"))?, @@ -50,8 +52,9 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let description = match &args.description { Some(t) => t.clone(), - None => Interactor::default() - .input(PromptInputParms::default().with_prompt("description (Optional)"))?, + None => { + Interactor::default().input(PromptInputParms::default().with_prompt("description"))? + } }; let git_server = git_repo @@ -63,7 +66,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let web: Vec = if args.web.is_empty() { Interactor::default() - .input(PromptInputParms::default().with_prompt("description (Optional)"))? + .input( + PromptInputParms::default() + .with_prompt("web") + .optional() + .with_default(format!("https://gitworkshop.dev/repo/{}", &identifier)), + )? .split(' ') .map(std::string::ToString::to_string) .collect() @@ -118,7 +126,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { println!("publishing repostory reference..."); let repo_event = RepoRef { - identifier: root_commit.to_string()[..7].to_string(), + identifier, name, description, root_commit: root_commit.to_string(), -- cgit v1.2.3