From 67b9801f420ae493fa4d2d5a3d829aaf3517f896 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 30 Nov 2022 22:15:34 -0800 Subject: [PATCH] Add doc comments --- build.go | 6 +++++- cli.go | 3 +++ install.go | 7 +++++++ internal/config/config.go | 2 ++ internal/cpu/cpu.go | 1 + internal/db/db.go | 1 + internal/repos/find.go | 3 +++ internal/types/config.go | 2 ++ internal/types/repo.go | 1 + 9 files changed, 25 insertions(+), 1 deletion(-) diff --git a/build.go b/build.go index 4979b6d..8dfd366 100644 --- a/build.go +++ b/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) diff --git a/cli.go b/cli.go index 07b3f48..4950e21 100644 --- a/cli.go +++ b/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( diff --git a/install.go b/install.go index dad49d6..176c608 100644 --- a/install.go +++ b/install.go @@ -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) diff --git a/internal/config/config.go b/internal/config/config.go index 5548c73..9b6e5c1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 { diff --git a/internal/cpu/cpu.go b/internal/cpu/cpu.go index 6a213ca..e79dddf 100644 --- a/internal/cpu/cpu.go +++ b/internal/cpu/cpu.go @@ -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" { diff --git a/internal/db/db.go b/internal/db/db.go index 1b868b8..5ed31e3 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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"` diff --git a/internal/repos/find.go b/internal/repos/find.go index 2168c34..c33a610 100644 --- a/internal/repos/find.go +++ b/internal/repos/find.go @@ -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) diff --git a/internal/types/config.go b/internal/types/config.go index 663da7a..ec1c80e 100644 --- a/internal/types/config.go +++ b/internal/types/config.go @@ -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"` diff --git a/internal/types/repo.go b/internal/types/repo.go index 2052417..b6d993e 100644 --- a/internal/types/repo.go +++ b/internal/types/repo.go @@ -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"`