MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / url

Function url

crates/chat-cli/src/cli/chat/parse.rs:414–451  ·  view source on GitHub ↗
(
    mut o: impl Write + 'b,
    state: &'b mut ParseState,
)

Source from the content-addressed store, hash-verified

412}
413
414fn url<'a, 'b>(
415 mut o: impl Write + 'b,
416 state: &'b mut ParseState,
417) -> impl FnMut(&mut Partial<&'a str>) -> PResult<(), Error<'a>> + 'b {
418 move |i| {
419 // Save the current input position
420 let start = i.checkpoint();
421
422 // Try to match the first part of URL pattern "[text]"
423 let display = match delimited::<_, _, _, _, Error<'a>, _, _, _>("[", take_until(1.., "]("), "]").parse_next(i) {
424 Ok(display) => display,
425 Err(_) => {
426 // If it doesn't match, reset position and fail
427 i.reset(&start);
428 return Err(ErrMode::from_error_kind(i, ErrorKind::Fail));
429 },
430 };
431
432 // Try to match the second part of URL pattern "(url)"
433 let link = match delimited::<_, _, _, _, Error<'a>, _, _, _>("(", take_till(0.., ')'), ")").parse_next(i) {
434 Ok(link) => link,
435 Err(_) => {
436 // If it doesn't match, reset position and fail
437 i.reset(&start);
438 return Err(ErrMode::from_error_kind(i, ErrorKind::Fail));
439 },
440 };
441
442 // Only generate output if the complete URL pattern matches
443 queue_newline_or_advance(&mut o, state, display.width() + 1)?;
444 queue(&mut o, StyledText::info_fg())?;
445 queue(&mut o, style::Print(format!("{display} ")))?;
446 queue(&mut o, StyledText::secondary_fg())?;
447 state.column += link.width();
448 queue(&mut o, style::Print(link))?;
449 queue(&mut o, StyledText::reset())
450 }
451}
452
453fn less_than<'a, 'b>(
454 mut o: impl Write + 'b,

Callers

nothing calls this directly

Calls 3

queue_newline_or_advanceFunction · 0.85
queueFunction · 0.85
resetMethod · 0.80

Tested by

no test coverage detected