Skip to content

Commit

Permalink
fix: correct defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Sep 21, 2019
1 parent 131b247 commit c1271fa
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
15 changes: 12 additions & 3 deletions PSKubectl/Completers/Get-KubeDeployment.Completer.ps1
Expand Up @@ -2,11 +2,20 @@ using namespace System.Management.Automation.Language;
using namespace System.Management.Automation;

Register-ArgumentCompleter -CommandName Get-KubeDeployment -ParameterName Name -ScriptBlock {
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$fakeBoundParameter)
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)

$fakeBoundParameter.Remove('Name')
$deployParams = @{ }
if ($params.ContainsKey('ApiEndpoint')) {
$deployParams.ApiEndpoint = $params.ApiEndpoint
}
if ($params.ContainsKey('AllowInsecure')) {
$deployParams.AllowInsecure = $params.AllowInsecure
}
if ($params.ContainsKey('Namespace')) {
$deployParams.Namespace = $params.Namespace
}

Get-KubeDeployment @fakeBoundParameter |
Get-KubeDeployment @deployParams |
ForEach-Object { $_.Metadata.Name } |
Where-Object { $_ -like "$wordToComplete*" } |
ForEach-Object { [CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_) }
Expand Down
13 changes: 9 additions & 4 deletions PSKubectl/Completers/Namespace.Completer.ps1
Expand Up @@ -2,12 +2,17 @@ using namespace System.Management.Automation.Language;
using namespace System.Management.Automation;

$namespaceCompleter = {
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$fakeBoundParameter)
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)

$fakeBoundParameter.Remove('Namespace')
$fakeBoundParameter.Remove('Name')
$nsParams = @{ }
if ($params.ContainsKey('ApiEndpoint')) {
$nsParams.ApiEndpoint = $params.ApiEndpoint
}
if ($params.ContainsKey('AllowInsecure')) {
$nsParams.AllowInsecure = $params.AllowInsecure
}

Get-KubeNamespace @fakeBoundParameter |
Get-KubeNamespace @nsParams |
ForEach-Object { $_.Metadata.Name } |
Where-Object { $_ -like "$wordToComplete*" } |
ForEach-Object { [CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_) }
Expand Down
15 changes: 12 additions & 3 deletions PSKubectl/Completers/PodName.Completer.ps1
Expand Up @@ -2,11 +2,20 @@ using namespace System.Management.Automation.Language;
using namespace System.Management.Automation;

$podNameCompleter = {
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$fakeBoundParameter)
param([string]$commandName, [string]$parameterName, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)

$fakeBoundParameter.Remove('Name')
$podParams = @{ }
if ($params.ContainsKey('ApiEndpoint')) {
$podParams.ApiEndpoint = $params.ApiEndpoint
}
if ($params.ContainsKey('AllowInsecure')) {
$podParams.AllowInsecure = $params.AllowInsecure
}
if ($params.ContainsKey('Namespace')) {
$podParams.Namespace = $params.Namespace
}

Get-KubePod @fakeBoundParameter |
Get-KubePod @podParams |
ForEach-Object { $_.Metadata.Name } |
Where-Object { $_ -like "$wordToComplete*" } |
ForEach-Object { [CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_) }
Expand Down
2 changes: 1 addition & 1 deletion src/Cmdlets/GetKubeDeploymentCmdlet.cs
Expand Up @@ -15,7 +15,7 @@ namespace Kubectl.Cmdlets {
public sealed class GetKubeDeploymentCmdlet : KubeApiCmdlet {
[Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Ns")]
public string Namespace { get; set; }
public string Namespace { get; set; } = "default";

[Parameter()]
public string LabelSelector { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Cmdlets/GetKubePodCmdlet.cs
Expand Up @@ -15,7 +15,7 @@ namespace Kubectl.Cmdlets {
public sealed class GetKubePodCmdlet : KubeApiCmdlet {
[Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Ns")]
public string Namespace { get; set; }
public string Namespace { get; set; } = "default";

[Parameter()]
public string LabelSelector { get; set; }
Expand Down
4 changes: 1 addition & 3 deletions src/Cmdlets/GetKubeResourceCmdlet.cs
Expand Up @@ -6,16 +6,14 @@
using System.Threading.Tasks;
using KubeClient;
using KubeClient.Models;
using KubeClient.ResourceClients;
using Microsoft.Extensions.Logging;

namespace Kubectl.Cmdlets {
[Cmdlet(VerbsCommon.Get, "KubeResource")]
[OutputType(new[] { typeof(KubeResourceV1) })]
public sealed class GetKubeResourceCmdlet : KubeApiCmdlet {
[Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Ns")]
public string Namespace { get; set; }
public string Namespace { get; set; } = "default";

[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)]
public string Kind { get; set; }
Expand Down

0 comments on commit c1271fa

Please sign in to comment.