Add doc comments

This commit is contained in:
Arsen Musayelyan 2022-11-30 22:15:34 -08:00
parent 7164aac0b4
commit 67b9801f42
9 changed files with 25 additions and 1 deletions

View File

@ -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
View File

@ -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(

View File

@ -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)

View File

@ -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 {

View File

@ -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" {

View File

@ -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"`

View File

@ -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)

View File

@ -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"`

View File

@ -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"`