mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(install,update,uninstall): add glob pattern matching for skill names
Support glob patterns (*, ?, [...]) in skill name arguments across all three commands. Matching is case-insensitive. - install: --skill and --exclude flags support glob (e.g. -s "core-*") - update: positional names support glob (e.g. update "core-*") - uninstall: positional names support glob (e.g. uninstall "core-*") Shared helpers isGlobPattern() and matchGlob() extracted to helpers.go to avoid duplication. Includes 25 new tests and updated docs.
This commit is contained in:
@@ -4,8 +4,20 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// isGlobPattern returns true if the string contains glob metacharacters.
|
||||
func isGlobPattern(s string) bool {
|
||||
return strings.ContainsAny(s, "*?[")
|
||||
}
|
||||
|
||||
// matchGlob performs a case-insensitive glob match of name against pattern.
|
||||
func matchGlob(pattern, name string) bool {
|
||||
ok, _ := filepath.Match(strings.ToLower(pattern), strings.ToLower(name))
|
||||
return ok
|
||||
}
|
||||
|
||||
// copyDir copies a directory recursively.
|
||||
func copyDir(src, dst string) error {
|
||||
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||
|
||||
@@ -434,8 +434,10 @@ Options:
|
||||
--force, -f Overwrite existing skill; also continue if audit would block
|
||||
--update, -u Update existing (git pull if possible, else reinstall)
|
||||
--track, -t Install as tracked repo (preserves .git for updates)
|
||||
--skill, -s <names> Select specific skills from multi-skill repo (comma-separated)
|
||||
--exclude <names> Skip specific skills during install (comma-separated)
|
||||
--skill, -s <names> Select specific skills from multi-skill repo (comma-separated;
|
||||
supports glob patterns like "core-*", "test-?")
|
||||
--exclude <names> Skip specific skills during install (comma-separated;
|
||||
supports glob patterns like "test-*")
|
||||
--all Install all discovered skills without prompting
|
||||
--yes, -y Auto-accept all prompts (equivalent to --all for multi-skill repos)
|
||||
--dry-run, -n Preview the installation without making changes
|
||||
@@ -460,10 +462,12 @@ Examples:
|
||||
|
||||
Selective install (non-interactive):
|
||||
skillshare install anthropics/skills -s pdf,commit # Specific skills
|
||||
skillshare install anthropics/skills -s "core-*" # Glob pattern
|
||||
skillshare install anthropics/skills --all # All skills
|
||||
skillshare install anthropics/skills -y # Auto-accept
|
||||
skillshare install anthropics/skills -s pdf --dry-run # Preview selection
|
||||
skillshare install repo --all --exclude cli-sentry # All except specific
|
||||
skillshare install repo --all --exclude "test-*" # Exclude by pattern
|
||||
|
||||
Organize into subdirectories:
|
||||
skillshare install anthropics/skills -s pdf --into frontend
|
||||
|
||||
@@ -164,19 +164,37 @@ func selectSkills(skills []install.SkillInfo, opts install.InstallOptions) ([]in
|
||||
}
|
||||
|
||||
// applyExclude removes skills whose names appear in the exclude list.
|
||||
// Supports glob patterns (e.g. "test-*") for pattern-based exclusion.
|
||||
func applyExclude(skills []install.SkillInfo, exclude []string) []install.SkillInfo {
|
||||
excludeSet := make(map[string]bool, len(exclude))
|
||||
// Split into exact names and glob patterns
|
||||
exactSet := make(map[string]bool)
|
||||
var globPatterns []string
|
||||
for _, name := range exclude {
|
||||
excludeSet[name] = true
|
||||
if isGlobPattern(name) {
|
||||
globPatterns = append(globPatterns, name)
|
||||
} else {
|
||||
exactSet[name] = true
|
||||
}
|
||||
}
|
||||
|
||||
var excluded []string
|
||||
filtered := make([]install.SkillInfo, 0, len(skills))
|
||||
for _, s := range skills {
|
||||
if excludeSet[s.Name] {
|
||||
if exactSet[s.Name] {
|
||||
excluded = append(excluded, s.Name)
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, s)
|
||||
var matched bool
|
||||
for _, pattern := range globPatterns {
|
||||
if matchGlob(pattern, s.Name) {
|
||||
excluded = append(excluded, s.Name)
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
filtered = append(filtered, s)
|
||||
}
|
||||
}
|
||||
if len(excluded) > 0 {
|
||||
ui.Info("Excluded %d skill(s): %s", len(excluded), strings.Join(excluded, ", "))
|
||||
@@ -185,7 +203,8 @@ func applyExclude(skills []install.SkillInfo, exclude []string) []install.SkillI
|
||||
}
|
||||
|
||||
// filterSkillsByName matches requested names against discovered skills.
|
||||
// It tries exact match first, then falls back to case-insensitive substring matching.
|
||||
// It tries exact match first, then glob pattern matching (if the name
|
||||
// contains wildcards), then falls back to case-insensitive substring matching.
|
||||
func filterSkillsByName(skills []install.SkillInfo, names []string) (matched []install.SkillInfo, notFound []string) {
|
||||
skillByName := make(map[string]install.SkillInfo, len(skills))
|
||||
for _, s := range skills {
|
||||
@@ -199,6 +218,22 @@ func filterSkillsByName(skills []install.SkillInfo, names []string) (matched []i
|
||||
continue
|
||||
}
|
||||
|
||||
// Try glob pattern matching (e.g. "core-*", "test-?")
|
||||
if isGlobPattern(name) {
|
||||
var globMatches []install.SkillInfo
|
||||
for _, s := range skills {
|
||||
if matchGlob(name, s.Name) {
|
||||
globMatches = append(globMatches, s)
|
||||
}
|
||||
}
|
||||
if len(globMatches) > 0 {
|
||||
matched = append(matched, globMatches...)
|
||||
continue
|
||||
}
|
||||
notFound = append(notFound, name)
|
||||
continue
|
||||
}
|
||||
|
||||
// Fall back to case-insensitive substring match
|
||||
nameLower := strings.ToLower(name)
|
||||
var candidates []install.SkillInfo
|
||||
|
||||
@@ -88,6 +88,183 @@ func TestFilterSkillsByName_ExactTakesPriority(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Glob matching tests ---
|
||||
|
||||
func TestFilterSkillsByName_GlobWildcard(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "core-auth", Path: "core-auth"},
|
||||
{Name: "core-db", Path: "core-db"},
|
||||
{Name: "utils", Path: "utils"},
|
||||
}
|
||||
|
||||
matched, notFound := filterSkillsByName(skills, []string{"core-*"})
|
||||
if len(notFound) > 0 {
|
||||
t.Errorf("unexpected notFound: %v", notFound)
|
||||
}
|
||||
if len(matched) != 2 {
|
||||
t.Fatalf("expected 2 glob matches, got %d: %v", len(matched), matched)
|
||||
}
|
||||
names := map[string]bool{}
|
||||
for _, m := range matched {
|
||||
names[m.Name] = true
|
||||
}
|
||||
if !names["core-auth"] || !names["core-db"] {
|
||||
t.Errorf("expected core-auth and core-db, got %v", matched)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSkillsByName_GlobQuestionMark(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "test-a", Path: "test-a"},
|
||||
{Name: "test-b", Path: "test-b"},
|
||||
{Name: "test-ab", Path: "test-ab"},
|
||||
}
|
||||
|
||||
matched, notFound := filterSkillsByName(skills, []string{"test-?"})
|
||||
if len(notFound) > 0 {
|
||||
t.Errorf("unexpected notFound: %v", notFound)
|
||||
}
|
||||
if len(matched) != 2 {
|
||||
t.Fatalf("expected 2 matches (test-a, test-b), got %d", len(matched))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSkillsByName_GlobCaseInsensitive(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "Core-Auth", Path: "Core-Auth"},
|
||||
{Name: "core-db", Path: "core-db"},
|
||||
}
|
||||
|
||||
matched, notFound := filterSkillsByName(skills, []string{"core-*"})
|
||||
if len(notFound) > 0 {
|
||||
t.Errorf("unexpected notFound: %v", notFound)
|
||||
}
|
||||
if len(matched) != 2 {
|
||||
t.Fatalf("expected 2 case-insensitive glob matches, got %d", len(matched))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSkillsByName_GlobNoMatch(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "figma", Path: "figma"},
|
||||
{Name: "pdf", Path: "pdf"},
|
||||
}
|
||||
|
||||
matched, notFound := filterSkillsByName(skills, []string{"core-*"})
|
||||
if len(matched) != 0 {
|
||||
t.Errorf("expected no matches, got %v", matched)
|
||||
}
|
||||
if len(notFound) != 1 || notFound[0] != "core-*" {
|
||||
t.Errorf("expected notFound=[core-*], got %v", notFound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSkillsByName_GlobStarAll(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "a", Path: "a"},
|
||||
{Name: "b", Path: "b"},
|
||||
}
|
||||
|
||||
matched, notFound := filterSkillsByName(skills, []string{"*"})
|
||||
if len(notFound) > 0 {
|
||||
t.Errorf("unexpected notFound: %v", notFound)
|
||||
}
|
||||
if len(matched) != 2 {
|
||||
t.Errorf("glob '*' should match all skills, got %d", len(matched))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSkillsByName_ExactTakesPriorityOverGlob(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "core-*", Path: "core-*"},
|
||||
{Name: "core-auth", Path: "core-auth"},
|
||||
}
|
||||
|
||||
// If a skill is literally named "core-*", exact match wins
|
||||
matched, notFound := filterSkillsByName(skills, []string{"core-*"})
|
||||
if len(notFound) > 0 {
|
||||
t.Errorf("unexpected notFound: %v", notFound)
|
||||
}
|
||||
if len(matched) != 1 || matched[0].Name != "core-*" {
|
||||
t.Errorf("exact match should take priority over glob, got %v", matched)
|
||||
}
|
||||
}
|
||||
|
||||
// --- applyExclude glob tests ---
|
||||
|
||||
func TestApplyExclude_GlobPattern(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "keep-a", Path: "keep-a"},
|
||||
{Name: "test-one", Path: "test-one"},
|
||||
{Name: "test-two", Path: "test-two"},
|
||||
}
|
||||
|
||||
filtered := applyExclude(skills, []string{"test-*"})
|
||||
if len(filtered) != 1 {
|
||||
t.Fatalf("expected 1 remaining skill, got %d: %v", len(filtered), filtered)
|
||||
}
|
||||
if filtered[0].Name != "keep-a" {
|
||||
t.Errorf("expected keep-a, got %s", filtered[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyExclude_MixedExactAndGlob(t *testing.T) {
|
||||
skills := []install.SkillInfo{
|
||||
{Name: "keep", Path: "keep"},
|
||||
{Name: "drop-a", Path: "drop-a"},
|
||||
{Name: "drop-b", Path: "drop-b"},
|
||||
{Name: "extra", Path: "extra"},
|
||||
}
|
||||
|
||||
filtered := applyExclude(skills, []string{"extra", "drop-*"})
|
||||
if len(filtered) != 1 {
|
||||
t.Fatalf("expected 1 remaining skill, got %d: %v", len(filtered), filtered)
|
||||
}
|
||||
if filtered[0].Name != "keep" {
|
||||
t.Errorf("expected keep, got %s", filtered[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
// --- isGlobPattern / matchGlob tests ---
|
||||
|
||||
func TestIsGlobPattern(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want bool
|
||||
}{
|
||||
{"core-*", true},
|
||||
{"test-?", true},
|
||||
{"[abc]", true},
|
||||
{"plain-name", false},
|
||||
{"", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := isGlobPattern(tt.input); got != tt.want {
|
||||
t.Errorf("isGlobPattern(%q) = %v, want %v", tt.input, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchGlob(t *testing.T) {
|
||||
tests := []struct {
|
||||
pattern, name string
|
||||
want bool
|
||||
}{
|
||||
{"core-*", "core-auth", true},
|
||||
{"core-*", "CORE-AUTH", true},
|
||||
{"CORE-*", "core-auth", true},
|
||||
{"test-?", "test-a", true},
|
||||
{"test-?", "test-ab", false},
|
||||
{"*", "anything", true},
|
||||
{"no-match", "something", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := matchGlob(tt.pattern, tt.name); got != tt.want {
|
||||
t.Errorf("matchGlob(%q, %q) = %v, want %v", tt.pattern, tt.name, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeInstallAuditThreshold(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
|
||||
@@ -154,6 +154,31 @@ func resolveUninstallTarget(skillName string, cfg *config.Config) (*uninstallTar
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveUninstallByGlob scans the source directory for top-level entries
|
||||
// whose names match the given glob pattern (e.g. "core-*", "_team-?").
|
||||
func resolveUninstallByGlob(pattern string, cfg *config.Config) ([]*uninstallTarget, error) {
|
||||
entries, err := os.ReadDir(cfg.Source)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot read source directory: %w", err)
|
||||
}
|
||||
|
||||
var targets []*uninstallTarget
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() {
|
||||
continue
|
||||
}
|
||||
if matchGlob(pattern, e.Name()) {
|
||||
skillPath := filepath.Join(cfg.Source, e.Name())
|
||||
targets = append(targets, &uninstallTarget{
|
||||
name: e.Name(),
|
||||
path: skillPath,
|
||||
isTrackedRepo: install.IsGitRepo(skillPath),
|
||||
})
|
||||
}
|
||||
}
|
||||
return targets, nil
|
||||
}
|
||||
|
||||
// resolveGroupSkills finds all skills under a group directory (prefix match).
|
||||
// Returns uninstallTargets for each skill found.
|
||||
func resolveGroupSkills(group, sourceDir string) ([]*uninstallTarget, error) {
|
||||
@@ -553,6 +578,27 @@ func cmdUninstall(args []string) error {
|
||||
}
|
||||
|
||||
for _, name := range opts.skillNames {
|
||||
// Glob pattern matching (e.g. "core-*", "_team-?")
|
||||
if isGlobPattern(name) {
|
||||
globMatches, globErr := resolveUninstallByGlob(name, cfg)
|
||||
if globErr != nil {
|
||||
resolveWarnings = append(resolveWarnings, fmt.Sprintf("%s: %v", name, globErr))
|
||||
continue
|
||||
}
|
||||
if len(globMatches) == 0 {
|
||||
resolveWarnings = append(resolveWarnings, fmt.Sprintf("%s: no skills match pattern", name))
|
||||
continue
|
||||
}
|
||||
ui.Info("Pattern '%s' matched %d item(s)", name, len(globMatches))
|
||||
for _, t := range globMatches {
|
||||
if !seen[t.path] {
|
||||
seen[t.path] = true
|
||||
targets = append(targets, t)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
t, err := resolveUninstallTarget(name, cfg)
|
||||
if err != nil {
|
||||
resolveWarnings = append(resolveWarnings, fmt.Sprintf("%s: %v", name, err))
|
||||
@@ -1008,6 +1054,8 @@ For tracked repositories (_repo-name):
|
||||
- Automatically removes the entry from .gitignore
|
||||
- The _ prefix is optional (automatically detected)
|
||||
|
||||
Skill names support glob patterns (e.g. "core-*", "test-?").
|
||||
|
||||
Options:
|
||||
--all Remove ALL skills from source (requires confirmation)
|
||||
--group, -G <name> Remove all skills in a group (prefix match, repeatable)
|
||||
@@ -1020,6 +1068,7 @@ Options:
|
||||
Examples:
|
||||
skillshare uninstall my-skill # Remove a single skill
|
||||
skillshare uninstall a b c --force # Remove multiple skills at once
|
||||
skillshare uninstall "core-*" # Remove all matching a glob pattern
|
||||
skillshare uninstall --all # Remove all skills
|
||||
skillshare uninstall --all --force # Remove all without confirmation
|
||||
skillshare uninstall --all -n # Preview what would be removed
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
)
|
||||
|
||||
// --- resolveUninstallByGlob tests ---
|
||||
|
||||
func TestResolveUninstallByGlob_MatchesDirs(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
for _, name := range []string{"core-auth", "core-db", "utils"} {
|
||||
os.MkdirAll(filepath.Join(src, name), 0755)
|
||||
}
|
||||
|
||||
cfg := &config.Config{Source: src}
|
||||
targets, err := resolveUninstallByGlob("core-*", cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets) != 2 {
|
||||
t.Fatalf("expected 2 matches, got %d", len(targets))
|
||||
}
|
||||
names := map[string]bool{}
|
||||
for _, tgt := range targets {
|
||||
names[tgt.name] = true
|
||||
}
|
||||
if !names["core-auth"] || !names["core-db"] {
|
||||
t.Errorf("expected core-auth and core-db, got %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUninstallByGlob_DetectsTrackedRepos(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
// Tracked repo (has .git)
|
||||
repoDir := filepath.Join(src, "_team-skills")
|
||||
os.MkdirAll(filepath.Join(repoDir, ".git"), 0755)
|
||||
// Regular skill
|
||||
os.MkdirAll(filepath.Join(src, "_team-docs"), 0755)
|
||||
|
||||
cfg := &config.Config{Source: src}
|
||||
targets, err := resolveUninstallByGlob("_team-*", cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets) != 2 {
|
||||
t.Fatalf("expected 2 matches, got %d", len(targets))
|
||||
}
|
||||
for _, tgt := range targets {
|
||||
if tgt.name == "_team-skills" && !tgt.isTrackedRepo {
|
||||
t.Error("_team-skills should be detected as tracked repo")
|
||||
}
|
||||
if tgt.name == "_team-docs" && tgt.isTrackedRepo {
|
||||
t.Error("_team-docs should not be detected as tracked repo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUninstallByGlob_CaseInsensitive(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(src, "Core-Auth"), 0755)
|
||||
os.MkdirAll(filepath.Join(src, "core-db"), 0755)
|
||||
|
||||
cfg := &config.Config{Source: src}
|
||||
targets, err := resolveUninstallByGlob("core-*", cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets) != 2 {
|
||||
t.Fatalf("expected 2 case-insensitive matches, got %d", len(targets))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUninstallByGlob_NoMatch(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(src, "utils"), 0755)
|
||||
|
||||
cfg := &config.Config{Source: src}
|
||||
targets, err := resolveUninstallByGlob("core-*", cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets) != 0 {
|
||||
t.Errorf("expected 0 matches, got %d", len(targets))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUninstallByGlob_SkipsFiles(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(src, "core-skill"), 0755)
|
||||
os.WriteFile(filepath.Join(src, "core-file.txt"), []byte("not a dir"), 0644)
|
||||
|
||||
cfg := &config.Config{Source: src}
|
||||
targets, err := resolveUninstallByGlob("core-*", cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets) != 1 {
|
||||
t.Fatalf("expected 1 match (dirs only), got %d", len(targets))
|
||||
}
|
||||
if targets[0].name != "core-skill" {
|
||||
t.Errorf("expected core-skill, got %s", targets[0].name)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify unused imports are referenced
|
||||
var _ = install.IsGitRepo
|
||||
@@ -189,6 +189,27 @@ func cmdUpdate(args []string) error {
|
||||
} else {
|
||||
// Resolve by specific names/groups
|
||||
for _, name := range opts.names {
|
||||
// Glob pattern matching (e.g. "core-*", "_team-?")
|
||||
if isGlobPattern(name) {
|
||||
globMatches, globErr := resolveByGlob(cfg.Source, name)
|
||||
if globErr != nil {
|
||||
resolveWarnings = append(resolveWarnings, fmt.Sprintf("%s: %v", name, globErr))
|
||||
continue
|
||||
}
|
||||
if len(globMatches) == 0 {
|
||||
resolveWarnings = append(resolveWarnings, fmt.Sprintf("%s: no skills match pattern", name))
|
||||
continue
|
||||
}
|
||||
ui.Info("Pattern '%s' matched %d item(s)", name, len(globMatches))
|
||||
for _, m := range globMatches {
|
||||
if !seen[m.name] {
|
||||
seen[m.name] = true
|
||||
targets = append(targets, m)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if isGroupDir(name, cfg.Source) {
|
||||
groupMatches, groupErr := resolveGroupUpdatable(name, cfg.Source)
|
||||
if groupErr != nil {
|
||||
@@ -388,6 +409,7 @@ Use --force to discard local changes and update.
|
||||
|
||||
Arguments:
|
||||
name... Skill name(s) or tracked repo name(s)
|
||||
Supports glob patterns (e.g. "core-*", "_team-?")
|
||||
|
||||
Options:
|
||||
--all, -a Update all tracked repos + skills with metadata
|
||||
@@ -408,6 +430,7 @@ Options:
|
||||
Examples:
|
||||
skillshare update my-skill # Update single skill from source
|
||||
skillshare update a b c # Update multiple skills at once
|
||||
skillshare update "core-*" # Update all matching a glob pattern
|
||||
skillshare update --group frontend # Update all skills in frontend/
|
||||
skillshare update x -G backend # Mix names and groups
|
||||
skillshare update _team-skills # Update tracked repo (git pull)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"skillshare/internal/install"
|
||||
@@ -53,6 +54,30 @@ func resolveByBasename(sourceDir, name string) (updateTarget, error) {
|
||||
return updateTarget{}, fmt.Errorf("%s", strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
// resolveByGlob searches tracked repos and updatable skills whose basenames
|
||||
// match the given glob pattern (e.g. "core-*", "_team-?"). Returns all matches
|
||||
// sorted by name.
|
||||
func resolveByGlob(sourceDir, pattern string) ([]updateTarget, error) {
|
||||
var matches []updateTarget
|
||||
|
||||
repos, _ := install.GetTrackedRepos(sourceDir)
|
||||
for _, r := range repos {
|
||||
if matchGlob(pattern, filepath.Base(r)) {
|
||||
matches = append(matches, updateTarget{name: r, path: filepath.Join(sourceDir, r), isRepo: true})
|
||||
}
|
||||
}
|
||||
|
||||
skills, _ := install.GetUpdatableSkills(sourceDir)
|
||||
for _, s := range skills {
|
||||
if matchGlob(pattern, filepath.Base(s)) {
|
||||
matches = append(matches, updateTarget{name: s, path: filepath.Join(sourceDir, s), isRepo: false})
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(matches, func(i, j int) bool { return matches[i].name < matches[j].name })
|
||||
return matches, nil
|
||||
}
|
||||
|
||||
// resolveGroupUpdatable finds all updatable items (tracked repos or skills with
|
||||
// metadata) under a group directory. Local skills without metadata are skipped.
|
||||
func resolveGroupUpdatable(group, sourceDir string) ([]updateTarget, error) {
|
||||
|
||||
@@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/audit"
|
||||
"skillshare/internal/install"
|
||||
)
|
||||
|
||||
func TestIsSecurityError(t *testing.T) {
|
||||
@@ -70,3 +73,107 @@ func TestParseUpdateArgs_InvalidThreshold(t *testing.T) {
|
||||
t.Fatal("expected showHelp=false on invalid threshold")
|
||||
}
|
||||
}
|
||||
|
||||
// --- resolveByGlob tests ---
|
||||
|
||||
// setupTrackedRepo creates a fake tracked repo (_-prefixed dir with .git).
|
||||
func setupTrackedRepo(t *testing.T, sourceDir, name string) {
|
||||
t.Helper()
|
||||
repoDir := filepath.Join(sourceDir, name)
|
||||
os.MkdirAll(filepath.Join(repoDir, ".git"), 0755)
|
||||
os.WriteFile(filepath.Join(repoDir, "SKILL.md"), []byte("# "+name), 0644)
|
||||
}
|
||||
|
||||
// setupUpdatableSkill creates a skill with .skillshare-meta.json containing a Source.
|
||||
func setupUpdatableSkill(t *testing.T, sourceDir, name string) {
|
||||
t.Helper()
|
||||
dir := filepath.Join(sourceDir, name)
|
||||
os.MkdirAll(dir, 0755)
|
||||
os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("# "+name), 0644)
|
||||
install.WriteMeta(dir, &install.SkillMeta{Source: "github.com/test/" + name, Type: "github"})
|
||||
}
|
||||
|
||||
func TestResolveByGlob_MatchesTrackedRepos(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
setupTrackedRepo(t, src, "_team-auth")
|
||||
setupTrackedRepo(t, src, "_team-db")
|
||||
setupTrackedRepo(t, src, "_other-repo")
|
||||
|
||||
matches, err := resolveByGlob(src, "_team-*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(matches) != 2 {
|
||||
t.Fatalf("expected 2 matches, got %d", len(matches))
|
||||
}
|
||||
for _, m := range matches {
|
||||
if !m.isRepo {
|
||||
t.Errorf("%s should be marked as repo", m.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveByGlob_MatchesUpdatableSkills(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
setupUpdatableSkill(t, src, "core-auth")
|
||||
setupUpdatableSkill(t, src, "core-db")
|
||||
setupUpdatableSkill(t, src, "utils")
|
||||
|
||||
matches, err := resolveByGlob(src, "core-*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(matches) != 2 {
|
||||
t.Fatalf("expected 2 matches, got %d", len(matches))
|
||||
}
|
||||
for _, m := range matches {
|
||||
if m.isRepo {
|
||||
t.Errorf("%s should not be marked as repo", m.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveByGlob_CaseInsensitive(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
setupUpdatableSkill(t, src, "Core-Auth")
|
||||
setupUpdatableSkill(t, src, "core-db")
|
||||
|
||||
matches, err := resolveByGlob(src, "CORE-*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(matches) != 2 {
|
||||
t.Fatalf("expected 2 case-insensitive matches, got %d", len(matches))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveByGlob_NoMatch(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
setupUpdatableSkill(t, src, "utils")
|
||||
|
||||
matches, err := resolveByGlob(src, "core-*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(matches) != 0 {
|
||||
t.Errorf("expected 0 matches, got %d", len(matches))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveByGlob_SortedByName(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
setupUpdatableSkill(t, src, "z-skill")
|
||||
setupUpdatableSkill(t, src, "a-skill")
|
||||
setupUpdatableSkill(t, src, "m-skill")
|
||||
|
||||
matches, err := resolveByGlob(src, "*-skill")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(matches) != 3 {
|
||||
t.Fatalf("expected 3 matches, got %d", len(matches))
|
||||
}
|
||||
if matches[0].name > matches[1].name || matches[1].name > matches[2].name {
|
||||
t.Errorf("results not sorted: %s, %s, %s", matches[0].name, matches[1].name, matches[2].name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,12 +119,15 @@ skillshare install anthropics/skills --dry-run
|
||||
|
||||
## Selective Install (Non-Interactive)
|
||||
|
||||
Pick specific skills from a multi-skill repo without prompts. The `--skill` flag supports **fuzzy matching** — if an exact name isn't found, it falls back to the closest match:
|
||||
Pick specific skills from a multi-skill repo without prompts. The `--skill` flag supports **fuzzy matching** and **glob patterns** — if an exact name isn't found, it tries glob matching (`*`, `?`, `[...]`), then falls back to the closest substring match:
|
||||
|
||||
```bash
|
||||
# Install specific skills by name (exact or fuzzy)
|
||||
skillshare install anthropics/skills -s pdf,commit
|
||||
|
||||
# Install skills matching a glob pattern
|
||||
skillshare install anthropics/skills -s "core-*"
|
||||
|
||||
# Install all discovered skills
|
||||
skillshare install anthropics/skills --all
|
||||
|
||||
@@ -136,6 +139,8 @@ skillshare install anthropics/skills -s pdf --dry-run
|
||||
skillshare install anthropics/skills --all -p
|
||||
```
|
||||
|
||||
Glob matching is case-insensitive: `"Core-*"` matches `core-auth`, `CORE-DB`, etc.
|
||||
|
||||
Useful for CI/CD pipelines and scripted workflows.
|
||||
|
||||
## Direct Install (Specific Path)
|
||||
@@ -244,8 +249,8 @@ See [Project Setup](/docs/how-to/sharing/project-setup) for the full guide.
|
||||
| `--force` | `-f` | Overwrite existing skill; override audit blocking and cross-path duplicate check |
|
||||
| `--update` | `-u` | Update if exists (git pull or reinstall) |
|
||||
| `--track` | `-t` | Keep `.git` for tracked repos |
|
||||
| `--skill` | `-s` | Select specific skills from multi-skill repo (comma-separated) |
|
||||
| `--exclude` | | Skip specific skills during install (comma-separated names) |
|
||||
| `--skill` | `-s` | Select specific skills from multi-skill repo (comma-separated; supports glob patterns like `core-*`) |
|
||||
| `--exclude` | | Skip specific skills during install (comma-separated; supports glob patterns like `test-*`) |
|
||||
| `--all` | | Install all discovered skills without prompting |
|
||||
| `--yes` | `-y` | Auto-accept all prompts (CI/CD friendly) |
|
||||
| `--skip-audit` | | Skip security audit for this install |
|
||||
@@ -521,12 +526,15 @@ Recommended usage:
|
||||
|
||||
### `--exclude` flag
|
||||
|
||||
Skip specific skills when installing from a multi-skill repo:
|
||||
Skip specific skills when installing from a multi-skill repo. Supports both exact names and **glob patterns**:
|
||||
|
||||
```bash
|
||||
# Install all except specific skills
|
||||
skillshare install anthropics/skills --all --exclude cli-sentry,delayed-command
|
||||
|
||||
# Exclude by glob pattern
|
||||
skillshare install anthropics/skills --all --exclude "test-*"
|
||||
|
||||
# Works with -y too
|
||||
skillshare install org/skills -y --exclude internal-tool
|
||||
|
||||
|
||||
@@ -56,6 +56,18 @@ skillshare uninstall alpha beta gamma --force
|
||||
|
||||
When some skills are not found, the command **skips them with a warning** and continues removing the rest. It only fails if **all** specified skills are invalid.
|
||||
|
||||
### Glob Patterns
|
||||
|
||||
Skill names support glob patterns (`*`, `?`, `[...]`) for batch removal:
|
||||
|
||||
```bash
|
||||
skillshare uninstall "core-*" # Remove all skills matching core-*
|
||||
skillshare uninstall "test-?" --force # Single-character wildcard
|
||||
skillshare uninstall "core-*" "util-*" # Multiple patterns
|
||||
```
|
||||
|
||||
Glob matching is case-insensitive: `"Core-*"` matches `core-auth`, `CORE-DB`, etc.
|
||||
|
||||
## Remove All
|
||||
|
||||
Use `--all` to remove every skill from the source directory at once:
|
||||
|
||||
@@ -78,6 +78,22 @@ skillshare update skill-a skill-b skill-c
|
||||
|
||||
Only updatable skills (tracked repos or skills with metadata) are processed. Skills not found are warned but don't cause failure. However, if any skill is **blocked by the security audit gate**, the batch command exits with a non-zero code.
|
||||
|
||||
### Glob Patterns
|
||||
|
||||
Skill names support glob patterns (`*`, `?`, `[...]`) for batch operations:
|
||||
|
||||
```bash
|
||||
skillshare update "core-*" # Update all skills matching core-*
|
||||
skillshare update "_team-?" # Single-character wildcard
|
||||
skillshare update "core-*" "util-*" # Multiple patterns
|
||||
```
|
||||
|
||||
Glob matching is case-insensitive: `"Core-*"` matches `core-auth`, `CORE-DB`, etc.
|
||||
|
||||
:::tip Shell glob protection
|
||||
Always quote glob patterns (`"core-*"`) to prevent your shell from expanding `*` into file names in the current directory.
|
||||
:::
|
||||
|
||||
## Update Group
|
||||
|
||||
Update all updatable skills within a group directory:
|
||||
|
||||
Reference in New Issue
Block a user