Repository: starship/starship
File: src/modules/aws.rs (Rust)

Code before:
    {
        chrono::DateTime::parse_from_rfc3339(&expiration_date).ok()
    } else {
        let contents = read_file(get_credentials_file_path(context)?).ok()?;

        let profile_line = if let Some(aws_profile) = aws_profile {
            format!("[{}]", aws_profile)
        } else {
            "[default]".to_string()
        };

        let expiration_date_line = contents
            .lines()
            .skip_while(|line| line != &profile_line)
            .skip(1)
            .take_while(|line| !line.starts_with('['))
            .find(|line| line.starts_with("expiration"))?;

        let expiration_date = expiration_date_line.split('=').nth(1)?.trim();
        DateTime::parse_from_rfc3339(expiration_date).ok()
    }?;

    Some(expiration_date.timestamp() - chrono::Local::now().timestamp())
}

fn alias_name(name: String, aliases: &HashMap<String, &str>) -> String {
    match aliases.get(&name) {
        None => name,
        Some(alias) => (*alias).to_string(),
    }
}

fn get_credential_process(context: &Context, aws_profile: Option<&Profile>) -> Option<String> {
    let contents = read_file(get_config_file_path(context)?).ok()?;

    let profile_line = if let Some(aws_profile) = aws_profile {
        format!("[profile {}]", aws_profile)
    } else {
        "[default]".to_string()
    };

    let cred_proc_line = contents
        .lines()
        .skip_while(|line| line != &profile_line)
        .skip(1)
        .take_while(|line| !line.starts_with('['))
        .find(|line| line.starts_with("credential_process"))?;

    let cred_proc = cred_proc_line.split('=').nth(1)?.trim();
    Some(cred_proc.to_string())
}

Review comment (refactor):
Maybe it would be better to refactor this to also handle the name being None and reduce the duplication on line 200-211 something like:

```rust
fn alias_name(name: Option<String>, aliases: &HashMap<String, &str>) -> Option<String> {
    if let Some(name) = name {
        match aliases.get(&name) {
            None => Some(name),
            Some(alias) => Some((*alias).to_string()),
        }
    } else {
        None
     }
 }
```

Code after:
    {
        chrono::DateTime::parse_from_rfc3339(&expiration_date).ok()
    } else {
        let contents = read_file(get_credentials_file_path(context)?).ok()?;

        let profile_line = if let Some(aws_profile) = aws_profile {
            format!("[{}]", aws_profile)
        } else {
            "[default]".to_string()
        };

        let expiration_date_line = contents
            .lines()
            .skip_while(|line| line != &profile_line)
            .skip(1)
            .take_while(|line| !line.starts_with('['))
            .find(|line| line.starts_with("expiration"))?;

        let expiration_date = expiration_date_line.split('=').nth(1)?.trim();
        DateTime::parse_from_rfc3339(expiration_date).ok()
    }?;

    Some(expiration_date.timestamp() - chrono::Local::now().timestamp())
}

fn alias_name(name: Option<String>, aliases: &HashMap<String, &str>) -> Option<String> {
    name.as_ref()
        .and_then(|n| aliases.get(n))
        .map(|&a| a.to_string())
        .or(name)
}

fn get_credential_process(context: &Context, aws_profile: Option<&Profile>) -> Option<String> {
    let contents = read_file(get_config_file_path(context)?).ok()?;

    let profile_line = if let Some(aws_profile) = aws_profile {
        format!("[profile {}]", aws_profile)
    } else {
        "[default]".to_string()
    };

    let cred_proc_line = contents
        .lines()
        .skip_while(|line| line != &profile_line)
        .skip(1)
        .take_while(|line| !line.starts_with('['))
        .find(|line| line.starts_with("credential_process"))?;

    let cred_proc = cred_proc_line.split('=').nth(1)?.trim();
    Some(cred_proc.to_string())
}