Class: ZipSkillInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/default_skills/skill-add/scripts/install_from_zip.rb

Overview

Install a skill from a remote zip archive URL. Usage: ruby install_from_zip.rb <zip_url>

The zip archive is expected to contain a skill directory at its root, e.g.:

my-skill/
  SKILL.md
  scripts/

Or the archive may contain multiple skill directories (each with a SKILL.md).

Constant Summary collapse

ZIP_URL_PATTERN =
%r{^https?://.+\.zip(\?.*)?$}i

Instance Method Summary collapse

Constructor Details

#initialize(zip_source, skill_name: nil, target_dir: nil, skip_if_exists: false) ⇒ ZipSkillInstaller

Returns a new instance of ZipSkillInstaller.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/clacky/default_skills/skill-add/scripts/install_from_zip.rb', line 22

def initialize(zip_source, skill_name: nil, target_dir: nil, skip_if_exists: false)
  @zip_source = zip_source
  @local_path = local_zip_path?(zip_source)
  # skill_name can be provided explicitly (e.g. slug from the store API).
  # If not provided, we try to infer it from the filename in the URL/path, e.g.
  # "ui-ux-pro-max-1.0.0.zip" → "ui-ux-pro-max".
  @skill_name = skill_name || infer_skill_name(zip_source)
  @target_dir = target_dir || File.join(Dir.home, '.clacky', 'skills')
  # When true, existing skill directories are preserved and the install for
  # that specific skill is skipped (recorded in @skipped_skills).
  # Default false keeps the legacy "overwrite" behaviour for `install`.
  @skip_if_exists   = skip_if_exists
  # Suppresses user-facing puts for programmatic callers (set by `perform`).
  @silent           = false
  @installed_skills = []
  @skipped_skills   = []
  @errors           = []
end

Instance Method Details

#installObject

Main installation entry point (CLI). Prints progress, prints a final report, and calls ‘exit` on failure. Use `perform` for programmatic use.



58
59
60
61
62
63
64
65
66
67
# File 'lib/clacky/default_skills/skill-add/scripts/install_from_zip.rb', line 58

def install
  do_install
  report_results
rescue ArgumentError => e
  puts "Error: #{e.message}"
  exit 1
rescue StandardError => e
  puts "Error: Installation failed: #{e.message}"
  exit 1
end

#performObject

Programmatic entry point for library-style callers (e.g. onboard pre-install).

Unlike ‘install`, this method:

- does NOT print user-facing output
- does NOT call `exit` on failure (raises instead)
- returns a result hash: { installed: [...], skipped: [...], errors: [...] }

The caller is responsible for rendering feedback and deciding whether any error is fatal.



50
51
52
53
54
# File 'lib/clacky/default_skills/skill-add/scripts/install_from_zip.rb', line 50

def perform
  @silent = true
  do_install
  { installed: @installed_skills, skipped: @skipped_skills, errors: @errors }
end