MCPcopy Create free account
hub / github.com/cli/cli / checkOverwrite

Function checkOverwrite

pkg/cmd/skills/install/install.go:1038–1080  ·  view source on GitHub ↗
(opts *InstallOptions, skills []discovery.Skill, targetDir string, canPrompt bool)

Source from the content-addressed store, hash-verified

1036}
1037
1038func checkOverwrite(opts *InstallOptions, skills []discovery.Skill, targetDir string, canPrompt bool) ([]discovery.Skill, error) {
1039 var existing, fresh []discovery.Skill
1040 for _, s := range skills {
1041 dir := filepath.Join(targetDir, s.Name)
1042 if _, err := os.Stat(dir); err == nil {
1043 existing = append(existing, s)
1044 } else {
1045 fresh = append(fresh, s)
1046 }
1047 }
1048
1049 if len(existing) == 0 {
1050 return skills, nil
1051 }
1052
1053 if opts.Force {
1054 return skills, nil
1055 }
1056
1057 if !canPrompt {
1058 names := make([]string, len(existing))
1059 for i, s := range existing {
1060 names[i] = s.DisplayName()
1061 }
1062 return nil, fmt.Errorf("skills already installed: %s (use --force to overwrite)", strings.Join(names, ", "))
1063 }
1064
1065 var confirmed []discovery.Skill
1066 for _, s := range existing {
1067 prompt := existingSkillPrompt(targetDir, s)
1068 ok, err := opts.Prompter.Confirm(prompt, false)
1069 if err != nil {
1070 return nil, err
1071 }
1072 if ok {
1073 confirmed = append(confirmed, s)
1074 } else {
1075 fmt.Fprintf(opts.IO.ErrOut, "Skipping %s\n", s.DisplayName())
1076 }
1077 }
1078
1079 return append(fresh, confirmed...), nil
1080}
1081
1082func existingSkillPrompt(targetDir string, incoming discovery.Skill) string {
1083 skillFile := filepath.Join(targetDir, incoming.Name, "SKILL.md")

Callers 1

buildInstallPlansFunction · 0.85

Calls 5

existingSkillPromptFunction · 0.85
JoinMethod · 0.80
DisplayNameMethod · 0.65
ErrorfMethod · 0.65
ConfirmMethod · 0.65

Tested by

no test coverage detected