mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Use file scoped namespace declarations
This commit is contained in:

committed by
Phil Scott

parent
1dbaf50935
commit
ec1188b837
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class AppVeyorEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class AppVeyorEnricher : IProfileEnricher
|
||||
public string Name => "AppVeyor";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "AppVeyor";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("APPVEYOR");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("APPVEYOR");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class BambooEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class BambooEnricher : IProfileEnricher
|
||||
public string Name => "Bamboo";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "Bamboo";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("bamboo_buildNumber");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("bamboo_buildNumber");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,21 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class BitbucketEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class BitbucketEnricher : IProfileEnricher
|
||||
public string Name => "Bitbucket";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "Bitbucket";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("BITBUCKET_REPO_OWNER") ||
|
||||
environmentVariables.ContainsKey("BITBUCKET_REPO_SLUG") ||
|
||||
environmentVariables.ContainsKey("BITBUCKET_COMMIT");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("BITBUCKET_REPO_OWNER") ||
|
||||
environmentVariables.ContainsKey("BITBUCKET_REPO_SLUG") ||
|
||||
environmentVariables.ContainsKey("BITBUCKET_COMMIT");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class BitriseEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class BitriseEnricher : IProfileEnricher
|
||||
public string Name => "Bitrise";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "Bitrise";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("BITRISE_BUILD_URL");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("BITRISE_BUILD_URL");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class ContinuaEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class ContinuaEnricher : IProfileEnricher
|
||||
public string Name => "ContinuaCI";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "ContinuaCI";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("ContinuaCI.Version");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("ContinuaCI.Version");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,28 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class GitHubEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class GitHubEnricher : IProfileEnricher
|
||||
public string Name => "GitHub";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "GitHub";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
if (environmentVariables.TryGetValue("GITHUB_ACTIONS", out var value))
|
||||
{
|
||||
if (environmentVariables.TryGetValue("GITHUB_ACTIONS", out var value))
|
||||
{
|
||||
return value?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return value?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Ansi = true;
|
||||
profile.Capabilities.Legacy = false;
|
||||
profile.Capabilities.Interactive = false;
|
||||
profile.Capabilities.Links = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Ansi = true;
|
||||
profile.Capabilities.Legacy = false;
|
||||
profile.Capabilities.Interactive = false;
|
||||
profile.Capabilities.Links = false;
|
||||
}
|
||||
}
|
@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class GitLabEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class GitLabEnricher : IProfileEnricher
|
||||
public string Name => "GitLab";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "GitLab";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
if (environmentVariables.TryGetValue("CI_SERVER", out var value))
|
||||
{
|
||||
if (environmentVariables.TryGetValue("CI_SERVER", out var value))
|
||||
{
|
||||
return value?.Equals("yes", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return value?.Equals("yes", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class GoCDEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class GoCDEnricher : IProfileEnricher
|
||||
public string Name => "GoCD";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "GoCD";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("GO_SERVER_URL");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("GO_SERVER_URL");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class JenkinsEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class JenkinsEnricher : IProfileEnricher
|
||||
public string Name => "Jenkins";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "Jenkins";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("JENKINS_URL");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("JENKINS_URL");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class MyGetEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class MyGetEnricher : IProfileEnricher
|
||||
public string Name => "MyGet";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "MyGet";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
if (environmentVariables.TryGetValue("BuildRunner", out var value))
|
||||
{
|
||||
if (environmentVariables.TryGetValue("BuildRunner", out var value))
|
||||
{
|
||||
return value?.Equals("MyGet", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return value?.Equals("MyGet", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class TeamCityEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class TeamCityEnricher : IProfileEnricher
|
||||
public string Name => "TeamCity";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "TeamCity";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("TEAMCITY_VERSION");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("TEAMCITY_VERSION");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class TfsEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class TfsEnricher : IProfileEnricher
|
||||
public string Name => "TFS";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "TFS";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("TF_BUILD");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("TF_BUILD");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal sealed class TravisEnricher : IProfileEnricher
|
||||
{
|
||||
internal sealed class TravisEnricher : IProfileEnricher
|
||||
public string Name => "Travis";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
public string Name => "Travis";
|
||||
|
||||
public bool Enabled(IDictionary<string, string> environmentVariables)
|
||||
{
|
||||
return environmentVariables.ContainsKey("TRAVIS");
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
return environmentVariables.ContainsKey("TRAVIS");
|
||||
}
|
||||
}
|
||||
|
||||
public void Enrich(Profile profile)
|
||||
{
|
||||
profile.Capabilities.Interactive = false;
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Spectre.Console.Enrichment
|
||||
namespace Spectre.Console.Enrichment;
|
||||
|
||||
internal static class ProfileEnricher
|
||||
{
|
||||
internal static class ProfileEnricher
|
||||
{
|
||||
private static readonly List<IProfileEnricher> _defaultEnrichers = new List<IProfileEnricher>
|
||||
private static readonly List<IProfileEnricher> _defaultEnrichers = new List<IProfileEnricher>
|
||||
{
|
||||
new AppVeyorEnricher(),
|
||||
new BambooEnricher(),
|
||||
@ -23,73 +23,72 @@ namespace Spectre.Console.Enrichment
|
||||
new TravisEnricher(),
|
||||
};
|
||||
|
||||
public static void Enrich(
|
||||
Profile profile,
|
||||
ProfileEnrichment settings,
|
||||
IDictionary<string, string>? environmentVariables)
|
||||
public static void Enrich(
|
||||
Profile profile,
|
||||
ProfileEnrichment settings,
|
||||
IDictionary<string, string>? environmentVariables)
|
||||
{
|
||||
if (profile is null)
|
||||
{
|
||||
if (profile is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(profile));
|
||||
}
|
||||
|
||||
settings ??= new ProfileEnrichment();
|
||||
|
||||
var variables = GetEnvironmentVariables(environmentVariables);
|
||||
foreach (var enricher in GetEnrichers(settings))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(enricher.Name))
|
||||
{
|
||||
throw new InvalidOperationException($"Profile enricher of type '{enricher.GetType().FullName}' does not have a name.");
|
||||
}
|
||||
|
||||
if (enricher.Enabled(variables))
|
||||
{
|
||||
enricher.Enrich(profile);
|
||||
profile.AddEnricher(enricher.Name);
|
||||
}
|
||||
}
|
||||
throw new ArgumentNullException(nameof(profile));
|
||||
}
|
||||
|
||||
private static List<IProfileEnricher> GetEnrichers(ProfileEnrichment settings)
|
||||
settings ??= new ProfileEnrichment();
|
||||
|
||||
var variables = GetEnvironmentVariables(environmentVariables);
|
||||
foreach (var enricher in GetEnrichers(settings))
|
||||
{
|
||||
var enrichers = new List<IProfileEnricher>();
|
||||
|
||||
if (settings.UseDefaultEnrichers)
|
||||
if (string.IsNullOrWhiteSpace(enricher.Name))
|
||||
{
|
||||
enrichers.AddRange(_defaultEnrichers);
|
||||
throw new InvalidOperationException($"Profile enricher of type '{enricher.GetType().FullName}' does not have a name.");
|
||||
}
|
||||
|
||||
if (settings.Enrichers?.Count > 0)
|
||||
if (enricher.Enabled(variables))
|
||||
{
|
||||
enrichers.AddRange(settings.Enrichers);
|
||||
enricher.Enrich(profile);
|
||||
profile.AddEnricher(enricher.Name);
|
||||
}
|
||||
|
||||
return enrichers;
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> GetEnvironmentVariables(IDictionary<string, string>? variables)
|
||||
{
|
||||
if (variables != null)
|
||||
{
|
||||
return new Dictionary<string, string>(variables, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
return Environment.GetEnvironmentVariables()
|
||||
.Cast<System.Collections.DictionaryEntry>()
|
||||
.Aggregate(
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
||||
(dictionary, entry) =>
|
||||
{
|
||||
var key = (string)entry.Key;
|
||||
if (!dictionary.TryGetValue(key, out _))
|
||||
{
|
||||
dictionary.Add(key, entry.Value as string ?? string.Empty);
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
},
|
||||
dictionary => dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<IProfileEnricher> GetEnrichers(ProfileEnrichment settings)
|
||||
{
|
||||
var enrichers = new List<IProfileEnricher>();
|
||||
|
||||
if (settings.UseDefaultEnrichers)
|
||||
{
|
||||
enrichers.AddRange(_defaultEnrichers);
|
||||
}
|
||||
|
||||
if (settings.Enrichers?.Count > 0)
|
||||
{
|
||||
enrichers.AddRange(settings.Enrichers);
|
||||
}
|
||||
|
||||
return enrichers;
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> GetEnvironmentVariables(IDictionary<string, string>? variables)
|
||||
{
|
||||
if (variables != null)
|
||||
{
|
||||
return new Dictionary<string, string>(variables, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
return Environment.GetEnvironmentVariables()
|
||||
.Cast<System.Collections.DictionaryEntry>()
|
||||
.Aggregate(
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
||||
(dictionary, entry) =>
|
||||
{
|
||||
var key = (string)entry.Key;
|
||||
if (!dictionary.TryGetValue(key, out _))
|
||||
{
|
||||
dictionary.Add(key, entry.Value as string ?? string.Empty);
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
},
|
||||
dictionary => dictionary);
|
||||
}
|
||||
}
|
@ -1,22 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console
|
||||
namespace Spectre.Console;
|
||||
|
||||
/// <summary>
|
||||
/// Contains settings for profile enrichment.
|
||||
/// </summary>
|
||||
public sealed class ProfileEnrichment
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains settings for profile enrichment.
|
||||
/// Gets or sets a value indicating whether or not
|
||||
/// any default enrichers should be added.
|
||||
/// </summary>
|
||||
public sealed class ProfileEnrichment
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not
|
||||
/// any default enrichers should be added.
|
||||
/// </summary>
|
||||
/// <remarks>Defaults to <c>true</c>.</remarks>
|
||||
public bool UseDefaultEnrichers { get; set; } = true;
|
||||
/// <remarks>Defaults to <c>true</c>.</remarks>
|
||||
public bool UseDefaultEnrichers { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of custom enrichers to use.
|
||||
/// </summary>
|
||||
public List<IProfileEnricher>? Enrichers { get; set; }
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the list of custom enrichers to use.
|
||||
/// </summary>
|
||||
public List<IProfileEnricher>? Enrichers { get; set; }
|
||||
}
|
Reference in New Issue
Block a user