From 78662b3e09881f48b6a4364bc093ebbceb629108 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Sat, 9 Dec 2023 23:45:30 -0500 Subject: [PATCH] Update shell funcs --- cmd/alias_list.go | 10 +++++++++- cmd/project.go | 1 - cmd/project_go.go | 5 +++++ cmd/project_list.go | 2 +- cmd/project_show.go | 11 +++++------ cmd/root.go | 1 + contrib/gpm_funcs.sh | 17 +++++++++++++++++ internal/projects/fuzz.go | 2 +- 8 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 contrib/gpm_funcs.sh diff --git a/cmd/alias_list.go b/cmd/alias_list.go index a00d2f8..2f9f7c8 100644 --- a/cmd/alias_list.go +++ b/cmd/alias_list.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -16,7 +17,14 @@ var aliasListCmd = &cobra.Command{ } func runListAliasCmd(cmd *cobra.Command, args []string) { - fmt.Print("\n" + cache.AliasesByProjectString() + "\n") + fmt.Println() + pterm.DefaultBox. + WithLeftPadding(5).WithRightPadding(5). + WithBoxStyle(&pterm.Style{pterm.FgLightBlue}). + WithTitle(pterm.Bold.Sprint(pterm.LightGreen("Aliases by Project"))). + Print("\n" + cache.AliasesByProjectString()) + fmt.Println("\n") + // fmt.Print("\n" + cache.AliasesByProjectString() + "\n") } func init() { diff --git a/cmd/project.go b/cmd/project.go index ba271c9..062e917 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -12,7 +12,6 @@ var projectCmd = &cobra.Command{ Aliases: []string{"proj", "projects", "p"}, Args: cobra.MaximumNArgs(1), ArgAliases: []string{"alias"}, - ValidArgsFunction: validAliasesFunc, Long: projCmdLong, PersistentPreRun: initProjectCmd, PersistentPostRun: postProjectCmd, diff --git a/cmd/project_go.go b/cmd/project_go.go index 0ba9ab6..b7fb3cf 100644 --- a/cmd/project_go.go +++ b/cmd/project_go.go @@ -26,6 +26,11 @@ func projectGoCmdRun(cmd *cobra.Command, args []string) { } // project := getProject(args) project := fzfSearchProjectAliases(term) + + if project == nil { + plog.Fatal("No project selected, nowhere to go") + } + cache.GoTo(project) project.SetRepo(cache.OpenProject(cmd.Context(), project)) diff --git a/cmd/project_list.go b/cmd/project_list.go index 892b30a..988adb5 100644 --- a/cmd/project_list.go +++ b/cmd/project_list.go @@ -10,7 +10,7 @@ import ( var projectListCmd = &cobra.Command{ Use: "list", Short: "List GitLab Projects", - Aliases: []string{"ls", "show"}, + Aliases: []string{"ls"}, Long: projListCmdLong, Run: projectListCmdRun, } diff --git a/cmd/project_show.go b/cmd/project_show.go index 36edaa1..9e9d314 100644 --- a/cmd/project_show.go +++ b/cmd/project_show.go @@ -7,12 +7,11 @@ import ( ) var projectShowCmd = &cobra.Command{ - Use: "show [fuzzy alias search]", - Short: "Show detail for a GitLab project", - Args: cobra.ArbitraryArgs, - ValidArgsFunction: validProjectsOrAliasesFunc, - Long: projShowCmdLong, - Run: projectShowCmdRun, + Use: "show [fuzzy alias search]", + Short: "Show detail for a GitLab project", + Args: cobra.ArbitraryArgs, + Long: projShowCmdLong, + Run: projectShowCmdRun, } func projectShowCmdRun(cmd *cobra.Command, args []string) { diff --git a/cmd/root.go b/cmd/root.go index b2858ae..1f21350 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,7 @@ var plog *pterm.Logger var rootCmd = &cobra.Command{ Use: "gitlab-project-manager", + Aliases: []string{"gpm"}, Short: "Find and use GitLab projects locally", Long: rootCmdLong, PersistentPreRun: initRootCmd, diff --git a/contrib/gpm_funcs.sh b/contrib/gpm_funcs.sh new file mode 100644 index 0000000..f680610 --- /dev/null +++ b/contrib/gpm_funcs.sh @@ -0,0 +1,17 @@ +# Go to a project, specify a fzf filter or filter +# through them all +pgo () { + project=` gitlab-project-manager project cd $1 ` + if [ $? -eq 0 ]; then + cd $project + fi +} + +# Add a new project to your local projects path +padd () { + gitlab-project-manager project add +} + +plist () { + gitlab-project-manager alias list +} diff --git a/internal/projects/fuzz.go b/internal/projects/fuzz.go index 1e90e36..8ccd1f5 100644 --- a/internal/projects/fuzz.go +++ b/internal/projects/fuzz.go @@ -23,7 +23,7 @@ func (c *Cache) FuzzyFindAlias(name string) []*ProjectAlias { for i, r := range ranks { found[i] = r.Target } - c.log.Warn("Fuzzy found multiple aliases, try being more specific", + c.log.Debug("Fuzzy found multiple aliases, try being more specific", c.log.Args("foundAliases", strings.Join(found, ", "))) } var aliases []*ProjectAlias