Class: Renuo::Cli::Commands::SetupAutocompletion

Inherits:
Object
  • Object
show all
Includes:
CommandHelper
Defined in:
lib/renuo/cli/commands/setup_autocompletion.rb

Constant Summary collapse

COMPLETION_DIR =
File.expand_path("~/.zfunc")
COMPLETION_FILENAME =
"_renuo"
COMPLETION_FILE_PATH =
File.join(COMPLETION_DIR, COMPLETION_FILENAME)
VERSION_STAMP_PREFIX =
"# renuo-cli-version: "

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommandHelper

#open_path, #run_command

Class Method Details

.refresh_if_staleObject



22
23
24
25
26
27
# File 'lib/renuo/cli/commands/setup_autocompletion.rb', line 22

def self.refresh_if_stale
  return unless File.exist?(COMPLETION_FILE_PATH)
  return if File.foreach(COMPLETION_FILE_PATH).first(2).last&.include?("#{VERSION_STAMP_PREFIX}#{Renuo::Cli::VERSION}")

  new.write_completion_file(silent: true)
end

Instance Method Details

#runObject



29
30
31
32
# File 'lib/renuo/cli/commands/setup_autocompletion.rb', line 29

def run
  write_completion_file
  print_installation_instructions
end

#write_completion_file(silent: false) ⇒ Object



34
35
36
37
38
39
# File 'lib/renuo/cli/commands/setup_autocompletion.rb', line 34

def write_completion_file(silent: false)
  say "Setting up zsh autocompletion for renuo-cli...".colorize(:green) unless silent
  FileUtils.mkdir_p(COMPLETION_DIR)
  File.write(COMPLETION_FILE_PATH, stamped_script)
  say "✓ Completion script installed to #{COMPLETION_FILE_PATH}".colorize(:green) unless silent
end