diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-15 10:16:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-15 10:16:00 +0000 |
| commit | b7c24559aa2758820039295ac0f6120dfdec550e (patch) | |
| tree | 9d5fa8e1ea96bea6757232a9beea3e9add493ed3 | |
| parent | 6a4519b79cd36d1edbb492a3c98e2a3a0b42e0e9 (diff) | |
fix: allow optional description and web
also add a default web
| -rw-r--r-- | src/cli_interactor.rs | 12 | ||||
| -rw-r--r-- | src/sub_commands/init.rs | 16 |
2 files changed, 24 insertions, 4 deletions
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 { | |||
| 19 | fn input(&self, parms: PromptInputParms) -> Result<String> { | 19 | fn input(&self, parms: PromptInputParms) -> Result<String> { |
| 20 | let input: String = Input::with_theme(&self.theme) | 20 | let input: String = Input::with_theme(&self.theme) |
| 21 | .with_prompt(parms.prompt) | 21 | .with_prompt(parms.prompt) |
| 22 | .default(parms.default) | ||
| 23 | .allow_empty(parms.optional) | ||
| 22 | .interact_text()?; | 24 | .interact_text()?; |
| 23 | Ok(input) | 25 | Ok(input) |
| 24 | } | 26 | } |
| @@ -51,6 +53,8 @@ impl InteractorPrompt for Interactor { | |||
| 51 | #[derive(Default)] | 53 | #[derive(Default)] |
| 52 | pub struct PromptInputParms { | 54 | pub struct PromptInputParms { |
| 53 | pub prompt: String, | 55 | pub prompt: String, |
| 56 | pub default: String, | ||
| 57 | pub optional: bool, | ||
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | impl PromptInputParms { | 60 | impl PromptInputParms { |
| @@ -58,6 +62,14 @@ impl PromptInputParms { | |||
| 58 | self.prompt = prompt.into(); | 62 | self.prompt = prompt.into(); |
| 59 | self | 63 | self |
| 60 | } | 64 | } |
| 65 | pub fn with_default<S: Into<String>>(mut self, default: S) -> Self { | ||
| 66 | self.default = default.into(); | ||
| 67 | self | ||
| 68 | } | ||
| 69 | pub fn optional(mut self) -> Self { | ||
| 70 | self.optional = true; | ||
| 71 | self | ||
| 72 | } | ||
| 61 | } | 73 | } |
| 62 | 74 | ||
| 63 | #[derive(Default)] | 75 | #[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<()> { | |||
| 43 | let repo_config_result = get_repo_config_from_yaml(&git_repo); | 43 | let repo_config_result = get_repo_config_from_yaml(&git_repo); |
| 44 | // TODO: check for other claims | 44 | // TODO: check for other claims |
| 45 | 45 | ||
| 46 | let identifier = root_commit.to_string()[..7].to_string(); | ||
| 47 | |||
| 46 | let name = match &args.title { | 48 | let name = match &args.title { |
| 47 | Some(t) => t.clone(), | 49 | Some(t) => t.clone(), |
| 48 | None => Interactor::default().input(PromptInputParms::default().with_prompt("name"))?, | 50 | None => Interactor::default().input(PromptInputParms::default().with_prompt("name"))?, |
| @@ -50,8 +52,9 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 50 | 52 | ||
| 51 | let description = match &args.description { | 53 | let description = match &args.description { |
| 52 | Some(t) => t.clone(), | 54 | Some(t) => t.clone(), |
| 53 | None => Interactor::default() | 55 | None => { |
| 54 | .input(PromptInputParms::default().with_prompt("description (Optional)"))?, | 56 | Interactor::default().input(PromptInputParms::default().with_prompt("description"))? |
| 57 | } | ||
| 55 | }; | 58 | }; |
| 56 | 59 | ||
| 57 | let git_server = git_repo | 60 | let git_server = git_repo |
| @@ -63,7 +66,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 63 | 66 | ||
| 64 | let web: Vec<String> = if args.web.is_empty() { | 67 | let web: Vec<String> = if args.web.is_empty() { |
| 65 | Interactor::default() | 68 | Interactor::default() |
| 66 | .input(PromptInputParms::default().with_prompt("description (Optional)"))? | 69 | .input( |
| 70 | PromptInputParms::default() | ||
| 71 | .with_prompt("web") | ||
| 72 | .optional() | ||
| 73 | .with_default(format!("https://gitworkshop.dev/repo/{}", &identifier)), | ||
| 74 | )? | ||
| 67 | .split(' ') | 75 | .split(' ') |
| 68 | .map(std::string::ToString::to_string) | 76 | .map(std::string::ToString::to_string) |
| 69 | .collect() | 77 | .collect() |
| @@ -118,7 +126,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 118 | println!("publishing repostory reference..."); | 126 | println!("publishing repostory reference..."); |
| 119 | 127 | ||
| 120 | let repo_event = RepoRef { | 128 | let repo_event = RepoRef { |
| 121 | identifier: root_commit.to_string()[..7].to_string(), | 129 | identifier, |
| 122 | name, | 130 | name, |
| 123 | description, | 131 | description, |
| 124 | root_commit: root_commit.to_string(), | 132 | root_commit: root_commit.to_string(), |