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

Method goBinScaffolding

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

Source from the content-addressed store, hash-verified

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