Bladeren bron

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

correct documentation on order of editor preference. Use logger for editfn
Jo 2 jaren geleden
bovenliggende
commit
511b95769e
3 gewijzigde bestanden met toevoegingen van 21 en 22 verwijderingen
  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
 .TP
 .B \-\-editor <command>
 .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.
 these are set Yay will prompt the user for an editor.
 
 
 .TP
 .TP

+ 1 - 1
install.go

@@ -291,7 +291,7 @@ func install(ctx context.Context, cfg *settings.Configuration,
 		return err
 		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,
 		cfg.Editor, cfg.EditorFlags, remoteNamesCache, srcinfos,
 		settings.NoConfirm, cfg.AnswerEdit); errEditMenu != nil {
 		settings.NoConfirm, cfg.AnswerEdit); errEditMenu != nil {
 		if errors.As(errEditMenu, &settings.ErrUserAbort{}) {
 		if errors.As(errEditMenu, &settings.ErrUserAbort{}) {

+ 18 - 19
pkg/menus/edit_menu.go

@@ -20,12 +20,12 @@ import (
 )
 )
 
 
 // Editor returns the preferred system editor.
 // 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 {
 	switch {
 	case editorConfig != "":
 	case editorConfig != "":
 		editor, err := exec.LookPath(editorConfig)
 		editor, err := exec.LookPath(editorConfig)
 		if err != nil {
 		if err != nil {
-			fmt.Fprintln(os.Stderr, err)
+			log.Errorln(err)
 		} else {
 		} else {
 			return editor, strings.Fields(editorFlags)
 			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 {
 		if editorArgs := strings.Fields(os.Getenv("VISUAL")); len(editorArgs) != 0 {
 			editor, err := exec.LookPath(editorArgs[0])
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 			} else {
 			} else {
 				return editor, editorArgs[1:]
 				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 {
 		if editorArgs := strings.Fields(os.Getenv("EDITOR")); len(editorArgs) != 0 {
 			editor, err := exec.LookPath(editorArgs[0])
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 			} else {
 			} else {
 				return editor, editorArgs[1:]
 				return editor, editorArgs[1:]
 			}
 			}
@@ -54,16 +54,15 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 
 
 		fallthrough
 		fallthrough
 	default:
 	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 {
 		for {
-			text.Infoln(gotext.Get("Edit PKGBUILD with?"))
+			log.Infoln(gotext.Get("Edit PKGBUILD with?"))
 
 
 			editorInput, err := text.GetInput(os.Stdin, "", noConfirm)
 			editorInput, err := text.GetInput(os.Stdin, "", noConfirm)
 			if err != nil {
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 				continue
 				continue
 			}
 			}
 
 
@@ -74,7 +73,7 @@ func editor(editorConfig, editorFlags string, noConfirm bool) (editor string, ar
 
 
 			editor, err := exec.LookPath(editorArgs[0])
 			editor, err := exec.LookPath(editorArgs[0])
 			if err != nil {
 			if err != nil {
-				fmt.Fprintln(os.Stderr, err)
+				log.Errorln(err)
 				continue
 				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,
 	editorFlags string, srcinfos map[string]*gosrc.Srcinfo, noConfirm bool,
 ) error {
 ) error {
 	pkgbuilds := make([]string, 0, len(bases))
 	pkgbuilds := make([]string, 0, len(bases))
@@ -102,7 +101,7 @@ func editPkgbuilds(pkgbuildDirs map[string]string, bases []string, editorConfig,
 	}
 	}
 
 
 	if len(pkgbuilds) > 0 {
 	if len(pkgbuilds) > 0 {
-		editor, editorArgs := editor(editorConfig, editorFlags, noConfirm)
+		editor, editorArgs := editor(log, editorConfig, editorFlags, noConfirm)
 		editorArgs = append(editorArgs, pkgbuilds...)
 		editorArgs = append(editorArgs, pkgbuilds...)
 		editcmd := exec.Command(editor, editorArgs...)
 		editcmd := exec.Command(editor, editorArgs...)
 		editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
 		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
 	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,
 	editorFlags string, installed mapset.Set[string], srcinfos map[string]*gosrc.Srcinfo,
 	noConfirm bool, editDefaultAnswer string,
 	noConfirm bool, editDefaultAnswer string,
 ) error {
 ) error {
@@ -134,7 +133,7 @@ func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, edit
 		return errMenu
 		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
 		return errEdit
 	}
 	}
 
 
@@ -147,7 +146,7 @@ func Edit(w io.Writer, editMenuOption bool, pkgbuildDirs map[string]string, edit
 	return nil
 	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,
 	pkgbuildDirsByBase map[string]string,
 ) error {
 ) error {
 	if len(pkgbuildDirsByBase) == 0 {
 	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,
 	toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases,
 		mapset.NewThreadUnsafeSet[string](),
 		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 {
 	if errMenu != nil || len(toEdit) == 0 {
 		return errMenu
 		return errMenu
 	}
 	}
 
 
 	// TOFIX: remove or use srcinfo data
 	// 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
 		return errEdit
 	}
 	}
 
 
-	fmt.Println()
+	cfg.Runtime.Logger.Println()
 
 
 	if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
 	if !text.ContinueTask(os.Stdin, gotext.Get("Proceed with install?"), true, false) {
 		return settings.ErrUserAbort{}
 		return settings.ErrUserAbort{}