Class: Harnex::Skills

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/skills.rb

Constant Summary collapse

SKILLS_ROOT =
File.expand_path("../../../../skills", __FILE__)
DEFAULT_SKILL =
"harnex"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Skills

Returns a new instance of Skills.



36
37
38
# File 'lib/harnex/commands/skills.rb', line 36

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.bundled_skill_namesObject



32
33
34
# File 'lib/harnex/commands/skills.rb', line 32

def self.bundled_skill_names
  Dir.children(SKILLS_ROOT).select { |name| File.directory?(File.join(SKILLS_ROOT, name)) }.sort
end

.usageObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/harnex/commands/skills.rb', line 8

def self.usage
  <<~TEXT
    Usage: harnex skills install [SKILL...] [--global]

    Subcommands:
      install     Install bundled skills into the current repo

    Options:
      --global    Install to ~/.claude/skills and ~/.codex/skills
                  instead of the current repo

    Available skills: #{bundled_skill_names.join(', ')}

    With no SKILL argument, installs #{DEFAULT_SKILL.inspect}.
    Pass one or more skill names to install specific skills.

    Without --global, copies the skill to .claude/skills/<skill>/
    in the current repo and symlinks .codex/skills/<skill> to it.

    With --global, symlinks both ~/.claude/skills/<skill> and
    ~/.codex/skills/<skill> to the bundled source.
  TEXT
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/harnex/commands/skills.rb', line 40

def run
  subcommand = @argv.shift
  case subcommand
  when "install"
    skill_names, global, help = parse_install_args(@argv)
    if help
      puts self.class.usage
      return 0
    end

    skill_names.each do |skill_name|
      skill_source = resolve_skill_source(skill_name)
      unless skill_source
        return missing_skill(skill_name)
      end

      result = global ? install_global(skill_name, skill_source) : install_local(skill_name, skill_source)
      return result unless result == 0
    end
    0
  when "-h", "--help", nil
    puts self.class.usage
    0
  else
    warn("harnex skills: unknown subcommand #{subcommand.inspect}")
    puts self.class.usage
    1
  end
end