mirror of
https://github.com/Jguer/yay
synced 2024-10-01 13:53:32 +00:00
feat(yay): skip confirmed confirms (#2107)
* skip pacman confirmations when yay confirmations are done * default to double confirm * fix tests
This commit is contained in:
parent
c7a51a1614
commit
88008e4eb3
|
@ -29,6 +29,8 @@ type (
|
|||
targetMode parser.TargetMode
|
||||
downloadOnly bool
|
||||
log *text.Logger
|
||||
|
||||
manualConfirmRequired bool
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -37,14 +39,15 @@ func NewInstaller(dbExecutor db.Executor,
|
|||
downloadOnly bool, logger *text.Logger,
|
||||
) *Installer {
|
||||
return &Installer{
|
||||
dbExecutor: dbExecutor,
|
||||
postInstallHooks: []PostInstallHookFunc{},
|
||||
failedAndIgnored: map[string]error{},
|
||||
exeCmd: exeCmd,
|
||||
vcsStore: vcsStore,
|
||||
targetMode: targetMode,
|
||||
downloadOnly: downloadOnly,
|
||||
log: logger,
|
||||
dbExecutor: dbExecutor,
|
||||
postInstallHooks: []PostInstallHookFunc{},
|
||||
failedAndIgnored: map[string]error{},
|
||||
exeCmd: exeCmd,
|
||||
vcsStore: vcsStore,
|
||||
targetMode: targetMode,
|
||||
downloadOnly: downloadOnly,
|
||||
log: logger,
|
||||
manualConfirmRequired: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +86,10 @@ func (installer *Installer) Install(ctx context.Context,
|
|||
targets []map[string]*dep.InstallInfo,
|
||||
pkgBuildDirs map[string]string,
|
||||
excluded []string,
|
||||
manualConfirmRequired bool,
|
||||
) error {
|
||||
installer.log.Debugln("manualConfirmRequired:", manualConfirmRequired)
|
||||
installer.manualConfirmRequired = manualConfirmRequired
|
||||
// Reorganize targets into layers of dependencies
|
||||
var errMulti multierror.MultiError
|
||||
for i := len(targets) - 1; i >= 0; i-- {
|
||||
|
@ -117,6 +123,10 @@ func mergeLayers(layer1, layer2 map[string]*dep.InstallInfo) map[string]*dep.Ins
|
|||
return layer1
|
||||
}
|
||||
|
||||
func (installer *Installer) appendNoConfirm() bool {
|
||||
return !installer.manualConfirmRequired || settings.NoConfirm
|
||||
}
|
||||
|
||||
func (installer *Installer) handleLayer(ctx context.Context,
|
||||
cmdArgs *parser.Arguments,
|
||||
layer map[string]*dep.InstallInfo,
|
||||
|
@ -165,16 +175,17 @@ func (installer *Installer) handleLayer(ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
text.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
|
||||
installer.log.Debugln("syncDeps", syncDeps, "SyncExp", syncExp,
|
||||
"aurDeps", aurDeps, "aurExp", aurExp, "upgrade", upgradeSync)
|
||||
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp, excluded, upgradeSync)
|
||||
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp,
|
||||
excluded, upgradeSync, installer.appendNoConfirm())
|
||||
if errShow != nil {
|
||||
return ErrInstallRepoPkgs
|
||||
}
|
||||
|
||||
errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp,
|
||||
nameToBaseMap, pkgBuildDirs, true, lastLayer)
|
||||
nameToBaseMap, pkgBuildDirs, true, lastLayer, installer.appendNoConfirm())
|
||||
|
||||
return errAur
|
||||
}
|
||||
|
@ -185,6 +196,7 @@ func (installer *Installer) installAURPackages(ctx context.Context,
|
|||
nameToBase, pkgBuildDirsByBase map[string]string,
|
||||
installIncompatible bool,
|
||||
lastLayer bool,
|
||||
noConfirm bool,
|
||||
) error {
|
||||
all := aurDepNames.Union(aurExpNames).ToSlice()
|
||||
if len(all) == 0 {
|
||||
|
@ -232,7 +244,8 @@ func (installer *Installer) installAURPackages(ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode, installer.vcsStore, cmdArgs, pkgArchives); err != nil {
|
||||
if err := installPkgArchive(ctx, installer.exeCmd, installer.targetMode,
|
||||
installer.vcsStore, cmdArgs, pkgArchives, noConfirm); err != nil {
|
||||
return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v", pkgArchives), err)
|
||||
}
|
||||
|
||||
|
@ -361,6 +374,7 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
|
|||
syncExp mapset.Set[string], // repo targets that are exp
|
||||
excluded []string,
|
||||
upgrade bool, // run even without targets
|
||||
noConfirm bool,
|
||||
) error {
|
||||
repoTargets := syncDeps.Union(syncExp).ToSlice()
|
||||
if len(repoTargets) == 0 && !upgrade {
|
||||
|
@ -379,7 +393,7 @@ func (installer *Installer) installSyncPackages(ctx context.Context, cmdArgs *pa
|
|||
}
|
||||
|
||||
errShow := installer.exeCmd.Show(installer.exeCmd.BuildPacmanCmd(ctx,
|
||||
arguments, installer.targetMode, settings.NoConfirm))
|
||||
arguments, installer.targetMode, noConfirm))
|
||||
|
||||
if errD := asdeps(ctx, installer.exeCmd, installer.targetMode, cmdArgs, syncDeps.ToSlice()); errD != nil {
|
||||
return errD
|
||||
|
|
|
@ -155,7 +155,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
|
@ -417,7 +417,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
|
|||
"jellyfin": tmpDirJfin,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
|
@ -600,7 +600,7 @@ func TestInstaller_CompileFailed(t *testing.T) {
|
|||
"yay": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
if tc.wantErrInstall {
|
||||
require.Error(td, errI)
|
||||
} else {
|
||||
|
@ -757,7 +757,7 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
|
|||
"jellyfin": tmpDir,
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
|
@ -907,7 +907,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{})
|
||||
errI := installer.Install(context.Background(), cmdArgs, targets, pkgBuildDirs, []string{}, false)
|
||||
require.NoError(td, errI)
|
||||
|
||||
require.Len(td, mockRunner.ShowCalls, len(tc.wantShow))
|
||||
|
|
1
cmd.go
1
cmd.go
|
@ -418,7 +418,6 @@ func displayNumberMenu(ctx context.Context, cfg *settings.Configuration, pkgS []
|
|||
}
|
||||
|
||||
// modify the arguments to pass for the install
|
||||
cmdArgs.Op = "S"
|
||||
cmdArgs.Targets = targets
|
||||
|
||||
if len(cmdArgs.Targets) == 0 {
|
||||
|
|
|
@ -649,7 +649,7 @@ func buildInstallPkgbuilds(
|
|||
if !satisfied || !cfg.BatchInstall {
|
||||
text.Debugln("non batch installing archives:", pkgArchives)
|
||||
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder,
|
||||
cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
|
||||
cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives, settings.NoConfirm)
|
||||
errReason := setInstallReason(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cmdArgs, deps, exp)
|
||||
|
||||
deps = make([]string, 0)
|
||||
|
@ -802,7 +802,8 @@ func buildInstallPkgbuilds(
|
|||
}
|
||||
|
||||
text.Debugln("installing archives:", pkgArchives)
|
||||
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cfg.Runtime.VCSStore, cmdArgs, pkgArchives)
|
||||
errArchive := installPkgArchive(ctx, cfg.Runtime.CmdBuilder, cfg.Mode, cfg.Runtime.VCSStore,
|
||||
cmdArgs, pkgArchives, settings.NoConfirm)
|
||||
if errArchive != nil {
|
||||
go cfg.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
|
||||
}
|
||||
|
@ -823,6 +824,7 @@ func installPkgArchive(ctx context.Context,
|
|||
vcsStore vcs.Store,
|
||||
cmdArgs *parser.Arguments,
|
||||
pkgArchives []string,
|
||||
noConfirm bool,
|
||||
) error {
|
||||
if len(pkgArchives) == 0 {
|
||||
return nil
|
||||
|
@ -845,7 +847,7 @@ func installPkgArchive(ctx context.Context,
|
|||
arguments.AddTarget(pkgArchives...)
|
||||
|
||||
if errShow := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
||||
arguments, mode, settings.NoConfirm)); errShow != nil {
|
||||
arguments, mode, noConfirm)); errShow != nil {
|
||||
return errShow
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ type Configuration struct {
|
|||
NewInstallEngine bool `json:"newinstallengine"`
|
||||
Debug bool `json:"debug"`
|
||||
UseRPC bool `json:"rpc"`
|
||||
DoubleConfirm bool `json:"doubleconfirm"` // confirm install before and after build
|
||||
|
||||
CompletionPath string `json:"-"`
|
||||
VCSFilePath string `json:"-"`
|
||||
|
@ -239,6 +240,7 @@ func DefaultConfig(version string) *Configuration {
|
|||
Version: version,
|
||||
Debug: false,
|
||||
UseRPC: true,
|
||||
DoubleConfirm: true,
|
||||
Runtime: &Runtime{
|
||||
Logger: text.GlobalLogger,
|
||||
},
|
||||
|
|
10
sync.go
10
sync.go
|
@ -123,8 +123,7 @@ func (o *OperationService) Run(ctx context.Context,
|
|||
return errInstall
|
||||
}
|
||||
|
||||
cleanFunc := preparer.ShouldCleanMakeDeps(cmdArgs)
|
||||
if cleanFunc != nil {
|
||||
if cleanFunc := preparer.ShouldCleanMakeDeps(cmdArgs); cleanFunc != nil {
|
||||
installer.AddPostInstallHook(cleanFunc)
|
||||
}
|
||||
|
||||
|
@ -158,7 +157,8 @@ func (o *OperationService) Run(ctx context.Context,
|
|||
return errPGP
|
||||
}
|
||||
|
||||
if errInstall := installer.Install(ctx, cmdArgs, targets, pkgBuildDirs, excluded); errInstall != nil {
|
||||
if errInstall := installer.Install(ctx, cmdArgs, targets, pkgBuildDirs,
|
||||
excluded, o.manualConfirmRequired(cmdArgs)); errInstall != nil {
|
||||
return errInstall
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,10 @@ func (o *OperationService) Run(ctx context.Context,
|
|||
return multiErr.Return()
|
||||
}
|
||||
|
||||
func (o *OperationService) manualConfirmRequired(cmdArgs *parser.Arguments) bool {
|
||||
return (!cmdArgs.ExistsArg("u", "sysupgrade") && cmdArgs.Op != "Y") || o.cfg.DoubleConfirm
|
||||
}
|
||||
|
||||
func confirmIncompatible(incompatible []string) error {
|
||||
if len(incompatible) > 0 {
|
||||
text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
|
||||
|
|
|
@ -513,6 +513,7 @@ pkgname = python-vosk
|
|||
}
|
||||
|
||||
cfg := &settings.Configuration{
|
||||
DoubleConfirm: true,
|
||||
NewInstallEngine: true,
|
||||
RemoveMake: "no",
|
||||
BuildDir: tmpDir,
|
||||
|
|
Loading…
Reference in a new issue