Compare commits
2 Commits
7164aac0b4
...
b4f4633f6a
Author | SHA1 | Date | |
---|---|---|---|
b4f4633f6a | |||
67b9801f42 |
6
build.go
6
build.go
@ -29,7 +29,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
_ "github.com/goreleaser/nfpm/v2/apk"
|
||||
_ "github.com/goreleaser/nfpm/v2/arch"
|
||||
_ "github.com/goreleaser/nfpm/v2/deb"
|
||||
@ -116,6 +115,8 @@ func buildCmd(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// buildPackage builds the script at the given path. It returns two slices. One contains the paths
|
||||
// to the built package(s), the other contains the names of the built package(s).
|
||||
func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]string, []string, error) {
|
||||
info, err := distro.ParseOSRelease(ctx)
|
||||
if err != nil {
|
||||
@ -607,6 +608,8 @@ func getBuildVars(ctx context.Context, script string, info *distro.OSRelease) (*
|
||||
return &vars, nil
|
||||
}
|
||||
|
||||
// archMatches checks if your system architecture matches
|
||||
// one of the provided architectures
|
||||
func archMatches(architectures []string) bool {
|
||||
if slices.Contains(architectures, "all") {
|
||||
return true
|
||||
@ -627,6 +630,7 @@ func setVersion(ctx context.Context, r *interp.Runner, to string) error {
|
||||
return r.Run(ctx, fl)
|
||||
}
|
||||
|
||||
// uniq removes all duplicates from string slices
|
||||
func uniq(ss ...*[]string) {
|
||||
for _, s := range ss {
|
||||
slices.Sort(*s)
|
||||
|
3
cli.go
3
cli.go
@ -5,6 +5,8 @@ import (
|
||||
"go.arsenm.dev/lure/internal/db"
|
||||
)
|
||||
|
||||
// pkgPrompt asks the user to choose between multiple packages.
|
||||
// The user may choose multiple packages.
|
||||
func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
|
||||
names := make([]string, len(options))
|
||||
for i, option := range options {
|
||||
@ -30,6 +32,7 @@ func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// yesNoPrompt asks the user a yes or no question, using def as the default answer
|
||||
func yesNoPrompt(msg string, def bool) (bool, error) {
|
||||
var answer bool
|
||||
err := survey.AskOne(
|
||||
|
@ -56,6 +56,8 @@ func installCmd(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// installPkgs installs non-LURE packages via the package manager, then builds and installs LURE
|
||||
// packages
|
||||
func installPkgs(ctx context.Context, pkgs []db.Package, notFound []string, mgr manager.Manager) {
|
||||
if len(notFound) > 0 {
|
||||
err := mgr.Install(nil, notFound...)
|
||||
@ -67,6 +69,8 @@ func installPkgs(ctx context.Context, pkgs []db.Package, notFound []string, mgr
|
||||
installScripts(ctx, mgr, getScriptPaths(pkgs))
|
||||
}
|
||||
|
||||
// getScriptPaths generates a slice of script paths corresponding to the
|
||||
// given packages
|
||||
func getScriptPaths(pkgs []db.Package) []string {
|
||||
var scripts []string
|
||||
for _, pkg := range pkgs {
|
||||
@ -76,6 +80,8 @@ func getScriptPaths(pkgs []db.Package) []string {
|
||||
return scripts
|
||||
}
|
||||
|
||||
// flattenFoundPkgs attempts to flatten the map of slices of packages into a single slice
|
||||
// of packages by prompting the users if multiple packages match.
|
||||
func flattenFoundPkgs(found map[string][]db.Package, verb string) []db.Package {
|
||||
var outPkgs []db.Package
|
||||
for _, pkgs := range found {
|
||||
@ -92,6 +98,7 @@ func flattenFoundPkgs(found map[string][]db.Package, verb string) []db.Package {
|
||||
return outPkgs
|
||||
}
|
||||
|
||||
// installScripts builds and installs LURE build scripts
|
||||
func installScripts(ctx context.Context, mgr manager.Manager, scripts []string) {
|
||||
for _, script := range scripts {
|
||||
builtPkgs, _, err := buildPackage(ctx, script, mgr)
|
||||
|
@ -17,6 +17,8 @@ var defaultConfig = types.Config{
|
||||
},
|
||||
}
|
||||
|
||||
// Decode decodes the config file into the given
|
||||
// pointer
|
||||
func Decode(cfg *types.Config) error {
|
||||
cfgFl, err := os.Open(ConfigPath)
|
||||
if err != nil {
|
||||
|
@ -44,6 +44,7 @@ func ARMVariant() string {
|
||||
}
|
||||
}
|
||||
|
||||
// Arch returns the canonical CPU architecture of the system
|
||||
func Arch() string {
|
||||
arch := runtime.GOARCH
|
||||
if arch == "arm" {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/genjidb/genji/document"
|
||||
)
|
||||
|
||||
// Package is a LURE package's database representation
|
||||
type Package struct {
|
||||
Name string `sh:"name,required"`
|
||||
Version string `sh:"version,required"`
|
||||
@ -17,9 +18,9 @@ type Package struct {
|
||||
Licenses []string `sh:"license"`
|
||||
Provides []string `sh:"provides"`
|
||||
Conflicts []string `sh:"conflicts"`
|
||||
Replaces []string `sh:"replaces"`
|
||||
Depends map[string][]string
|
||||
BuildDepends map[string][]string
|
||||
Replaces []string `sh:"replaces"`
|
||||
Repository string
|
||||
}
|
||||
|
||||
@ -27,10 +28,22 @@ type Package struct {
|
||||
func Init(db *genji.DB) error {
|
||||
return db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS pkgs (
|
||||
name TEXT,
|
||||
name TEXT NOT NULL,
|
||||
repository TEXT NOT NULL,
|
||||
UNIQUE(name, repository),
|
||||
...
|
||||
version TEXT NOT NULL,
|
||||
release INT NOT NULL,
|
||||
epoch INT,
|
||||
description TEXT,
|
||||
homepage TEXT,
|
||||
maintainer TEXT,
|
||||
architectures ARRAY,
|
||||
licenses ARRAY,
|
||||
provides ARRAY,
|
||||
conflicts ARRAY,
|
||||
replaces ARRAY,
|
||||
depends (...),
|
||||
builddepends (...),
|
||||
UNIQUE(name, repository)
|
||||
);
|
||||
`)
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
"go.arsenm.dev/lure/internal/db"
|
||||
)
|
||||
|
||||
// FindPkgs looks for packages matching the inputs inside the database.
|
||||
// It returns a map that maps the package name input to the packages found for it.
|
||||
// It also returns a slice that contains the names of all packages that were not found.
|
||||
func FindPkgs(gdb *genji.DB, pkgs []string) (map[string][]db.Package, []string, error) {
|
||||
found := map[string][]db.Package{}
|
||||
notFound := []string(nil)
|
||||
|
@ -1,10 +1,12 @@
|
||||
package types
|
||||
|
||||
// Config represents the LURE configuration file
|
||||
type Config struct {
|
||||
RootCmd string `toml:"rootCmd"`
|
||||
Repos []Repo `toml:"repo"`
|
||||
}
|
||||
|
||||
// Repo represents a LURE repo within a configuration file
|
||||
type Repo struct {
|
||||
Name string `toml:"name"`
|
||||
URL string `toml:"url"`
|
||||
|
@ -1,5 +1,6 @@
|
||||
package types
|
||||
|
||||
// RepoConfig represents a LURE repo's lure-repo.toml file.
|
||||
type RepoConfig struct {
|
||||
Repo struct {
|
||||
MinVersion string `toml:"minVersion"`
|
||||
|
Loading…
Reference in New Issue
Block a user