From d598d90a9ada4101b2b63836017da11e49ccbbdb Mon Sep 17 00:00:00 2001 From: irkode Date: Sat, 25 May 2024 10:20:07 +0200 Subject: [PATCH 01/10] cmd/use: add --latest to directly install latest release tag --- cmd/status.go | 2 +- cmd/use.go | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmd/status.go b/cmd/status.go index 340ec44..839248d 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -118,7 +118,7 @@ func status(cmd *cobra.Command) error { fmt.Printf("Would you like to get it now? (Y/n): ") fmt.Scanln(&r) if len(r) == 0 || strings.ToLower(string(r[0])) == "y" { - err = use(true) + err = use(true,false) if err != nil { return err } diff --git a/cmd/use.go b/cmd/use.go index f296017..1d59e3c 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -50,15 +50,19 @@ tag to an .hvm file.`, Run: func(cmd *cobra.Command, args []string) { useVersionInDotFile, err := cmd.Flags().GetBool("useVersionInDotFile") cobra.CheckErr(err) + useLatest, err := cmd.Flags().GetBool("latest") + cobra.CheckErr(err) - err = use(useVersionInDotFile) + err = use(useVersionInDotFile, useLatest) cobra.CheckErr(err) + }, } func init() { rootCmd.AddCommand(useCmd) useCmd.Flags().Bool("useVersionInDotFile", false, "Use the version specified by the "+App.DotFileName+" file\nin the current directory") + useCmd.Flags().Bool("latest", false, "Use the latest release") } // A repository is a GitHub repository. @@ -80,7 +84,7 @@ type asset struct { } // use sets the version of the Hugo executable to use in the current directory. -func use(useVersionInDotFile bool) error { +func use(useVersionInDotFile bool, useLatest bool) error { asset := newAsset() repo := newRepository() @@ -99,6 +103,11 @@ func use(useVersionInDotFile bool) error { os.Exit(1) } asset.tag = version + } else if useLatest { + err := repo.getLatestTag(asset) + if err != nil { + return err + } } else { msg := "Select a version to use in the current directory" err := repo.selectTag(asset, msg) @@ -244,6 +253,16 @@ func (r *repository) fetchTags() error { return nil } +// latestTag returns the most recent tag from repository. +func (r *repository) getLatestTag(a *asset) error { + if 1 > len(r.tags) { + return fmt.Errorf("no latest release found") + } + // relying on the sort order + a.tag = r.tags[0] + return nil +} + // selectTag prompts the user to select a tag from a list of recent tags. func (r *repository) selectTag(a *asset, msg string) error { // List tags. From deab0cd5723b4386d8f8bbe42283454730fff90b Mon Sep 17 00:00:00 2001 From: irkode Date: Sat, 25 May 2024 11:49:35 +0200 Subject: [PATCH 02/10] cmd/install: add --latest to directly install latest release tag --- cmd/install.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 53e9a91..736a450 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -39,28 +39,39 @@ To use this version when version management is disabled in the current directory, the cache "default" directory must be in your PATH. If it is not, you will be prompted to add it when installation is complete.`, Run: func(cmd *cobra.Command, args []string) { - err := install() + useLatest, err := cmd.Flags().GetBool("latest") + cobra.CheckErr(err) + + err = install(useLatest) cobra.CheckErr(err) }, } func init() { rootCmd.AddCommand(installCmd) + installCmd.Flags().Bool("latest", false, "Install the latest release") } // install sets the version of the Hugo executable to use when version // management is disabled in the current directory. -func install() error { +func install(useLatest bool) error { asset := newAsset() repo := newRepository() - msg := "Select a version to use when version management is disabled" - err := repo.selectTag(asset, msg) - if err != nil { - return err - } - if asset.tag == "" { - return nil // the user did not select a tag; do nothing + if useLatest { + err := repo.getLatestTag(asset) + if err != nil { + return err + } + } else { + msg := "Select a version to use when version management is disabled" + err := repo.selectTag(asset, msg) + if err != nil { + return err + } + if asset.tag == "" { + return nil // the user did not select a tag; do nothing + } } exists, err := helpers.Exists(filepath.Join(App.CacheDirPath, asset.tag)) @@ -74,7 +85,6 @@ func install() error { return err } } - err = helpers.CopyFile(asset.getExecPath(), filepath.Join(App.CacheDirPath, App.DefaultDirName, asset.execName)) if err != nil { return err From d0a4c52f8545e32b2504f330695207dabfb58a50 Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 15:00:37 +0200 Subject: [PATCH 03/10] Update cmd/use.go fix function name in comment Co-authored-by: Joe Mooring --- cmd/use.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/use.go b/cmd/use.go index 1d59e3c..efb471b 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -253,7 +253,7 @@ func (r *repository) fetchTags() error { return nil } -// latestTag returns the most recent tag from repository. +// getLatestTag returns the most recent tag from repository. func (r *repository) getLatestTag(a *asset) error { if 1 > len(r.tags) { return fmt.Errorf("no latest release found") From 5531eec24983f018ca7a2c1ac438b561796c953a Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 15:00:56 +0200 Subject: [PATCH 04/10] Update cmd/install.go reword Co-authored-by: Joe Mooring --- cmd/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/install.go b/cmd/install.go index 736a450..c3c5a13 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -49,7 +49,7 @@ you will be prompted to add it when installation is complete.`, func init() { rootCmd.AddCommand(installCmd) - installCmd.Flags().Bool("latest", false, "Install the latest release") + installCmd.Flags().Bool("latest", false, "Install the latest version") } // install sets the version of the Hugo executable to use when version From 3b3c393d1d7d882929cb1d6ebd363c4943579041 Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 15:01:07 +0200 Subject: [PATCH 05/10] Update cmd/use.go reword Co-authored-by: Joe Mooring --- cmd/use.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/use.go b/cmd/use.go index efb471b..d487e41 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -62,7 +62,7 @@ tag to an .hvm file.`, func init() { rootCmd.AddCommand(useCmd) useCmd.Flags().Bool("useVersionInDotFile", false, "Use the version specified by the "+App.DotFileName+" file\nin the current directory") - useCmd.Flags().Bool("latest", false, "Use the latest release") + useCmd.Flags().Bool("latest", false, "Use the latest version") } // A repository is a GitHub repository. From 95da2946c81b9fe9abe8d75bb83e54a2472c2f11 Mon Sep 17 00:00:00 2001 From: irkode Date: Sat, 25 May 2024 10:20:07 +0200 Subject: [PATCH 06/10] cmd/use: add --latest to directly install latest release tag --- cmd/use.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/use.go b/cmd/use.go index d487e41..3924ed9 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -50,12 +50,10 @@ tag to an .hvm file.`, Run: func(cmd *cobra.Command, args []string) { useVersionInDotFile, err := cmd.Flags().GetBool("useVersionInDotFile") cobra.CheckErr(err) - useLatest, err := cmd.Flags().GetBool("latest") - cobra.CheckErr(err) + err = use(useVersionInDotFile) - err = use(useVersionInDotFile, useLatest) + useLatest, err := cmd.Flags().GetBool("latest") cobra.CheckErr(err) - }, } From f6a50940159f37de1ff973f04ea2334efa4bac4f Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 18:15:01 +0200 Subject: [PATCH 07/10] cmd/use use latestTag field to fix when used with SortOrder --- cmd/install.go | 2 +- cmd/use.go | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index c3c5a13..c442001 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -41,7 +41,7 @@ you will be prompted to add it when installation is complete.`, Run: func(cmd *cobra.Command, args []string) { useLatest, err := cmd.Flags().GetBool("latest") cobra.CheckErr(err) - + err = install(useLatest) cobra.CheckErr(err) }, diff --git a/cmd/use.go b/cmd/use.go index 3924ed9..56b1269 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -50,10 +50,12 @@ tag to an .hvm file.`, Run: func(cmd *cobra.Command, args []string) { useVersionInDotFile, err := cmd.Flags().GetBool("useVersionInDotFile") cobra.CheckErr(err) - err = use(useVersionInDotFile) useLatest, err := cmd.Flags().GetBool("latest") cobra.CheckErr(err) + + err = use(useVersionInDotFile, useLatest) + cobra.CheckErr(err) }, } @@ -65,10 +67,11 @@ func init() { // A repository is a GitHub repository. type repository struct { - owner string // account owner of the GitHub repository - name string // name of the GitHub repository without the .git extension - tags []string // repository tags in semver ascending order - client *github.Client // a GitHub API client + owner string // account owner of the GitHub repository + name string // name of the GitHub repository without the .git extension + tags []string // repository tags in semver ascending order + latestTag string // only retrieve the latest tag + client *github.Client // a GitHub API client } // An asset is a GitHub asset for a given release, operating system, and architecture. @@ -165,9 +168,10 @@ func newRepository() *repository { } r := repository{ - client: client, - name: App.RepositoryName, - owner: App.RepositoryOwner, + client: client, + name: App.RepositoryName, + owner: App.RepositoryOwner, + latestTag: "", } err := r.fetchTags() @@ -243,6 +247,8 @@ func (r *repository) fetchTags() error { } } + r.latestTag = tagNames[0] + if Config.SortAscending { semver.Sort(tagNames) } @@ -253,11 +259,10 @@ func (r *repository) fetchTags() error { // getLatestTag returns the most recent tag from repository. func (r *repository) getLatestTag(a *asset) error { - if 1 > len(r.tags) { + if "" == r.latestTag { return fmt.Errorf("no latest release found") } - // relying on the sort order - a.tag = r.tags[0] + a.tag = r.latestTag return nil } From 82930474f288a15450cf48b11d9c15b88cbb8c4c Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 19:05:44 +0200 Subject: [PATCH 08/10] Update cmd/use.go reword Co-authored-by: Joe Mooring --- cmd/use.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/use.go b/cmd/use.go index 56b1269..ef7e944 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -70,7 +70,7 @@ type repository struct { owner string // account owner of the GitHub repository name string // name of the GitHub repository without the .git extension tags []string // repository tags in semver ascending order - latestTag string // only retrieve the latest tag + latestTag string // latest repository tag client *github.Client // a GitHub API client } From 1f0a0893fd190787a109af09c4b2fa256f6968e5 Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 19:06:37 +0200 Subject: [PATCH 09/10] Update cmd/use.go reword Co-authored-by: Joe Mooring --- cmd/use.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/use.go b/cmd/use.go index ef7e944..67ea57e 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -69,7 +69,7 @@ func init() { type repository struct { owner string // account owner of the GitHub repository name string // name of the GitHub repository without the .git extension - tags []string // repository tags in semver ascending order + tags []string // repository tags latestTag string // latest repository tag client *github.Client // a GitHub API client } From 60a1119e3f78f329fb076ed9cb52b80e8f5b3325 Mon Sep 17 00:00:00 2001 From: irkode Date: Sun, 26 May 2024 19:08:29 +0200 Subject: [PATCH 10/10] Update status.go - add missing comma --- cmd/status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/status.go b/cmd/status.go index 839248d..c3a7db5 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -118,7 +118,7 @@ func status(cmd *cobra.Command) error { fmt.Printf("Would you like to get it now? (Y/n): ") fmt.Scanln(&r) if len(r) == 0 || strings.ToLower(string(r[0])) == "y" { - err = use(true,false) + err = use(true, false) if err != nil { return err }