upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands/list.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-20 16:22:10 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-20 16:48:48 +0000
commit141ebf0cc0c6cfea640debc9b9073303509a8bc7 (patch)
tree579ef546ea83b13a56066e44c43318ad9ed4f3d0 /src/sub_commands/list.rs
parentc2817d081700d1fe14d92c51c4e89551182e7fb6 (diff)
feat(list): set checkout branch as default choice
instead of no default. note: I spent hours trying to get CliTester to support default choices and gave up. I have a stashed the attempt and am moving on...
Diffstat (limited to 'src/sub_commands/list.rs')
-rw-r--r--src/sub_commands/list.rs79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs
index 008872b..b556d5a 100644
--- a/src/sub_commands/list.rs
+++ b/src/sub_commands/list.rs
@@ -121,14 +121,16 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
121 121
122 if no_support_for_patches_as_branch { 122 if no_support_for_patches_as_branch {
123 println!("{patch_text_ref}"); 123 println!("{patch_text_ref}");
124 return match Interactor::default().choice(PromptChoiceParms::default().with_choices( 124 return match Interactor::default().choice(
125 vec![ 125 PromptChoiceParms::default()
126 "learn why 'patch only' proposals can't be checked out".to_string(), 126 .with_default(0)
127 format!("apply to current branch with `git am`"), 127 .with_choices(vec![
128 format!("download to ./patches"), 128 "learn why 'patch only' proposals can't be checked out".to_string(),
129 "back".to_string(), 129 format!("apply to current branch with `git am`"),
130 ], 130 format!("download to ./patches"),
131 ))? { 131 "back".to_string(),
132 ]),
133 )? {
132 0 => { 134 0 => {
133 println!("Some proposals are posted as 'patch only'\n"); 135 println!("Some proposals are posted as 'patch only'\n");
134 println!( 136 println!(
@@ -144,7 +146,9 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
144 "by default ngit posts proposals that support both the branch and patch model so either workflow can be used" 146 "by default ngit posts proposals that support both the branch and patch model so either workflow can be used"
145 ); 147 );
146 Interactor::default().choice( 148 Interactor::default().choice(
147 PromptChoiceParms::default().with_choices(vec!["back".to_string()]), 149 PromptChoiceParms::default()
150 .with_default(0)
151 .with_choices(vec!["back".to_string()]),
148 )?; 152 )?;
149 continue; 153 continue;
150 } 154 }
@@ -180,7 +184,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
180 if !git_repo.does_commit_exist(&proposal_base_commit.to_string())? { 184 if !git_repo.does_commit_exist(&proposal_base_commit.to_string())? {
181 println!("your '{main_branch_name}' branch may not be up-to-date."); 185 println!("your '{main_branch_name}' branch may not be up-to-date.");
182 println!("the proposal parent commit doesnt exist in your local repository."); 186 println!("the proposal parent commit doesnt exist in your local repository.");
183 return match Interactor::default().choice(PromptChoiceParms::default().with_choices( 187 return match Interactor::default().choice(PromptChoiceParms::default().with_default(0).with_choices(
184 vec![ 188 vec![
185 format!( 189 format!(
186 "manually run `git pull` on '{main_branch_name}' and select proposal again" 190 "manually run `git pull` on '{main_branch_name}' and select proposal again"
@@ -213,7 +217,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
213 // branch doesnt exist 217 // branch doesnt exist
214 if !branch_exists { 218 if !branch_exists {
215 return match Interactor::default() 219 return match Interactor::default()
216 .choice(PromptChoiceParms::default().with_choices(vec![ 220 .choice(PromptChoiceParms::default().with_default(0).with_choices(vec![
217 format!( 221 format!(
218 "create and checkout proposal branch ({} ahead {} behind '{main_branch_name}')", 222 "create and checkout proposal branch ({} ahead {} behind '{main_branch_name}')",
219 most_recent_proposal_patch_chain.len(), 223 most_recent_proposal_patch_chain.len(),
@@ -255,6 +259,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
255 println!("branch checked out and up-to-date"); 259 println!("branch checked out and up-to-date");
256 return match Interactor::default().choice( 260 return match Interactor::default().choice(
257 PromptChoiceParms::default() 261 PromptChoiceParms::default()
262 .with_default(0)
258 .with_choices(vec!["exit".to_string(), "back".to_string()]), 263 .with_choices(vec!["exit".to_string(), "back".to_string()]),
259 )? { 264 )? {
260 0 => Ok(()), 265 0 => Ok(()),
@@ -265,18 +270,20 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
265 }; 270 };
266 } 271 }
267 272
268 return match Interactor::default().choice(PromptChoiceParms::default().with_choices( 273 return match Interactor::default().choice(
269 vec![ 274 PromptChoiceParms::default()
270 format!( 275 .with_default(0)
271 "checkout proposal branch ({} ahead {} behind '{main_branch_name}')", 276 .with_choices(vec![
272 most_recent_proposal_patch_chain.len(), 277 format!(
273 proposal_behind_main.len(), 278 "checkout proposal branch ({} ahead {} behind '{main_branch_name}')",
274 ), 279 most_recent_proposal_patch_chain.len(),
275 format!("apply to current branch with `git am`"), 280 proposal_behind_main.len(),
276 format!("download to ./patches"), 281 ),
277 "back".to_string(), 282 format!("apply to current branch with `git am`"),
278 ], 283 format!("download to ./patches"),
279 ))? { 284 "back".to_string(),
285 ]),
286 )? {
280 0 => { 287 0 => {
281 check_clean(&git_repo)?; 288 check_clean(&git_repo)?;
282 git_repo.checkout(&cover_letter.branch_name)?; 289 git_repo.checkout(&cover_letter.branch_name)?;
@@ -304,14 +311,16 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
304 .unwrap_or_default() 311 .unwrap_or_default()
305 .eq(&local_branch_tip.to_string()) 312 .eq(&local_branch_tip.to_string())
306 }) { 313 }) {
307 return match Interactor::default().choice(PromptChoiceParms::default().with_choices( 314 return match Interactor::default().choice(
308 vec![ 315 PromptChoiceParms::default()
309 format!("checkout proposal branch and apply {} appendments", &index,), 316 .with_default(0)
310 format!("apply to current branch with `git am`"), 317 .with_choices(vec![
311 format!("download to ./patches"), 318 format!("checkout proposal branch and apply {} appendments", &index,),
312 "back".to_string(), 319 format!("apply to current branch with `git am`"),
313 ], 320 format!("download to ./patches"),
314 ))? { 321 "back".to_string(),
322 ]),
323 )? {
315 0 => { 324 0 => {
316 check_clean(&git_repo)?; 325 check_clean(&git_repo)?;
317 git_repo.checkout(&cover_letter.branch_name)?; 326 git_repo.checkout(&cover_letter.branch_name)?;
@@ -346,7 +355,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
346 .eq(&local_branch_tip.to_string()) 355 .eq(&local_branch_tip.to_string())
347 }) { 356 }) {
348 return match Interactor::default().choice( 357 return match Interactor::default().choice(
349 PromptChoiceParms::default() 358 PromptChoiceParms::default().with_default(0)
350 .with_choices( 359 .with_choices(
351 vec![ 360 vec![
352 format!( 361 format!(
@@ -410,7 +419,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
410 local_ahead_of_proposal.len() 419 local_ahead_of_proposal.len()
411 ); 420 );
412 return match Interactor::default().choice( 421 return match Interactor::default().choice(
413 PromptChoiceParms::default() 422 PromptChoiceParms::default().with_default(0)
414 .with_choices( 423 .with_choices(
415 vec![ 424 vec![
416 format!( 425 format!(
@@ -450,7 +459,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
450 local_beind_main.len(), 459 local_beind_main.len(),
451 ); 460 );
452 return match Interactor::default().choice( 461 return match Interactor::default().choice(
453 PromptChoiceParms::default() 462 PromptChoiceParms::default().with_default(0)
454 .with_choices( 463 .with_choices(
455 vec![ 464 vec![
456 format!( 465 format!(
@@ -514,7 +523,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
514 ); 523 );
515 524
516 return match Interactor::default().choice( 525 return match Interactor::default().choice(
517 PromptChoiceParms::default() 526 PromptChoiceParms::default().with_default(0)
518 .with_choices( 527 .with_choices(
519 vec![ 528 vec![
520 format!( 529 format!(