Add doc comments
This commit is contained in:
parent
89ead2706d
commit
7266b716d1
6
build.go
6
build.go
@ -29,7 +29,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
|
||||||
_ "github.com/goreleaser/nfpm/v2/apk"
|
_ "github.com/goreleaser/nfpm/v2/apk"
|
||||||
_ "github.com/goreleaser/nfpm/v2/arch"
|
_ "github.com/goreleaser/nfpm/v2/arch"
|
||||||
_ "github.com/goreleaser/nfpm/v2/deb"
|
_ "github.com/goreleaser/nfpm/v2/deb"
|
||||||
@ -116,6 +115,8 @@ func buildCmd(c *cli.Context) error {
|
|||||||
return nil
|
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) {
|
func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]string, []string, error) {
|
||||||
info, err := distro.ParseOSRelease(ctx)
|
info, err := distro.ParseOSRelease(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -607,6 +608,8 @@ func getBuildVars(ctx context.Context, script string, info *distro.OSRelease) (*
|
|||||||
return &vars, nil
|
return &vars, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// archMatches checks if your system architecture matches
|
||||||
|
// one of the provided architectures
|
||||||
func archMatches(architectures []string) bool {
|
func archMatches(architectures []string) bool {
|
||||||
if slices.Contains(architectures, "all") {
|
if slices.Contains(architectures, "all") {
|
||||||
return true
|
return true
|
||||||
@ -627,6 +630,7 @@ func setVersion(ctx context.Context, r *interp.Runner, to string) error {
|
|||||||
return r.Run(ctx, fl)
|
return r.Run(ctx, fl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uniq removes all duplicates from string slices
|
||||||
func uniq(ss ...*[]string) {
|
func uniq(ss ...*[]string) {
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
slices.Sort(*s)
|
slices.Sort(*s)
|
||||||
|
3
cli.go
3
cli.go
@ -5,6 +5,8 @@ import (
|
|||||||
"go.arsenm.dev/lure/internal/db"
|
"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) {
|
func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
|
||||||
names := make([]string, len(options))
|
names := make([]string, len(options))
|
||||||
for i, option := range options {
|
for i, option := range options {
|
||||||
@ -30,6 +32,7 @@ func pkgPrompt(options []db.Package, verb string) ([]db.Package, error) {
|
|||||||
return out, nil
|
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) {
|
func yesNoPrompt(msg string, def bool) (bool, error) {
|
||||||
var answer bool
|
var answer bool
|
||||||
err := survey.AskOne(
|
err := survey.AskOne(
|
||||||
|
@ -56,6 +56,8 @@ func installCmd(c *cli.Context) error {
|
|||||||
return nil
|
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) {
|
func installPkgs(ctx context.Context, pkgs []db.Package, notFound []string, mgr manager.Manager) {
|
||||||
if len(notFound) > 0 {
|
if len(notFound) > 0 {
|
||||||
err := mgr.Install(nil, notFound...)
|
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))
|
installScripts(ctx, mgr, getScriptPaths(pkgs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getScriptPaths generates a slice of script paths corresponding to the
|
||||||
|
// given packages
|
||||||
func getScriptPaths(pkgs []db.Package) []string {
|
func getScriptPaths(pkgs []db.Package) []string {
|
||||||
var scripts []string
|
var scripts []string
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
@ -76,6 +80,8 @@ func getScriptPaths(pkgs []db.Package) []string {
|
|||||||
return scripts
|
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 {
|
func flattenFoundPkgs(found map[string][]db.Package, verb string) []db.Package {
|
||||||
var outPkgs []db.Package
|
var outPkgs []db.Package
|
||||||
for _, pkgs := range found {
|
for _, pkgs := range found {
|
||||||
@ -92,6 +98,7 @@ func flattenFoundPkgs(found map[string][]db.Package, verb string) []db.Package {
|
|||||||
return outPkgs
|
return outPkgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// installScripts builds and installs LURE build scripts
|
||||||
func installScripts(ctx context.Context, mgr manager.Manager, scripts []string) {
|
func installScripts(ctx context.Context, mgr manager.Manager, scripts []string) {
|
||||||
for _, script := range scripts {
|
for _, script := range scripts {
|
||||||
builtPkgs, _, err := buildPackage(ctx, script, mgr)
|
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 {
|
func Decode(cfg *types.Config) error {
|
||||||
cfgFl, err := os.Open(ConfigPath)
|
cfgFl, err := os.Open(ConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,6 +44,7 @@ func ARMVariant() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Arch returns the canonical CPU architecture of the system
|
||||||
func Arch() string {
|
func Arch() string {
|
||||||
arch := runtime.GOARCH
|
arch := runtime.GOARCH
|
||||||
if arch == "arm" {
|
if arch == "arm" {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/genjidb/genji/document"
|
"github.com/genjidb/genji/document"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Package is a LURE package's database representation
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Name string `sh:"name,required"`
|
Name string `sh:"name,required"`
|
||||||
Version string `sh:"version,required"`
|
Version string `sh:"version,required"`
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
"go.arsenm.dev/lure/internal/db"
|
"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) {
|
func FindPkgs(gdb *genji.DB, pkgs []string) (map[string][]db.Package, []string, error) {
|
||||||
found := map[string][]db.Package{}
|
found := map[string][]db.Package{}
|
||||||
notFound := []string(nil)
|
notFound := []string(nil)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
// Config represents the LURE configuration file
|
||||||
type Config struct {
|
type Config struct {
|
||||||
RootCmd string `toml:"rootCmd"`
|
RootCmd string `toml:"rootCmd"`
|
||||||
Repos []Repo `toml:"repo"`
|
Repos []Repo `toml:"repo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Repo represents a LURE repo within a configuration file
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
URL string `toml:"url"`
|
URL string `toml:"url"`
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
// RepoConfig represents a LURE repo's lure-repo.toml file.
|
||||||
type RepoConfig struct {
|
type RepoConfig struct {
|
||||||
Repo struct {
|
Repo struct {
|
||||||
MinVersion string `toml:"minVersion"`
|
MinVersion string `toml:"minVersion"`
|
||||||
|
Loading…
Reference in New Issue
Block a user