<commit_before>﻿using System.Management.Automation;
using System.Security;

namespace Zyborg.Vault.POSH
{
	[Cmdlet(VerbsCommon.Get, "Profile",
			DefaultParameterSetName = DefaultParamSet)]
	public class GetProfile : PSCmdlet
	{
		public const string DefaultParamSet = VaultBaseCmdlet.DefaultParamSet;
		public const string GetDetailsParamSet = "GetDetails";

		[Parameter(Mandatory = true, Position = 0,
				ParameterSetName = GetDetailsParamSet)]
		public string[] VaultProfile
		{ get; set; }

		[Parameter(ParameterSetName = DefaultParamSet)]
		public SwitchParameter ShowLabels
		{ get; set; }

		protected override void ProcessRecord()
		{
			if (VaultProfile == null)
			{
				foreach (var name in Global.GetVaultProfileNames(this))
				{
					if (ShowLabels)
					{
						var vp = Global.GetVaultProfile(this, name);
						WriteObject(new
						{
							Name = name,
							Label = vp.Label,
						});
					}
					else
					{
						WriteObject(name);
					}
				}
			}
			else
			{
				foreach (var name in VaultProfile)
				{
					var vp = Global.GetVaultProfile(this, name);
					if (vp != null)
					{
						WriteObject(new GetProfileResult
						{
							Label = vp.Label,
							VaultAddress = vp.VaultAddress,
						}.SetVaultToken(vp.VaultToken));
					}
				}
			}
		}
	}

	public class GetProfileResult
	{
		public string VaultAddress
		{ get; set; }

		public SecureString VaultToken
		{ get; set; }

		public string Label
		{ get; set; }

		public GetProfileResult SetVaultToken(string t)
		{
			if (string.IsNullOrEmpty(t))
				VaultToken = null;
			else
			{
				var ss = new SecureString();
				foreach (var c in t)
					ss.AppendChar(c);
				VaultToken = ss;
			}

			return this;
		}
	}
}
<commit_msg>Allow profiles names to be specified via pipeline<commit_after>﻿using System.Management.Automation;
using System.Security;

namespace Zyborg.Vault.POSH
{
	[Cmdlet(VerbsCommon.Get, "Profile",
			DefaultParameterSetName = DefaultParamSet)]
	public class GetProfile : PSCmdlet
	{
		public const string DefaultParamSet = VaultBaseCmdlet.DefaultParamSet;
		public const string GetDetailsParamSet = "GetDetails";

		[Parameter(Mandatory = true, Position = 0, ParameterSetName = GetDetailsParamSet,
				ValueFromPipeline = true)]
		public string[] VaultProfile
		{ get; set; }

		[Parameter(ParameterSetName = DefaultParamSet)]
		public SwitchParameter ShowLabels
		{ get; set; }

		protected override void ProcessRecord()
		{
			if (VaultProfile == null)
			{
				foreach (var name in Global.GetVaultProfileNames(this))
				{
					if (ShowLabels)
					{
						var vp = Global.GetVaultProfile(this, name);
						WriteObject(new
						{
							Name = name,
							Label = vp.Label,
						});
					}
					else
					{
						WriteObject(name);
					}
				}
			}
			else
			{
				foreach (var name in VaultProfile)
				{
					var vp = Global.GetVaultProfile(this, name);
					if (vp != null)
					{
						WriteObject(new GetProfileResult
						{
							Label = vp.Label,
							VaultAddress = vp.VaultAddress,
						}.SetVaultToken(vp.VaultToken));
					}
				}
			}
		}
	}

	public class GetProfileResult
	{
		public string VaultAddress
		{ get; set; }

		public SecureString VaultToken
		{ get; set; }

		public string Label
		{ get; set; }

		public GetProfileResult SetVaultToken(string t)
		{
			if (string.IsNullOrEmpty(t))
				VaultToken = null;
			else
			{
				var ss = new SecureString();
				foreach (var c in t)
					ss.AppendChar(c);
				VaultToken = ss;
			}

			return this;
		}
	}
}

{'fraction_non_alphanumeric': 0.09851936218678815, 'fraction_numerical': 0.0005694760820045558, 'mean_word_length': 2.694006309148265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646808', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1141, 'n_words': 265}