MCPcopy
hub / github.com/cli/cli / goBinScaffolding

Method goBinScaffolding

pkg/cmd/extension/manager.go:665–716  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

663}
664
665func (m *Manager) goBinScaffolding(name string) error {
666 goExe, err := m.lookPath("go")
667 if err != nil {
668 return fmt.Errorf("go is required for creating Go extensions: %w", err)
669 }
670
671 if err := writeFile(filepath.Join(name, ".github", "workflows", "release.yml"), goBinWorkflow, 0644); err != nil {
672 return err
673 }
674
675 mainGo := fmt.Sprintf(mainGoTmpl, name)
676 if err := writeFile(filepath.Join(name, "main.go"), []byte(mainGo), 0644); err != nil {
677 return err
678 }
679
680 host, _ := m.config.Authentication().DefaultHost()
681
682 currentUser, err := api.CurrentLoginName(api.NewClientFromHTTP(m.client), host)
683 if err != nil {
684 return err
685 }
686
687 goCmds := [][]string{
688 {"mod", "init", fmt.Sprintf("%s/%s/%s", host, currentUser, name)},
689 {"mod", "tidy"},
690 {"build"},
691 }
692
693 ignore := fmt.Sprintf("/%[1]s\n/%[1]s.exe\n", name)
694 if err := writeFile(filepath.Join(name, ".gitignore"), []byte(ignore), 0644); err != nil {
695 return err
696 }
697
698 for _, args := range goCmds {
699 goCmd := m.newCommand(goExe, args...)
700 goCmd.Dir = name
701 if err := goCmd.Run(); err != nil {
702 return fmt.Errorf("failed to set up go module: %w", err)
703 }
704 }
705
706 scopedClient := m.gitClient.ForRepo(name)
707 if _, err := scopedClient.CommandOutput([]string{"add", "."}); err != nil {
708 return err
709 }
710
711 if _, err := scopedClient.CommandOutput([]string{"commit", "-m", "initial commit"}); err != nil {
712 return ErrInitialCommitFailed
713 }
714
715 return nil
716}
717
718func isSymlink(m os.FileMode) bool {
719 return m&os.ModeSymlink != 0

Callers 1

CreateMethod · 0.95

Calls 10

CurrentLoginNameFunction · 0.92
NewClientFromHTTPFunction · 0.92
writeFileFunction · 0.85
JoinMethod · 0.80
ErrorfMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65
RunMethod · 0.65
ForRepoMethod · 0.65
CommandOutputMethod · 0.65

Tested by

no test coverage detected