forked from Plemya-x/ALR
		
	Merge pull request 'fix: add auto_req and auto_prov' (#7) from Maks1mS/ALR:fix/make-findprovides-findrequires-optional into master
Reviewed-on: Plemya-x/ALR#7
This commit is contained in:
		@@ -25,12 +25,12 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/mitchellh/mapstructure"
 | 
						"github.com/mitchellh/mapstructure"
 | 
				
			||||||
	"plemya-x.ru/alr/internal/overrides"
 | 
					 | 
				
			||||||
	"plemya-x.ru/alr/pkg/distro"
 | 
					 | 
				
			||||||
	"golang.org/x/exp/slices"
 | 
						"golang.org/x/exp/slices"
 | 
				
			||||||
	"mvdan.cc/sh/v3/expand"
 | 
						"mvdan.cc/sh/v3/expand"
 | 
				
			||||||
	"mvdan.cc/sh/v3/interp"
 | 
						"mvdan.cc/sh/v3/interp"
 | 
				
			||||||
	"mvdan.cc/sh/v3/syntax"
 | 
						"mvdan.cc/sh/v3/syntax"
 | 
				
			||||||
 | 
						"plemya-x.ru/alr/internal/overrides"
 | 
				
			||||||
 | 
						"plemya-x.ru/alr/pkg/distro"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var ErrNotPointerToStruct = errors.New("val must be a pointer to a struct")
 | 
					var ErrNotPointerToStruct = errors.New("val must be a pointer to a struct")
 | 
				
			||||||
@@ -221,3 +221,8 @@ func (d *Decoder) getVar(name string) *expand.Variable {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func IsTruthy(value string) bool {
 | 
				
			||||||
 | 
						value = strings.ToLower(strings.TrimSpace(value))
 | 
				
			||||||
 | 
						return value == "true" || value == "yes" || value == "1"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,6 +49,8 @@ type BuildVars struct {
 | 
				
			|||||||
	Checksums     []string `sh:"checksums"`
 | 
						Checksums     []string `sh:"checksums"`
 | 
				
			||||||
	Backup        []string `sh:"backup"`
 | 
						Backup        []string `sh:"backup"`
 | 
				
			||||||
	Scripts       Scripts  `sh:"scripts"`
 | 
						Scripts       Scripts  `sh:"scripts"`
 | 
				
			||||||
 | 
						AutoReq       []string `sh:"auto_req"`
 | 
				
			||||||
 | 
						AutoProv      []string `sh:"auto_prov"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Scripts struct {
 | 
					type Scripts struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,7 @@ import (
 | 
				
			|||||||
	_ "github.com/goreleaser/nfpm/v2/arch"
 | 
						_ "github.com/goreleaser/nfpm/v2/arch"
 | 
				
			||||||
	_ "github.com/goreleaser/nfpm/v2/deb"
 | 
						_ "github.com/goreleaser/nfpm/v2/deb"
 | 
				
			||||||
	_ "github.com/goreleaser/nfpm/v2/rpm"
 | 
						_ "github.com/goreleaser/nfpm/v2/rpm"
 | 
				
			||||||
 | 
						"go.elara.ws/logger/log"
 | 
				
			||||||
	"mvdan.cc/sh/v3/expand"
 | 
						"mvdan.cc/sh/v3/expand"
 | 
				
			||||||
	"mvdan.cc/sh/v3/interp"
 | 
						"mvdan.cc/sh/v3/interp"
 | 
				
			||||||
	"mvdan.cc/sh/v3/syntax"
 | 
						"mvdan.cc/sh/v3/syntax"
 | 
				
			||||||
@@ -543,15 +544,26 @@ func buildPkgMetadata(ctx context.Context, vars *types.BuildVars, dirs types.Dir
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	pkgInfo.Overridables.Contents = contents
 | 
						pkgInfo.Overridables.Contents = contents
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(vars.AutoProv) == 1 && decoder.IsTruthy(vars.AutoProv[0]) {
 | 
				
			||||||
		if pkgFormat == "rpm" {
 | 
							if pkgFormat == "rpm" {
 | 
				
			||||||
			err = rpmFindProvides(ctx, pkgInfo, dirs)
 | 
								err = rpmFindProvides(ctx, pkgInfo, dirs)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								log.Info("AutoProv is not implemented for this package format, so it's skiped").Send()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(vars.AutoReq) == 1 && decoder.IsTruthy(vars.AutoReq[0]) {
 | 
				
			||||||
 | 
							if pkgFormat == "rpm" {
 | 
				
			||||||
			err = rpmFindRequires(ctx, pkgInfo, dirs)
 | 
								err = rpmFindRequires(ctx, pkgInfo, dirs)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								log.Info("AutoReq is not implemented for this package format, so it's skiped").Send()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return pkgInfo, nil
 | 
						return pkgInfo, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ func rpmFindDependencies(ctx context.Context, pkgInfo *nfpm.Info, dirs types.Dir
 | 
				
			|||||||
	cmd.Stdout = &out
 | 
						cmd.Stdout = &out
 | 
				
			||||||
	cmd.Stderr = &stderr
 | 
						cmd.Stderr = &stderr
 | 
				
			||||||
	if err := cmd.Run(); err != nil {
 | 
						if err := cmd.Run(); err != nil {
 | 
				
			||||||
		log.Error(stderr.String())
 | 
							log.Error(stderr.String()).Send()
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user