Skip to content

Commit

Permalink
Add support for k3s completion subcommand (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola authored Feb 6, 2024
1 parent d0205bf commit 0f3abe8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GIT
PATH
remote: .
specs:
vagrant-k3s (0.1.8)
vagrant-k3s (0.2.0)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 6 additions & 0 deletions lib/vagrant-k3s/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/vagrant-k3s/provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...'
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-k3s/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module VagrantPlugins
module K3s
VERSION = '0.1.9'
VERSION = '0.2.0'
end
end

0 comments on commit 0f3abe8

Please sign in to comment.