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

Function checkOverwrite

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

Source from the content-addressed store, hash-verified

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