From 3f5b953d00f2363dfed7a8ee5ae3339f7b299b74 Mon Sep 17 00:00:00 2001 From: unilock Date: Mon, 11 Sep 2023 10:00:04 -0400 Subject: [PATCH] github: Allow specifying branch to retrieve releases for via CLI Signed-off-by: unilock --- github/install.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/github/install.go b/github/install.go index 76cd8d4..add69e9 100644 --- a/github/install.go +++ b/github/install.go @@ -37,6 +37,7 @@ var installCmd = &cobra.Command{ // Try interpreting the argument as a slug, or GitHub repository URL. var slug string + var branch string // Check if the argument is a valid GitHub repository URL; if so, extract the slug from the URL. // Otherwise, interpret the argument as a slug directly. @@ -54,7 +55,11 @@ var installCmd = &cobra.Command{ os.Exit(1) } - err = installMod(repo, pack) + if branchFlag != "" { + branch = branchFlag + } + + err = installMod(repo, branch, pack) if err != nil { fmt.Printf("Failed to add project: %s\n", err) os.Exit(1) @@ -62,12 +67,8 @@ var installCmd = &cobra.Command{ }, } -func init() { - githubCmd.AddCommand(installCmd) -} - -func installMod(repo Repo, pack core.Pack) error { - latestRelease, err := getLatestRelease(repo.FullName, "") +func installMod(repo Repo, branch string, pack core.Pack) error { + latestRelease, err := getLatestRelease(repo.FullName, branch) if err != nil { return fmt.Errorf("failed to get latest release: %v", err) } @@ -193,4 +194,11 @@ func installRelease(repo Repo, release Release, pack core.Pack) error { fmt.Printf("Project \"%s\" successfully added! (%s)\n", repo.Name, file.Name) return nil } + +var branchFlag string + +func init() { + githubCmd.AddCommand(installCmd) + + installCmd.Flags().StringVar(&branchFlag, "branch", "", "The GitHub repository branch to retrieve releases for") }