Content-Length: 435081 | pFad | http://github.com/starship/starship/pull/4949/files

BA feat(azure): subscription name aliases by marcybelardo · Pull Request #4949 · starship/starship · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(azure): subscription name aliases #4949

Merged
merged 5 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"disabled": true,
"format": "on [$symbol($subscription)]($style) ",
"style": "blue bold",
"subscription_aliases": {},
"symbol": "ﴃ "
},
"allOf": [
Expand Down Expand Up @@ -1845,6 +1846,13 @@
"disabled": {
"default": true,
"type": "boolean"
},
"subscription_aliases": {
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
22 changes: 16 additions & 6 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,13 @@ The `azure` module shows the current Azure Subscription. This is based on showin

### Options

| Variable | Default | Description |
| ---------- | ---------------------------------------- | ------------------------------------------ |
| `format` | `'on [$symbol($subscription)]($style) '` | The format for the Azure module to render. |
| `symbol` | `'ﴃ '` | The symbol used in the format. |
| `style` | `'blue bold'` | The style used in the format. |
| `disabled` | `true` | Disables the `azure` module. |
| Variable | Default | Description |
| ---------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------- |
| `format` | `'on [$symbol($subscription)]($style) '` | The format for the Azure module to render. |
| `symbol` | `'ﴃ '` | The symbol used in the format. |
| `style` | `'blue bold'` | The style used in the format. |
| `disabled` | `true` | Disables the `azure` module. |
| `subscription_aliases` | `{}` | Table of subscription name aliases to display in addition to Azure subscription name. |

### Examples

Expand Down Expand Up @@ -481,6 +482,15 @@ symbol = "ﴃ "
style = "blue bold"
```

#### Display Subscription Name Alias

```toml
# ~/.config/starship.toml

[azure.subscription_aliases]
very-long-subscription-name = 'vlsn'
```

## Battery

The `battery` module shows how charged the device's battery is and its current charging status.
Expand Down
3 changes: 3 additions & 0 deletions src/configs/azure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
Expand All @@ -12,6 +13,7 @@ pub struct AzureConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub subscription_aliases: HashMap<String, &'a str>,
}

impl<'a> Default for AzureConfig<'a> {
Expand All @@ -21,6 +23,7 @@ impl<'a> Default for AzureConfig<'a> {
symbol: "ﴃ ",
style: "blue bold",
disabled: true,
subscription_aliases: HashMap::new(),
}
}
}
81 changes: 80 additions & 1 deletion src/modules/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
"subscription" => Some(Ok(&subscription.name)),
"subscription" => Some(Ok(config
.subscription_aliases
.get(&subscription.name)
.copied()
.unwrap_or(&subscription.name))),
"username" => Some(Ok(&subscription.user.name)),
_ => None,
})
Expand Down Expand Up @@ -616,6 +620,81 @@ mod tests {
dir.close()
}

#[test]
fn subscription_name_with_alias() -> io::Result<()> {
let dir = tempfile::tempdir()?;

let azure_profile_contents = r#"{
"installationId": "3deacd2a-b9db-77e1-aa42-23e2f8dfffc3",
"subscriptions": [
{
"id": "f568c543-d12e-de0b-3d85-69843598b565",
"name": "VeryLongSubscriptionName",
"state": "Enabled",
"user": {
"name": "user@domain.com",
"type": "user"
},
"isDefault": false,
"tenantId": "0e8a15ec-b0f5-d355-7062-8ece54c59aee",
"environmentName": "AzureCloud",
"homeTenantId": "0e8a15ec-b0f5-d355-7062-8ece54c59aee",
"managedByTenants": []
},
{
"id": "d4442d26-ea6d-46c4-07cb-4f70b8ae5465",
"name": "AnotherLongSubscriptionName",
"state": "Enabled",
"user": {
"name": "user@domain.com",
"type": "user"
},
"isDefault": false,
"tenantId": "a4e1bb4b-5330-2d50-339d-b9674d3a87bc",
"environmentName": "AzureCloud",
"homeTenantId": "a4e1bb4b-5330-2d50-339d-b9674d3a87bc",
"managedByTenants": []
},
{
"id": "f3935dc9-92b5-9a93-da7b-42c325d86939",
"name": "TheLastLongSubscriptionName",
"state": "Enabled",
"user": {
"name": "user@domain.com",
"type": "user"
},
"isDefault": true,
"tenantId": "f0273a19-7779-e40a-00a1-53b8331b3bb6",
"environmentName": "AzureCloud",
"homeTenantId": "f0273a19-7779-e40a-00a1-53b8331b3bb6",
"managedByTenants": []
}
]
}
"#;

generate_test_config(&dir, azure_profile_contents)?;
let dir_path = &dir.path().to_string_lossy();
let actual = ModuleRenderer::new("azure")
.config(toml::toml! {
[azure]
format = "on [$symbol($subscription:$username)]($style)"
disabled = false
[azure.subscription_aliases]
VeryLongSubscriptionName = "vlsn"
AnotherLongSubscriptionName = "alsn"
TheLastLongSubscriptionName = "tllsn"
})
.env("AZURE_CONFIG_DIR", dir_path.as_ref())
.collect();
let expected = Some(format!(
"on {}",
Color::Blue.bold().paint("ﴃ tllsn:user@domain.com")
));
assert_eq!(actual, expected);
dir.close()
}

#[test]
fn subscription_azure_profile_empty() -> io::Result<()> {
let dir = tempfile::tempdir()?;
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/starship/starship/pull/4949/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy