Skip to content

Commit

Permalink
feat: Enhance KSail CLI with global options bug fixes and configurati…
Browse files Browse the repository at this point in the history
…on improvements (#657)

* chore: add .sops.yaml to .gitignore

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: add connection kubeconfig and context options to KSailUpCommand

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: optimize KSail YAML file search by using wildcard pattern

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: enhance KSailClusterConfigLoader to accept custom config file path

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: add ksail config path option to KSailUpCommand and update config loading logic

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: add ksail config path option to KSailInitCommand

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: rename ksailConfigPath to configPath in ksail-cluster-schema.json

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: replace EditorOption with ProjectEditorOption for project-specific editor configuration

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailDebugCommand to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailDownCommand to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: move ProjectTemplateOption to a new location and update its implementation

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailInitCommand to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailLintCommand to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailListCommand to use global options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailRootCommand to use global options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor secrets commands to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor commands to use global options and remove unused options

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: add global options for KSail CLI with detailed descriptions

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: implement LoadWithGlobalOptions method to utilize global options in KSailClusterConfigLoader

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: rename KSailConfigPath to ConfigPath in KSailProject

Signed-off-by: Nikolai Emil Damm <[email protected]>

* chore: update tests

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update LoadWithGlobalOptions method calls to LoadWithGlobalOptionsAsync for consistency

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update options to include default values from KSailCluster configuration

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: rename LoadWithGlobalOptions to LoadWithGlobalOptionsAsync and streamline option retrieval

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update KSailDebugCommandTests to use array syntax for command arguments

Signed-off-by: Nikolai Emil Damm <[email protected]>

* chore: update tests

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: enhance logging for 'flux-system' namespace creation in BootstrapDeploymentTool and BootstrapSecretManager

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update path regex patterns for SOPS configuration to support encrypted YAML files

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update path regex patterns in SOPS configuration for encrypted YAML files

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: refactor KSailUpCommandHandler to improve engine readiness checks and enhance OCI source registry bootstrapping

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: simplify FluxDeploymentTool initialization by removing OS-specific checks

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update Devantler.SecretManager.SOPS.LocalAge package version to 1.3.1

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update Devantler.K9sCLI package version to 1.3.0

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update container ID retrieval for OCI source registry connections in KSailUpCommandHandler

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: enable SOPS binary execution in Startup configuration

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update mirror registry names to include '-proxy' suffix and change host port in KSailUpCommandHandler

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update OCI source registry port and retrieval logic in KSailUpCommandHandler

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update source URL construction to use KSail registry host port

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update proxy registry names to include '-proxy' suffix in configuration files

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update port retrieval logic in KSailUpdateCommandHandler to use KSail registry port

Signed-off-by: Nikolai Emil Damm <[email protected]>

* fix: update port retrieval logic in KSailUpdateCommandHandler to use KSail registry host port

Signed-off-by: Nikolai Emil Damm <[email protected]>

---------

Signed-off-by: Nikolai Emil Damm <[email protected]>
  • Loading branch information
devantler authored Feb 22, 2025
1 parent 7d52f2c commit 113a254
Show file tree
Hide file tree
Showing 144 changed files with 1,989 additions and 817 deletions.
2 changes: 1 addition & 1 deletion schemas/ksail-cluster-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"description": "The working directory for the project.",
"type": "string"
},
"ksailConfigPath": {
"configPath": {
"description": "The path to the ksail configuration file.",
"type": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion src/KSail.Models/KSail.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="YamlDotNet" Version="16.3.0" />
<PackageReference Include="Devantler.K9sCLI" Version="1.2.1" />
<PackageReference Include="Devantler.K9sCLI" Version="1.3.0" />
</ItemGroup>

</Project>
22 changes: 7 additions & 15 deletions src/KSail.Models/KSailClusterSpec.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using KSail.Models.CLI;
using KSail.Models.CNI;
using KSail.Models.Connection;
Expand Down Expand Up @@ -71,12 +70,12 @@ public class KSailClusterSpec
/// </summary>
[Description("The mirror registries to create for the KSail cluster.")]
public IEnumerable<KSailMirrorRegistry> MirrorRegistries { get; set; } = [
new KSailMirrorRegistry { Name = "registry.k8s.io", HostPort = 5556, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://registry.k8s.io") } },
new KSailMirrorRegistry { Name = "docker.io", HostPort = 5557, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://registry-1.docker.io") } },
new KSailMirrorRegistry { Name = "ghcr.io", HostPort = 5558, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://ghcr.io") } },
new KSailMirrorRegistry { Name = "gcr.io", HostPort = 5559, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://gcr.io") } },
new KSailMirrorRegistry { Name = "mcr.microsoft.com", HostPort = 5560, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://mcr.microsoft.com") } },
new KSailMirrorRegistry { Name = "quay.io", HostPort = 5561, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://quay.io") } },
new KSailMirrorRegistry { Name = "registry.k8s.io-proxy", HostPort = 5556, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://registry.k8s.io") } },
new KSailMirrorRegistry { Name = "docker.io-proxy", HostPort = 5557, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://registry-1.docker.io") } },
new KSailMirrorRegistry { Name = "ghcr.io-proxy", HostPort = 5558, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://ghcr.io") } },
new KSailMirrorRegistry { Name = "gcr.io-proxy", HostPort = 5559, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://gcr.io") } },
new KSailMirrorRegistry { Name = "mcr.microsoft.com-proxy", HostPort = 5560, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://mcr.microsoft.com") } },
new KSailMirrorRegistry { Name = "quay.io-proxy", HostPort = 5561, Proxy = new KSailMirrorRegistryProxy { Url = new Uri("https://quay.io") } },
];

/// <summary>
Expand Down Expand Up @@ -146,14 +145,7 @@ void SetOCISourceUri(KSailKubernetesDistribution distribution = KSailKubernetesD
switch (distribution)
{
case KSailKubernetesDistribution.Native:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
FluxDeploymentTool = new KSailFluxDeploymentTool(new Uri("oci://172.17.0.1:5555/ksail-registry"));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
FluxDeploymentTool = new KSailFluxDeploymentTool(new Uri("oci://host.docker.internal:5555/ksail-registry"));
}
FluxDeploymentTool = new KSailFluxDeploymentTool(new Uri("oci://ksail-registry:5000/ksail-registry"));
break;
case KSailKubernetesDistribution.K3s:
FluxDeploymentTool = new KSailFluxDeploymentTool(new Uri("oci://host.k3d.internal:5555/ksail-registry"));
Expand Down
5 changes: 1 addition & 4 deletions src/KSail.Models/Project/KSailProject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Text.Json.Serialization;
using Devantler.K9sCLI;
using YamlDotNet.Serialization;

Expand All @@ -20,9 +19,7 @@ public class KSailProject
/// The path to the ksail configuration file.
/// </summary>
[Description("The path to the ksail configuration file.")]
[YamlMember(Alias = "ksailConfigPath")]
[JsonPropertyName("ksailConfigPath")]
public string KSailConfigPath { get; set; } = "ksail-config.yaml";
public string ConfigPath { get; set; } = "ksail-config.yaml";

/// <summary>
/// The path to the distribution configuration file.
Expand Down
1 change: 1 addition & 0 deletions src/KSail/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
k8s
kind-config.yaml
ksail-config.yaml
.sops.yaml
14 changes: 2 additions & 12 deletions src/KSail/Commands/Debug/KSailDebugCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.CommandLine;
using KSail.Commands.Debug.Handlers;
using KSail.Commands.Debug.Options;
using KSail.Options;
using KSail.Utils;

Expand All @@ -9,23 +8,14 @@ namespace KSail.Commands.Debug;
sealed class KSailDebugCommand : Command
{
readonly ExceptionHandler _exceptionHandler = new();
readonly ConnectionKubeconfigOption _kubeconfigOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ConnectionContextOption _contextOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly EditorOption _editorOption = new() { Arity = ArgumentArity.ZeroOrOne };

internal KSailDebugCommand() : base("debug", "Debug a cluster (❤️ K9s)")
internal KSailDebugCommand(GlobalOptions globalOptions) : base("debug", "Debug a cluster (❤️ K9s)")
{
AddOption(_kubeconfigOption);
AddOption(_contextOption);
AddOption(_editorOption);
this.SetHandler(async (context) =>
{
try
{
var config = await KSailClusterConfigLoader.LoadAsync().ConfigureAwait(false);
config.UpdateConfig("Spec.Connection.Kubeconfig", context.ParseResult.GetValueForOption(_kubeconfigOption));
config.UpdateConfig("Spec.Connection.Context", context.ParseResult.GetValueForOption(_contextOption));
config.UpdateConfig("Spec.Project.Editor", context.ParseResult.GetValueForOption(_editorOption));
var config = await KSailClusterConfigLoader.LoadWithGlobalOptionsAsync(globalOptions, context);
var handler = new KSailDebugCommandHandler(config);
context.ExitCode = await handler.HandleAsync(context.GetCancellationToken()).ConfigureAwait(false) ? 0 : 1;
Console.WriteLine();
Expand Down
9 changes: 0 additions & 9 deletions src/KSail/Commands/Debug/Options/EditorOption.cs

This file was deleted.

18 changes: 2 additions & 16 deletions src/KSail/Commands/Down/KSailDownCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@ namespace KSail.Commands.Down;
sealed class KSailDownCommand : Command
{
readonly ExceptionHandler _exceptionHandler = new();
readonly MetadataNameOption _nameOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectEngineOption _engineOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectDistributionOption _distributionOption = new() { Arity = ArgumentArity.ZeroOrOne };
internal KSailDownCommand() : base("down", "Destroy a cluster")
internal KSailDownCommand(GlobalOptions globalOptions) : base("down", "Destroy a cluster")
{
AddOptions();

this.SetHandler(async (context) =>
{
try
{
var config = await KSailClusterConfigLoader.LoadAsync().ConfigureAwait(false);
config.UpdateConfig("Metadata.Name", context.ParseResult.GetValueForOption(_nameOption));
config.UpdateConfig("Spec.Project.Engine", context.ParseResult.GetValueForOption(_engineOption));
config.UpdateConfig("Spec.Project.Distribution", context.ParseResult.GetValueForOption(_distributionOption));
var config = await KSailClusterConfigLoader.LoadWithGlobalOptionsAsync(globalOptions, context);

var handler = new KSailDownCommandHandler(config);
context.ExitCode = await handler.HandleAsync(context.GetCancellationToken()).ConfigureAwait(false) ? 0 : 1;
Expand All @@ -34,10 +26,4 @@ internal KSailDownCommand() : base("down", "Destroy a cluster")
}
});
}

void AddOptions()
{
AddOption(_nameOption);
AddOption(_distributionOption);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class KSailGenCertManagerCertificateCommand : Command
readonly OutputOption _outputOption = new("./certificate.yaml");
public KSailGenCertManagerCertificateCommand() : base("certificate", "Generate a 'cert-manager.io/v1/Certificate' resource.")
{
AddOption(_outputOption);
this.AddOption(_outputOption);

this.SetHandler(async (context) =>
{
try
{
string outputFile = context.ParseResult.RootCommandResult.GetValueForOption(_outputOption)!;
string outputFile = context.ParseResult.CommandResult.GetValueForOption(_outputOption) ?? "./certificate.yaml";
var handler = new KSailGenCertManagerCertificateCommandHandler();
Console.WriteLine($"✚ generating {outputFile}");
context.ExitCode = await handler.HandleAsync(outputFile, context.GetCancellationToken()).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ internal async Task<int> HandleAsync(string outputFile, CancellationToken cancel
CreationRules =
[
new() {
PathRegex = @"^k8s\/.+\.sops\.yaml$",
EncryptedRegex = "^(data | stringData)$",
PathRegex = @"^.+\.enc\.ya?ml$",
EncryptedRegex = "^(data|stringData)$",
Age = """
<age-public-key-1>
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ async Task GenerateNewSOPSConfigFile(string path, string clusterName, AgeKey age
[
new()
{
PathRegex = @$"^k8s\/clusters\/{clusterName}\/.+\.sops\.yaml$",
PathRegex = @$"^k8s\/clusters\/{clusterName}\/.+\.enc\.ya?ml$",
Age = ageKey.PublicKey
},
new()
{
PathRegex = ".sops.yaml",
PathRegex = @"^.+\.enc\.ya?ml$",
Age = ageKey.PublicKey
}
]
Expand All @@ -69,12 +69,12 @@ async Task GenerateUpdatedSOPSConfigFile(string path, string clusterName, AgeKey
var sopsConfig = await SOPSConfigHelper.GetSOPSConfigAsync(path, cancellationToken: cancellationToken).ConfigureAwait(false);

// Check if the creation rule already exists
if (!sopsConfig.CreationRules.Any(cr => cr.PathRegex == @$"^k8s\/clusters\/{clusterName}\/.+\.sops\.yaml$"))
if (!sopsConfig.CreationRules.Any(cr => cr.PathRegex == @$"^k8s\/clusters\/{clusterName}\/.+\.enc\.ya?ml$"))
{
// Add new creation rule to the start of the list
sopsConfig.CreationRules.Insert(0, new SOPSConfigCreationRule
{
PathRegex = @$"^k8s\/clusters\/{clusterName}\/.+\.sops\.yaml$",
PathRegex = @$"^k8s\/clusters\/{clusterName}\/.+\.enc\.ya?ml$",
Age = ageKey.PublicKey
});
var lastCreationRule = sopsConfig.CreationRules.Last();
Expand Down
26 changes: 2 additions & 24 deletions src/KSail/Commands/Init/KSailInitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,22 @@ namespace KSail.Commands.Init;
sealed class KSailInitCommand : Command
{
readonly ExceptionHandler _exceptionHandler = new();
readonly MetadataNameOption _metadataNameOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly PathOption _projectWorkingDirectoryOption = new("The output directory", ["-o", "--output"]) { Arity = ArgumentArity.ZeroOrOne };
readonly FluxDeploymentToolPostBuildVariablesOption _fluxDeploymentToolPostBuildVariablesOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly KustomizeTemplateFlowsOption _kustomizeTemplateKustomizationsOption = new() { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
readonly KustomizeTemplateHooksOption _kustomizeTemplateKustomizationHooksOption = new() { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
readonly ProjectDeploymentToolOption _projectDeploymentToolOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectDistributionOption _projectDistributionOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectMirrorRegistriesOption _projectMirrorRegistriesOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectSecretManagerOption _projectSecretManagerOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly ProjectTemplateOption _projectTemplateOption = new() { Arity = ArgumentArity.ZeroOrOne };

public KSailInitCommand() : base("init", "Initialize a cluster")
public KSailInitCommand(GlobalOptions globalOptions) : base("init", "Initialize a cluster")
{
AddOptions();

this.SetHandler(async (context) =>
{
try
{
var config = await KSailClusterConfigLoader.LoadAsync(name: context.ParseResult.GetValueForOption(_metadataNameOption), distribution: context.ParseResult.GetValueForOption(_projectDistributionOption)).ConfigureAwait(false);
config.UpdateConfig("Metadata.Name", context.ParseResult.GetValueForOption(_metadataNameOption));
var config = await KSailClusterConfigLoader.LoadWithGlobalOptionsAsync(globalOptions, context);
config.UpdateConfig("Spec.FluxDeploymentTool.PostBuildVariables", context.ParseResult.GetValueForOption(_fluxDeploymentToolPostBuildVariablesOption));
config.UpdateConfig("Spec.KustomizeTemplate.Flows", context.ParseResult.GetValueForOption(_kustomizeTemplateKustomizationsOption));
config.UpdateConfig("Spec.KustomizeTemplate.Hooks", context.ParseResult.GetValueForOption(_kustomizeTemplateKustomizationHooksOption));
config.UpdateConfig("Spec.Project.DeploymentTool", context.ParseResult.GetValueForOption(_projectDeploymentToolOption));
config.UpdateConfig("Spec.Project.Distribution", context.ParseResult.GetValueForOption(_projectDistributionOption));
config.UpdateConfig("Spec.Project.MirrorRegistries", context.ParseResult.GetValueForOption(_projectMirrorRegistriesOption));
config.UpdateConfig("Spec.Project.SecretManager", context.ParseResult.GetValueForOption(_projectSecretManagerOption));
config.UpdateConfig("Spec.Project.Template", context.ParseResult.GetValueForOption(_projectTemplateOption));
config.UpdateConfig("Spec.Project.WorkingDirectory", context.ParseResult.GetValueForOption(_projectWorkingDirectoryOption));

var handler = new KSailInitCommandHandler(config);
Console.WriteLine($"📁 Initializing new cluster '{config.Metadata.Name}' in '{config.Spec.Project.WorkingDirectory}' with the '{config.Spec.Project.Template}' template.");
context.ExitCode = await handler.HandleAsync(context.GetCancellationToken()).ConfigureAwait(false);
Expand All @@ -55,13 +40,6 @@ public KSailInitCommand() : base("init", "Initialize a cluster")

void AddOptions()
{
AddOption(_metadataNameOption);
AddOption(_projectWorkingDirectoryOption);
AddOption(_projectDeploymentToolOption);
AddOption(_projectDistributionOption);
AddOption(_projectMirrorRegistriesOption);
AddOption(_projectSecretManagerOption);
AddOption(_projectTemplateOption);
AddOption(_fluxDeploymentToolPostBuildVariablesOption);
AddOption(_kustomizeTemplateKustomizationHooksOption);
AddOption(_kustomizeTemplateKustomizationsOption);
Expand Down
12 changes: 0 additions & 12 deletions src/KSail/Commands/Init/Options/ProjectTemplateOption.cs

This file was deleted.

13 changes: 2 additions & 11 deletions src/KSail/Commands/Lint/KSailLintCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ namespace KSail.Commands.Lint;
sealed class KSailLintCommand : Command
{
readonly ExceptionHandler _exceptionHandler = new();
readonly MetadataNameOption _nameOption = new() { Arity = ArgumentArity.ZeroOrOne };
readonly PathOption _workingDirectoryOption = new("Path to the working directory for your project") { Arity = ArgumentArity.ZeroOrOne };
internal KSailLintCommand() : base(
internal KSailLintCommand(GlobalOptions globalOptions) : base(
"lint", "Lint manifests for a cluster"
)
{
AddOption(_nameOption);
AddOption(_workingDirectoryOption);
this.SetHandler(async (context) =>
{
try
{
string workingDirectory = context.ParseResult.GetValueForOption(_workingDirectoryOption) ?? Environment.CurrentDirectory;
string? name = context.ParseResult.GetValueForOption(_nameOption);

var config = await KSailClusterConfigLoader.LoadAsync(workingDirectory, name).ConfigureAwait(false);
config.UpdateConfig("Metadata.Name", context.ParseResult.GetValueForOption(_nameOption));
config.UpdateConfig("Spec.Project.WorkingDirectory", workingDirectory);
var config = await KSailClusterConfigLoader.LoadWithGlobalOptionsAsync(globalOptions, context);

Console.WriteLine("🧹 Linting manifest files");
var handler = new KSailLintCommandHandler();
Expand Down
5 changes: 3 additions & 2 deletions src/KSail/Commands/List/KsailListCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.CommandLine;
using KSail.Commands.List.Handlers;
using KSail.Commands.List.Options;
using KSail.Options;
using KSail.Utils;

namespace KSail.Commands.List;
Expand All @@ -9,14 +10,14 @@ sealed class KSailListCommand : Command
{
readonly ExceptionHandler _exceptionHandler = new();
readonly AllOption _allOption = new() { Arity = ArgumentArity.ZeroOrOne };
internal KSailListCommand() : base("list", "List active clusters")
internal KSailListCommand(GlobalOptions globalOptions) : base("list", "List active clusters")
{
AddOption(_allOption);
this.SetHandler(async (context) =>
{
try
{
var config = await KSailClusterConfigLoader.LoadAsync().ConfigureAwait(false);
var config = await KSailClusterConfigLoader.LoadWithGlobalOptionsAsync(globalOptions, context);
config.UpdateConfig("Spec.CLI.List.All", context.ParseResult.GetValueForOption(_allOption));
var cancellationToken = context.GetCancellationToken();
var handler = new KSailListCommandHandler(config);
Expand Down
33 changes: 22 additions & 11 deletions src/KSail/Commands/Root/KSailRootCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.CommandLine;
using System.CommandLine.Parsing;
using KSail.Commands.Debug;
using KSail.Commands.Down;
using KSail.Commands.Gen;
Expand All @@ -11,17 +12,19 @@
using KSail.Commands.Stop;
using KSail.Commands.Up;
using KSail.Commands.Update;
using KSail.Options;
using KSail.Utils;

namespace KSail.Commands.Root;

sealed class KSailRootCommand : RootCommand
{
readonly ExceptionHandler _exceptionHandler = new();
readonly GlobalOptions _globalOptions = new();
internal KSailRootCommand(IConsole console) : base("KSail is an SDK for Kubernetes. Ship k8s with ease!")
{
AddGlobalOptions();
AddCommands(console);

this.SetHandler(async (context) =>
{
try
Expand All @@ -38,18 +41,26 @@ sealed class KSailRootCommand : RootCommand
);
}

internal void AddGlobalOptions()
{
foreach (var option in _globalOptions.Options)
{
AddGlobalOption(option);
}
}

void AddCommands(IConsole console)
{
AddCommand(new KSailUpCommand());
AddCommand(new KSailDownCommand());
AddCommand(new KSailUpdateCommand());
AddCommand(new KSailStartCommand());
AddCommand(new KSailStopCommand());
AddCommand(new KSailInitCommand());
AddCommand(new KSailLintCommand());
AddCommand(new KSailListCommand());
AddCommand(new KSailDebugCommand());
AddCommand(new KSailUpCommand(_globalOptions));
AddCommand(new KSailDownCommand(_globalOptions));
AddCommand(new KSailUpdateCommand(_globalOptions));
AddCommand(new KSailStartCommand(_globalOptions));
AddCommand(new KSailStopCommand(_globalOptions));
AddCommand(new KSailInitCommand(_globalOptions));
AddCommand(new KSailLintCommand(_globalOptions));
AddCommand(new KSailListCommand(_globalOptions));
AddCommand(new KSailDebugCommand(_globalOptions));
AddCommand(new KSailGenCommand(console));
AddCommand(new KSailSecretsCommand());
AddCommand(new KSailSecretsCommand(_globalOptions, console));
}
}
Loading

0 comments on commit 113a254

Please sign in to comment.