termscp 1.0.0

termscp is a feature rich terminal file transfer and explorer with support for SCP/SFTP/FTP/Kube/S3/WebDAV
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! ## Parser Credential Helpers
//!
//! Shared capture-group helpers used by parser submodules when extracting
//! credentials and required fields from regex matches.

pub(super) fn optional_capture(groups: &regex::Captures<'_>, index: usize) -> Option<String> {
    groups.get(index).map(|group| group.as_str().to_string())
}

pub(super) fn required_capture(
    groups: &regex::Captures<'_>,
    index: usize,
    field_name: &str,
) -> Result<String, String> {
    optional_capture(groups, index).ok_or_else(|| format!("Missing {field_name}"))
}