MCPcopy Index your code
hub / github.com/cli/cli / checkOverwrite

Function checkOverwrite

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

Source from the content-addressed store, hash-verified

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