From 0f3abe889c509c4b1444fdfb38176d87efc1b0c1 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Tue, 6 Feb 2024 10:23:56 -0800 Subject: [PATCH] Add support for k3s completion subcommand (#10) Signed-off-by: Derek Nola --- Gemfile.lock | 2 +- lib/vagrant-k3s/config.rb | 6 ++++++ lib/vagrant-k3s/provisioner.rb | 12 ++++++++++++ lib/vagrant-k3s/version.rb | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3a83275..1ff2043 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,7 +33,7 @@ GIT PATH remote: . specs: - vagrant-k3s (0.1.8) + vagrant-k3s (0.2.0) GEM remote: https://rubygems.org/ diff --git a/lib/vagrant-k3s/config.rb b/lib/vagrant-k3s/config.rb index 512f4a6..cbd3bea 100644 --- a/lib/vagrant-k3s/config.rb +++ b/lib/vagrant-k3s/config.rb @@ -57,6 +57,10 @@ class Config < Vagrant.plugin(2, :config) # @return [Boolean] attr_accessor :skip_start + # Defaults to false + # @return [Boolean] + attr_accessor :skip_complete + # # INSTALL_K3S_BIN_DIR # # @return [String] # attr_accessor :install_bin_dir @@ -109,6 +113,7 @@ def initialize @env_path = UNSET_VALUE @installer_url = UNSET_VALUE @skip_start = UNSET_VALUE + @skip_complete = UNSET_VALUE end def finalize! @@ -123,6 +128,7 @@ def finalize! @env_path = DEFAULT_ENV_PATH if @env_path == UNSET_VALUE @installer_url = DEFAULT_INSTALLER_URL if @installer_url == UNSET_VALUE @skip_start = false if @skip_start == UNSET_VALUE + @skip_complete = false if @skip_complete == UNSET_VALUE if @args && args_valid? @args = @args.is_a?(Array) ? @args.map { |a| a.to_s } : @args.to_s diff --git a/lib/vagrant-k3s/provisioner.rb b/lib/vagrant-k3s/provisioner.rb index 68cf22a..c014746 100644 --- a/lib/vagrant-k3s/provisioner.rb +++ b/lib/vagrant-k3s/provisioner.rb @@ -79,6 +79,18 @@ def provision outputs.values.map(&:close) end + if not config.skip_complete + outputs, handler = build_outputs + begin + @machine.ui.info 'Enabling K3s autocompletion ...' + @machine.communicate.sudo("k3s completion -i bash", error_key: :ssh_bad_exit_status_muted, &handler) + rescue Vagrant::Errors::VagrantError => e + @machine.ui.detail "#{e.extra_data[:stderr].chomp}", :color => :yellow + ensure + outputs.values.map(&:close) + end + end + begin exe = "k3s" @machine.ui.info 'Checking the K3s version ...' diff --git a/lib/vagrant-k3s/version.rb b/lib/vagrant-k3s/version.rb index fe12894..8a51e68 100644 --- a/lib/vagrant-k3s/version.rb +++ b/lib/vagrant-k3s/version.rb @@ -2,6 +2,6 @@ module VagrantPlugins module K3s - VERSION = '0.1.9' + VERSION = '0.2.0' end end