From 24ad32a4235560f4dc41312ac55d980be8831bfd Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 28 Sep 2022 16:13:50 -0500 Subject: [PATCH 1/2] Add notes to installation Signed-off-by: jolheiser --- cmd/add/add.go | 18 +++++++++++++- cmd/add/install_pkg.go | 49 ++++++++++++++++++++------------------ cmd/dev/bintest/bintest.go | 4 ++-- cmd/group/add/group_add.go | 21 ++++++++++++---- cmd/search/search.go | 19 ++++++++++++--- pkgparse/parser.go | 6 +++-- schema/pkg_schema.json | 8 +++++++ 7 files changed, 90 insertions(+), 35 deletions(-) diff --git a/cmd/add/add.go b/cmd/add/add.go index a847daf..99ac680 100644 --- a/cmd/add/add.go +++ b/cmd/add/add.go @@ -12,6 +12,7 @@ import ( "github.com/candrewlee14/webman/config" "github.com/candrewlee14/webman/multiline" + "github.com/candrewlee14/webman/pkgparse" "github.com/candrewlee14/webman/utils" "github.com/fatih/color" @@ -60,7 +61,22 @@ webman add go@18.0.0 zig@9.1.0 rg@13.0.0`, } } } - if !InstallAllPkgs(cfg.PkgRepos, args) { + pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] + pkgs := InstallAllPkgs(cfg.PkgRepos, args) + for _, pkg := range pkgs { + note := pkg.Note + osNote := pkg.OsMap[pkgOS].Note + if note != "" || osNote != "" { + color.Blue("== %s", pkg.Title) + } + if note != "" { + color.Yellow(note) + } + if osNote != "" { + color.Yellow(osNote) + } + } + if len(args) != len(pkgs) { return errors.New("Not all packages installed successfully") } color.Green("All %d packages are installed!", len(args)) diff --git a/cmd/add/install_pkg.go b/cmd/add/install_pkg.go index bdc4535..c05cae2 100644 --- a/cmd/add/install_pkg.go +++ b/cmd/add/install_pkg.go @@ -18,11 +18,11 @@ import ( "github.com/fatih/color" ) -func InstallAllPkgs(pkgRepos []*config.PkgRepo, args []string) bool { +func InstallAllPkgs(pkgRepos []*config.PkgRepo, args []string) []*pkgparse.PkgConfig { var wg sync.WaitGroup ml := multiline.New(len(args), os.Stdout) wg.Add(len(args)) - results := make(chan bool, len(args)) + results := make(chan *pkgparse.PkgConfig, len(args)) for i, arg := range args { i := i arg := arg @@ -32,19 +32,22 @@ func InstallAllPkgs(pkgRepos []*config.PkgRepo, args []string) bool { }() } wg.Wait() - success := true + pkgs := make([]*pkgparse.PkgConfig, 0, len(args)) for i := 0; i < len(args); i++ { - success = success && <-results + res := <-results + if res != nil { + pkgs = append(pkgs, res) + } } - return success + return pkgs } -func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount int, wg *sync.WaitGroup, ml *multiline.MultiLogger) bool { +func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount int, wg *sync.WaitGroup, ml *multiline.MultiLogger) *pkgparse.PkgConfig { defer wg.Done() pkg, ver, err := utils.ParsePkgVer(arg) if err != nil { ml.Printf(argIndex, color.RedString(err.Error())) - return false + return nil } if len(ver) == 0 { ml.SetPrefix(argIndex, color.CyanString(pkg)+": ") @@ -61,13 +64,13 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i foundRecipe <- true if err != nil { ml.Printf(argIndex, color.RedString("%v", err)) - return false + return nil } pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] for _, ignorePair := range pkgConf.Ignore { if pkgOS == ignorePair.Os && utils.GOARCH == ignorePair.Arch { ml.Printf(argIndex, color.RedString("unsupported OS + Arch for this package")) - return false + return nil } } if len(ver) == 0 || pkgConf.ForceLatest { @@ -81,12 +84,12 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i foundLatest <- true if err != nil { ml.Printf(argIndex, color.RedString("unable to find latest version tag: %v", err)) - return false + return nil } if pkgConf.ForceLatest && len(ver) != 0 && *verPtr != ver { ml.Printf(argIndex, color.RedString("This package requires using the latest version, which is currently %s", color.MagentaString(*verPtr))) - return false + return nil } ver = *verPtr ml.Printf(argIndex, "Found %s version tag: %s", color.CyanString(pkg), color.MagentaString(ver)) @@ -94,7 +97,7 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i stemPtr, extPtr, urlPtr, err := pkgConf.GetAssetStemExtUrl(ver) if err != nil { ml.Printf(argIndex, color.RedString("%v", err)) - return false + return nil } stem := *stemPtr ext := *extPtr @@ -112,10 +115,10 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i // If file exists if _, err := os.Stat(extractPath); !os.IsNotExist(err) { ml.Printf(argIndex, color.HiBlackString("Already installed!")) - return true + return pkgConf } if !DownloadUrl(url, downloadPath, pkg, ver, argIndex, argCount, ml) { - return false + return nil } var isRawBinary bool if m, ok := pkgConf.OsMap[pkgOS]; ok { @@ -124,11 +127,11 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i if isRawBinary { if err = os.Chmod(downloadPath, 0o755); err != nil { ml.Printf(argIndex, color.RedString("Failed to make download executable!")) - return false + return nil } if err = os.MkdirAll(extractPath, os.ModePerm); err != nil { ml.Printf(argIndex, color.RedString("Failed to create package-version path!")) - return false + return nil } binPath := filepath.Join(extractPath, pkgConf.Title) if utils.GOOS == "windows" { @@ -136,7 +139,7 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i } if err = os.Rename(downloadPath, binPath); err != nil { ml.Printf(argIndex, color.RedString("Failed to rename temporary download to new path!")) - return false + return nil } } else { hasUnpacked := make(chan bool) @@ -154,7 +157,7 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i if err != nil { ml.Printf(argIndex, color.RedString("%v", err)) cleanUpFailedInstall(pkg, extractPath) - return false + return nil } ml.Printf(argIndex, "Completed unpacking %s@%s", color.CyanString(pkg), color.MagentaString(ver)) } @@ -168,23 +171,23 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i if err != nil { cleanUpFailedInstall(pkg, extractPath) ml.Printf(argIndex, color.RedString("%v", err)) - return false + return nil } renames, err := pkgConf.GetRenames() if err != nil { ml.Printf(argIndex, color.RedString("Failed creating links: %v", err)) - return false + return nil } madeLinks, err := link.CreateLinks(pkg, ver, binPaths, renames) if err != nil { cleanUpFailedInstall(pkg, extractPath) ml.Printf(argIndex, color.RedString("Failed creating links: %v", err)) - return false + return nil } if !madeLinks { cleanUpFailedInstall(pkg, extractPath) ml.Printf(argIndex, color.RedString("Failed creating links")) - return false + return nil } ml.Printf(argIndex, "Now using %s@%s", color.CyanString(pkg), color.MagentaString(ver)) } @@ -192,5 +195,5 @@ func InstallPkg(pkgRepos []*config.PkgRepo, arg string, argIndex int, argCount i if p, err := exec.LookPath(pkg); err == nil && !strings.Contains(p, utils.WebmanBinDir) { ml.Printf(argIndex, color.YellowString("Found another binary at %q that may interfere", p)) } - return true + return pkgConf } diff --git a/cmd/dev/bintest/bintest.go b/cmd/dev/bintest/bintest.go index 38a7909..788e110 100644 --- a/cmd/dev/bintest/bintest.go +++ b/cmd/dev/bintest/bintest.go @@ -44,7 +44,7 @@ The "bintest" tests that binary paths given in a package recipe have valid binar return err } pkg := args[0] - var pairResults map[string]bool = map[string]bool{} + pairResults := make(map[string]bool) if err := check.CheckPkgConfig(pkg); err != nil { color.Red("Pkg Config Error: %v", err) } @@ -86,7 +86,7 @@ The "bintest" tests that binary paths given in a package recipe have valid binar var wg sync.WaitGroup ml := multiline.New(len(args), os.Stdout) wg.Add(1) - pairResults[osPairStr] = add.InstallPkg(cfg.PkgRepos, pkg+"@"+*latestVer, 0, 1, &wg, &ml) + pairResults[osPairStr] = add.InstallPkg(cfg.PkgRepos, pkg+"@"+*latestVer, 0, 1, &wg, &ml) != nil relbinPaths, err := pkgConf.GetMyBinPaths() if err != nil { diff --git a/cmd/group/add/group_add.go b/cmd/group/add/group_add.go index ef7bdab..721864d 100644 --- a/cmd/group/add/group_add.go +++ b/cmd/group/add/group_add.go @@ -3,7 +3,6 @@ package add import ( "errors" "fmt" - "os" "github.com/candrewlee14/webman/cmd/add" "github.com/candrewlee14/webman/config" @@ -84,9 +83,23 @@ The "group add" subcommand installs a group of packages. if len(pkgsToInstall) == 0 { color.HiBlack("No packages selected for installation.") } else { - if !add.InstallAllPkgs(cfg.PkgRepos, pkgsToInstall) { - color.Magenta("Not all packages installed successfully") - os.Exit(1) + pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] + pkgs := add.InstallAllPkgs(cfg.PkgRepos, pkgsToInstall) + for _, pkg := range pkgs { + note := pkg.Note + osNote := pkg.OsMap[pkgOS].Note + if note != "" || osNote != "" { + color.Blue("== %s", pkg.Title) + } + if note != "" { + color.Yellow(note) + } + if osNote != "" { + color.Yellow(osNote) + } + } + if len(pkgs) != len(pkgsToInstall) { + return errors.New("Not all packages installed successfully") } color.Green("All %d selected packages from group %s are installed", len(pkgsToInstall), color.YellowString(group)) } diff --git a/cmd/search/search.go b/cmd/search/search.go index f285dd4..a3a770c 100644 --- a/cmd/search/search.go +++ b/cmd/search/search.go @@ -94,9 +94,9 @@ The "search" subcommand starts an interactive window to find and display info ab color.HiBlack("No package selected.") return nil } - pkg := pkgInfos[idx].Title + pkgName := pkgInfos[idx].Title prompt := &survey.Confirm{ - Message: "Would you like to install the latest version of " + color.CyanString(pkg) + "?", + Message: "Would you like to install the latest version of " + color.CyanString(pkgName) + "?", } shouldInstall := false if err := survey.AskOne(prompt, &shouldInstall); err != nil || !shouldInstall { @@ -106,9 +106,22 @@ The "search" subcommand starts an interactive window to find and display info ab var wg sync.WaitGroup ml := multiline.New(1, os.Stdout) wg.Add(1) - if !add.InstallPkg(cfg.PkgRepos, pkg, 0, 1, &wg, &ml) { + pkg := add.InstallPkg(cfg.PkgRepos, pkgName, 0, 1, &wg, &ml) + if pkg == nil { return errors.New("failed to install pkg") } + pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] + note := pkg.Note + osNote := pkg.OsMap[pkgOS].Note + if note != "" || osNote != "" { + color.Blue("== %s", pkg.Title) + } + if note != "" { + color.Yellow(note) + } + if osNote != "" { + color.Yellow(osNote) + } return nil }, } diff --git a/pkgparse/parser.go b/pkgparse/parser.go index dc6fc94..8f0cb0b 100644 --- a/pkgparse/parser.go +++ b/pkgparse/parser.go @@ -32,6 +32,7 @@ type OsInfo struct { IsRawBinary bool `yaml:"is_raw_binary"` FilenameFormatOverride string `yaml:"filename_format_override"` Renames []RenameItem `yaml:"renames"` + Note string `yaml:"note"` } type OsArchPair struct { @@ -40,9 +41,10 @@ type OsArchPair struct { } type PkgConfig struct { - Title string + Title string `yaml:"-"` Tagline string About string + Note string InfoUrl string `yaml:"info_url"` ReleasesUrl string `yaml:"releases_url"` @@ -252,7 +254,7 @@ func ParseVersion(versionStr string, versionFmt string) (*string, error) { return &matchedVer[1], nil } -/// +// / func (pkgConf *PkgConfig) GetAssetStemExtUrl(version string) (*string, *string, *string, error) { pkgOs, exists := GOOStoPkgOs[utils.GOOS] if !exists { diff --git a/schema/pkg_schema.json b/schema/pkg_schema.json index 5ab9a81..352604c 100644 --- a/schema/pkg_schema.json +++ b/schema/pkg_schema.json @@ -23,6 +23,10 @@ "description": "Package description", "type": "string" }, + "note": { + "description": "Installation notes for this package", + "type": "string" + }, "info_url": { "description": "URL for information/documentation", "type": "string" @@ -281,6 +285,10 @@ } } + }, + "note": { + "description": "Installation notes for this OS", + "type": "string" } } } From 479c339ccdb172fc664d8100e1e7bb4f29223f82 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 28 Sep 2022 16:52:52 -0500 Subject: [PATCH 2/2] Update for install vs remove notes Signed-off-by: jolheiser --- cmd/add/add.go | 14 +-------- cmd/group/add/group_add.go | 13 +------- cmd/group/remove/group_remove.go | 1 + cmd/remove/remove.go | 1 + cmd/search/search.go | 13 +------- pkgparse/parser.go | 51 ++++++++++++++++++++++++++++---- schema/pkg_schema.json | 12 ++++++-- 7 files changed, 60 insertions(+), 45 deletions(-) diff --git a/cmd/add/add.go b/cmd/add/add.go index 99ac680..d1ba06b 100644 --- a/cmd/add/add.go +++ b/cmd/add/add.go @@ -12,7 +12,6 @@ import ( "github.com/candrewlee14/webman/config" "github.com/candrewlee14/webman/multiline" - "github.com/candrewlee14/webman/pkgparse" "github.com/candrewlee14/webman/utils" "github.com/fatih/color" @@ -61,20 +60,9 @@ webman add go@18.0.0 zig@9.1.0 rg@13.0.0`, } } } - pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] pkgs := InstallAllPkgs(cfg.PkgRepos, args) for _, pkg := range pkgs { - note := pkg.Note - osNote := pkg.OsMap[pkgOS].Note - if note != "" || osNote != "" { - color.Blue("== %s", pkg.Title) - } - if note != "" { - color.Yellow(note) - } - if osNote != "" { - color.Yellow(osNote) - } + fmt.Print(pkg.InstallNotes()) } if len(args) != len(pkgs) { return errors.New("Not all packages installed successfully") diff --git a/cmd/group/add/group_add.go b/cmd/group/add/group_add.go index 721864d..13f2f2e 100644 --- a/cmd/group/add/group_add.go +++ b/cmd/group/add/group_add.go @@ -83,20 +83,9 @@ The "group add" subcommand installs a group of packages. if len(pkgsToInstall) == 0 { color.HiBlack("No packages selected for installation.") } else { - pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] pkgs := add.InstallAllPkgs(cfg.PkgRepos, pkgsToInstall) for _, pkg := range pkgs { - note := pkg.Note - osNote := pkg.OsMap[pkgOS].Note - if note != "" || osNote != "" { - color.Blue("== %s", pkg.Title) - } - if note != "" { - color.Yellow(note) - } - if osNote != "" { - color.Yellow(osNote) - } + fmt.Print(pkg.InstallNotes()) } if len(pkgs) != len(pkgsToInstall) { return errors.New("Not all packages installed successfully") diff --git a/cmd/group/remove/group_remove.go b/cmd/group/remove/group_remove.go index 2282040..3d8ed8c 100644 --- a/cmd/group/remove/group_remove.go +++ b/cmd/group/remove/group_remove.go @@ -60,6 +60,7 @@ The "group remove" subcommand removes a group of packages. return err } if removed { + fmt.Print(pkgConf.RemoveNotes()) fmt.Println("Removed", color.CyanString(pkg)) } else { color.HiBlack("%s was not previously installed", pkg) diff --git a/cmd/remove/remove.go b/cmd/remove/remove.go index f25c9bb..73f9168 100644 --- a/cmd/remove/remove.go +++ b/cmd/remove/remove.go @@ -93,6 +93,7 @@ webman remove rg`, } } } + fmt.Print(pkgConf.RemoveNotes()) fmt.Printf("All %d selected packages are uninstalled.\n", len(pkgVerStems)) return nil }, diff --git a/cmd/search/search.go b/cmd/search/search.go index a3a770c..545a646 100644 --- a/cmd/search/search.go +++ b/cmd/search/search.go @@ -110,18 +110,7 @@ The "search" subcommand starts an interactive window to find and display info ab if pkg == nil { return errors.New("failed to install pkg") } - pkgOS := pkgparse.GOOStoPkgOs[utils.GOOS] - note := pkg.Note - osNote := pkg.OsMap[pkgOS].Note - if note != "" || osNote != "" { - color.Blue("== %s", pkg.Title) - } - if note != "" { - color.Yellow(note) - } - if osNote != "" { - color.Yellow(osNote) - } + fmt.Print(pkg.InstallNotes()) return nil }, } diff --git a/pkgparse/parser.go b/pkgparse/parser.go index 8f0cb0b..9e853ab 100644 --- a/pkgparse/parser.go +++ b/pkgparse/parser.go @@ -8,10 +8,11 @@ import ( "path/filepath" "regexp" "strings" - + "github.com/candrewlee14/webman/config" "github.com/candrewlee14/webman/utils" + "github.com/fatih/color" "gopkg.in/yaml.v3" ) @@ -32,7 +33,8 @@ type OsInfo struct { IsRawBinary bool `yaml:"is_raw_binary"` FilenameFormatOverride string `yaml:"filename_format_override"` Renames []RenameItem `yaml:"renames"` - Note string `yaml:"note"` + InstallNote string `yaml:"install_note"` + RemoveNote string `yaml:"remove_note"` } type OsArchPair struct { @@ -41,10 +43,11 @@ type OsArchPair struct { } type PkgConfig struct { - Title string `yaml:"-"` - Tagline string - About string - Note string + Title string `yaml:"-"` + Tagline string `yaml:"tagline"` + About string `yaml:"about"` + InstallNote string `yaml:"install_note"` + RemoveNote string `yaml:"remove_note"` InfoUrl string `yaml:"info_url"` ReleasesUrl string `yaml:"releases_url"` @@ -66,6 +69,42 @@ type PkgConfig struct { Ignore []OsArchPair `yaml:"ignore"` } +func (pkgConf *PkgConfig) InstallNotes() string { + var installNotes string + + pkgOS := GOOStoPkgOs[utils.GOOS] + note := pkgConf.InstallNote + osNote := pkgConf.OsMap[pkgOS].InstallNote + if note != "" || osNote != "" { + installNotes += color.BlueString("== %s\n", pkgConf.Title) + } + if note != "" { + installNotes += color.YellowString(note) + "\n" + } + if osNote != "" { + installNotes += color.YellowString(osNote) + "\n" + } + return installNotes +} + +func (pkgConf *PkgConfig) RemoveNotes() string { + var removeNotes string + + pkgOS := GOOStoPkgOs[utils.GOOS] + note := pkgConf.RemoveNote + osNote := pkgConf.OsMap[pkgOS].RemoveNote + if note != "" || osNote != "" { + removeNotes += color.BlueString("== %s\n", pkgConf.Title) + } + if note != "" { + removeNotes += color.YellowString(note) + "\n" + } + if osNote != "" { + removeNotes += color.YellowString(osNote) + "\n" + } + return removeNotes +} + var GOOStoPkgOs = map[string]string{ "darwin": "macos", "windows": "win", diff --git a/schema/pkg_schema.json b/schema/pkg_schema.json index 352604c..cd95d2f 100644 --- a/schema/pkg_schema.json +++ b/schema/pkg_schema.json @@ -23,10 +23,14 @@ "description": "Package description", "type": "string" }, - "note": { + "install_note": { "description": "Installation notes for this package", "type": "string" }, + "remove_note": { + "description": "Removal notes for this package", + "type": "string" + }, "info_url": { "description": "URL for information/documentation", "type": "string" @@ -286,9 +290,13 @@ } }, - "note": { + "install_note": { "description": "Installation notes for this OS", "type": "string" + }, + "remove_note": { + "description": "Removal notes for this OS", + "type": "string" } } }