瀏覽代碼

docs(yay): correct order of editor var evaluation (#2104)

correct documentation on order of editor preference. Use logger for editfn
Jo 2 年之前
父節點
當前提交
511b95769e
共有 3 個文件被更改,包括 21 次插入22 次删除
  1. 2 2
      doc/yay.8
  2. 1 1
      install.go
  3. 18 19
      pkg/menus/edit_menu.go

+ 2 - 2
doc/yay.8

@@ -174,8 +174,8 @@ the AUR cache when deciding if Yay should skip builds.
 
 .TP
 .B \-\-editor <command>
-Editor to use when editing PKGBUILDs. If this is not set the \fBEDITOR\fR
-environment variable will be checked, followed by \fBVISUAL\fR. If none of
+Editor to use when editing PKGBUILDs. If this is not set the \fBVISUAL\fR
+environment variable will be checked, followed by \fBEDITOR\fR. If none of
 these are set Yay will prompt the user for an editor.
 
 .TP

+ 1 - 1
install.go

@@ -291,7 +291,7 @@ func install(ctx context.Context, cfg *settings.Configuration,
 		return err
 	}
 
-	if errEditMenu := menus.Edit(os.Stdout, cfg.EditMenu, pkgbuildDirs,
+	if errEditMenu := menus.Edit(os.Stdout, cfg.Runtime.Logger, cfg.EditMenu, pkgbuildDirs,
 		cfg.Editor, cfg.EditorFlags, remoteNamesCache, srcinfos,
 		settings.NoConfirm, cfg.AnswerEdit); errEditMenu != nil {
 		if errors.As(errEditMenu, &settings.ErrUserAbort{}) {

+ 18 - 19
pkg/menus/edit_menu.go

@@ -20,12 +20,12 @@ import (
 )
 
 // Editor returns the preferred system editor.
-func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, args []string) {
+func editor(log *text.Logger, editorConfig, editorFlags string, noConfirm bool) (editor string, args []string) {
 	switch {
 	case editorConfig != "":
 		editor, err := exec.LookPath(editorConfig)
 		if err != nil {
-			fmt.Fprintln(os.Stderr, err)
+			log.Errorln(err)
 		} else {
 			return editor, strings.Fields(editorFlags)
 		}
@@ -35,7 +35,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 		if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 			} else {
 				return editor, editorArgs[1:]
 			}
@@ -46,7 +46,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 		if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 			} else {
 				return editor, editorArgs[1:]
 			}
@@ -54,16 +54,15 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 
 		fallthrough
 	default:
-		fmt.Fprintln(os.Stderr)
-		text.Errorln(gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
-		text.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
+		log.Errorln("\n", gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
+		log.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
 
 		for {
-			text.Infoln(gotext.Get("Edit PKGBUILD with?"))
+			log.Infoln(gotext.Get("Edit PKGBUILD with?"))
 
 			editorInput, err := text.GetInput(os.Stdin, "", noConfirm)
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 				continue
 			}
 
@@ -74,7 +73,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 				continue
 			}
 
@@ -83,7 +82,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 	}
 }
 
-func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
+func editPkgbuilds(log *text.Logger, pkgbuildDirs map[string]string, bases []string, editorConfig,
 	editorFlags string, srcinfos map[string]*gosrc.Srcinfo, noConfirm bool,
 ) error {
 	pkgbuilds := make([]string, 0, len(bases))
@@ -102,7 +101,7 @@ func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
 	}
 
 	if len(pkgbuilds) > 0 {
-		editor, editorArgs := editor(editorConfig, editorFlags, noConfirm)
+		editor, editorArgs := editor(log, editorConfig, editorFlags, noConfirm)
 		editorArgs = append(editorArgs, pkgbuilds...)
 		editcmd := exec.Command(editor, editorArgs...)
 		editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
@@ -115,7 +114,7 @@ func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
 	return nil
 }
 
-func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, editorConfig,
+func Edit(w io.Writer, log *text.Logger, editMenuOption bool, pkgbuildDirs map[string]string, editorConfig,
 	editorFlags string, installed mapset.Set[string], srcinfos map[string]*gosrc.Srcinfo,
 	noConfirm bool, editDefaultAnswer string,
 ) error {
@@ -134,7 +133,7 @@ func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, edit
 		return errMenu
 	}
 
-	if errEdit := editPkgbuilds(pkgbuildDirs, toEdit, editorConfig, editorFlags, srcinfos, noConfirm); errEdit != nil {
+	if errEdit := editPkgbuilds(log, pkgbuildDirs, toEdit, editorConfig, editorFlags, srcinfos, noConfirm); errEdit != nil {
 		return errEdit
 	}
 
@@ -147,7 +146,7 @@ func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, edit
 	return nil
 }
 
-func EditFn(ctx context.Context, config *settings.Configuration, w io.Writer,
+func EditFn(ctx context.Context, cfg *settings.Configuration, w io.Writer,
 	pkgbuildDirsByBase map[string]string,
 ) error {
 	if len(pkgbuildDirsByBase) == 0 {
@@ -161,18 +160,18 @@ func EditFn(ctx context.Context, config *settings.Configuration, w io.Writer,
 
 	toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases,
 		mapset.NewThreadUnsafeSet[string](),
-		gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, config.AnswerEdit, nil)
+		gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, cfg.AnswerEdit, nil)
 	if errMenu != nil || len(toEdit) == 0 {
 		return errMenu
 	}
 
 	// TOFIX: remove or use srcinfo data
-	if errEdit := editPkgbuilds(pkgbuildDirsByBase,
-		toEdit, config.Editor, config.EditorFlags, nil, settings.NoConfirm); errEdit != nil {
+	if errEdit := editPkgbuilds(cfg.Runtime.Logger, pkgbuildDirsByBase,
+		toEdit, cfg.Editor, cfg.EditorFlags, nil, settings.NoConfirm); errEdit != nil {
 		return errEdit
 	}
 
-	fmt.Println()
+	cfg.Runtime.Logger.Println()
 
 	if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
 		return settings.ErrUserAbort{}