From b9d7d5a4f20b239fcc09d63e69b9db4947487d1e Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Mon, 30 Dec 2024 15:50:31 -0500 Subject: [PATCH] Package subcommand code --- .vscode/launch.json | 10 +++ cmd/alias/alias.go | 5 +- cmd/alias/alias_add.go | 24 +++---- cmd/alias/alias_list.go | 8 +-- cmd/cache/cache.go | 31 +++++---- cmd/cache/cache_clear.go | 5 +- cmd/cache/cache_dump.go | 13 ++-- cmd/cache/cache_load.go | 14 ++-- cmd/cache/cache_unlock.go | 20 +++--- cmd/config.go | 16 ----- cmd/config/config.go | 26 ++++++++ cmd/{ => config}/config_generate.go | 30 ++++----- cmd/{ => config}/config_show.go | 13 ++-- cmd/docs.go | 14 ++-- cmd/project.go | 54 --------------- cmd/project/project.go | 66 +++++++++++++++++++ cmd/{ => project}/project_add.go | 12 ++-- cmd/{ => project}/project_go.go | 34 +++++----- cmd/project/project_list.go | 28 ++++++++ cmd/{ => project}/project_open.go | 54 +++++++-------- cmd/{ => project}/project_run.go | 22 ++++--- cmd/{ => project}/project_show.go | 35 +++++----- cmd/project_list.go | 27 -------- cmd/root.go | 20 ++++-- cmd/util/util_completion.go | 17 +++-- docs/git-project-manager.md | 2 +- docs/git-project-manager_alias.md | 2 +- docs/git-project-manager_alias_add.md | 2 +- docs/git-project-manager_alias_delete.md | 2 +- docs/git-project-manager_alias_list.md | 2 +- docs/git-project-manager_cache.md | 2 +- docs/git-project-manager_cache_clear.md | 2 +- docs/git-project-manager_cache_dump.md | 2 +- docs/git-project-manager_cache_load.md | 2 +- docs/git-project-manager_cache_unlock.md | 2 +- docs/git-project-manager_completion.md | 2 +- docs/git-project-manager_completion_bash.md | 2 +- docs/git-project-manager_completion_fish.md | 2 +- ...t-project-manager_completion_powershell.md | 2 +- docs/git-project-manager_completion_zsh.md | 2 +- docs/git-project-manager_config.md | 2 +- docs/git-project-manager_config_generate.md | 2 +- docs/git-project-manager_config_show.md | 2 +- docs/git-project-manager_docs.md | 2 +- docs/git-project-manager_project.md | 4 +- docs/git-project-manager_project_add.md | 2 +- docs/git-project-manager_project_go.md | 2 +- docs/git-project-manager_project_list.md | 2 +- docs/git-project-manager_project_open.md | 2 +- docs/git-project-manager_project_run.md | 2 +- docs/git-project-manager_project_show.md | 2 +- 51 files changed, 357 insertions(+), 295 deletions(-) delete mode 100644 cmd/config.go create mode 100644 cmd/config/config.go rename cmd/{ => config}/config_generate.go (78%) rename cmd/{ => config}/config_show.go (58%) delete mode 100644 cmd/project.go create mode 100644 cmd/project/project.go rename cmd/{ => project}/project_add.go (64%) rename cmd/{ => project}/project_go.go (50%) create mode 100644 cmd/project/project_list.go rename cmd/{ => project}/project_open.go (69%) rename cmd/{ => project}/project_run.go (58%) rename cmd/{ => project}/project_show.go (55%) delete mode 100644 cmd/project_list.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 87b5782..76accb6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,6 +14,16 @@ "https://gitea.libretechconsulting.com" ] }, + { + "name": "List Aliases", + "type": "delve", + "request": "launch", + "program": "${workspaceFolder}", + "args": [ + "alias", + "ls" + ] + }, { "name": "Generate Docs", "type": "delve", diff --git a/cmd/alias/alias.go b/cmd/alias/alias.go index f9feef7..b8ac709 100644 --- a/cmd/alias/alias.go +++ b/cmd/alias/alias.go @@ -1,8 +1,9 @@ package alias import ( - "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" "github.com/spf13/cobra" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var AliasCmd = &cobra.Command{ @@ -23,7 +24,7 @@ func aliasCmdPreRun(cmd *cobra.Command, args []string) { } func mustHaveAliases(cmd *cobra.Command, args []string) { - utils := util.MustFromCtx(cmd.Context()) + utils = util.MustFromCtx(cmd.Context()) if len(utils.Cache().Aliases) == 0 { utils.Logger().Fatal("No aliases set, nothing to " + cmd.Name()) diff --git a/cmd/alias/alias_add.go b/cmd/alias/alias_add.go index 2d543ef..0d57196 100644 --- a/cmd/alias/alias_add.go +++ b/cmd/alias/alias_add.go @@ -45,18 +45,19 @@ func runAddAliasCmd(cmd *cobra.Command, args []string) { } } - addNewAliases(project.ID) + AddNewAliases(cmd, project.ID) } -func addNewAliases(projectID int) { - project := utils.Cache().GetProjectByID(projectID) +func AddNewAliases(cmd *cobra.Command, projectID int) { + u := util.MustFromCtx(cmd.Context()) + project := u.Cache().GetProjectByID(projectID) if project == nil { - utils.Logger().Error("Failed to find project to alias", utils.Logger().Args("projectID", projectID)) + u.Logger().Error("Failed to find project to alias", u.Logger().Args("projectID", projectID)) return } // Collect the aliases - aliases := promptAliasesForProject(project) + aliases := PromptAliasesForProject(cmd, project) // Add aliases for _, a := range aliases { @@ -64,13 +65,13 @@ func addNewAliases(projectID int) { if a == "" { continue } - if err := utils.Cache().AddAlias(a, project.ID, project.Remote); err != nil { - utils.Logger().Debug("Skipping alias add", utils.Logger().Args( + if err := u.Cache().AddAlias(a, project.ID, project.Remote); err != nil { + u.Logger().Debug("Skipping alias add", u.Logger().Args( "error", err, "alias", a, )) } else { - utils.Logger().Info("Successfully added alias to project", utils.Logger().Args( + u.Logger().Info("Successfully added alias to project", u.Logger().Args( "project", project.String(), "alias", a, )) @@ -78,10 +79,11 @@ func addNewAliases(projectID int) { } } -func promptAliasesForProject(p *projects.Project) []string { - aliases := utils.Cache().GetProjectAliases(p) +func PromptAliasesForProject(cmd *cobra.Command, p *projects.Project) []string { + u := util.MustFromCtx(cmd.Context()) + aliases := u.Cache().GetProjectAliases(p) if len(aliases) > 0 { - utils.Logger().Info("Adding aliases to project", utils.Logger().Args( + u.Logger().Info("Adding aliases to project", u.Logger().Args( "project", p.String(), "existingAliases", cache.ProjectAliasesString(aliases), )) diff --git a/cmd/alias/alias_list.go b/cmd/alias/alias_list.go index 412c49a..bc3dce5 100644 --- a/cmd/alias/alias_list.go +++ b/cmd/alias/alias_list.go @@ -20,15 +20,11 @@ var aliasListCmd = &cobra.Command{ } func runListAliasCmd(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) + remotes := viper.GetStringSlice(util.FlagRemote) pterm.DefaultBox. WithLeftPadding(5).WithRightPadding(5). WithBoxStyle(&pterm.Style{pterm.FgLightBlue}). WithTitle(pterm.Bold.Sprint(pterm.LightGreen("Aliases by Project"))). - Print("\n" + projectCache.AliasesByProjectString(remotes...)) + Print("\n" + utils.Cache().AliasesByProjectString(remotes...)) fmt.Print("\n\n") } - -func init() { - aliasCmd.AddCommand(aliasListCmd) -} diff --git a/cmd/cache/cache.go b/cmd/cache/cache.go index 60b73cb..56f1fca 100644 --- a/cmd/cache/cache.go +++ b/cmd/cache/cache.go @@ -1,34 +1,43 @@ -package cmd +package cache import ( "time" "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) -var cacheCmd = &cobra.Command{ +var CacheCmd = &cobra.Command{ Use: "cache", Aliases: []string{"a", "ln"}, Short: "Manage Git project cache", - Long: cacheCmdLong, + Long: util.CacheCmdLong, } +var utils *util.Utils + func runCacheCmd(cmd *cobra.Command, args []string) { - initProjectCache(cmd, args) - projectCache.LockCache() + utils = util.MustFromCtx(cmd.Context()) + + utils.InitProjectCache(cmd, args) + utils.Cache().LockCache() } func postCacheCmd(cmd *cobra.Command, args []string) { - postProjectCache(cmd, args) - projectCache.UnlockCache() + utils.PostProjectCache(cmd, args) + utils.Cache().UnlockCache() } func init() { - rootCmd.AddCommand(cacheCmd) - - cacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour, + CacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour, "Duration before cache is re-built in go time.Duration format") - viper.BindPFlags(cacheCmd.Flags()) + viper.BindPFlags(CacheCmd.Flags()) + + CacheCmd.AddCommand(clearCmd) + CacheCmd.AddCommand(dumpCmd) + CacheCmd.AddCommand(loadCmd) + CacheCmd.AddCommand(unlockCmd) } diff --git a/cmd/cache/cache_clear.go b/cmd/cache/cache_clear.go index f03bcd4..a6c1a15 100644 --- a/cmd/cache/cache_clear.go +++ b/cmd/cache/cache_clear.go @@ -1,4 +1,4 @@ -package cmd +package cache import ( "github.com/spf13/cobra" @@ -21,11 +21,10 @@ var clearCmd = &cobra.Command{ func clearCache(cmd *cobra.Command, args []string) { slog.Debug("Preparing to clear local cache") - projectCache.Clear(conf.Cache.Clear.ClearAliases) + utils.Cache().Clear(utils.Config().Cache.Clear.ClearAliases) } func init() { - cacheCmd.AddCommand(clearCmd) clearCmd.Flags().Bool("clearAliases", false, "Will also clear aliases from the cache, use with caution") viper.BindPFlag("cache.clear.clearAliases", clearCmd.LocalFlags().Lookup("clearAliases")) } diff --git a/cmd/cache/cache_dump.go b/cmd/cache/cache_dump.go index 7210038..68b03d9 100644 --- a/cmd/cache/cache_dump.go +++ b/cmd/cache/cache_dump.go @@ -1,10 +1,12 @@ -package cmd +package cache import ( "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var dumpCmd = &cobra.Command{ @@ -17,16 +19,15 @@ var dumpCmd = &cobra.Command{ } func runCacheDunpCmd(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) - if conf.Dump.Full { - fmt.Println(projectCache.DumpString(true, searchStringFromArgs(args), remotes...)) + remotes := viper.GetStringSlice(util.FlagRemote) + if utils.Config().Dump.Full { + fmt.Println(utils.Cache().DumpString(true, utils.SearchStringFromArgs(args), remotes...)) } else { - plog.Info(projectCache.String()) + utils.Logger().Info(utils.Cache().String()) } } func init() { - cacheCmd.AddCommand(dumpCmd) dumpCmd.PersistentFlags().BoolP("full", "f", false, "Dumps entire cache") viper.BindPFlag("dump.full", dumpCmd.LocalFlags().Lookup("full")) } diff --git a/cmd/cache/cache_load.go b/cmd/cache/cache_load.go index 33028e0..a4518c1 100644 --- a/cmd/cache/cache_load.go +++ b/cmd/cache/cache_load.go @@ -1,8 +1,10 @@ -package cmd +package cache import ( "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var loadCmd = &cobra.Command{ @@ -17,15 +19,13 @@ wants to find a new project.`, } func loadCache(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) - projectCache.Refresh(remotes...) + remotes := viper.GetStringSlice(util.FlagRemote) + utils.Cache().Refresh(remotes...) } func init() { - cacheCmd.AddCommand(loadCmd) - - loadCmd.PersistentFlags().Bool(FlagOwnerOnly, true, + loadCmd.PersistentFlags().Bool(util.FlagOwnerOnly, true, "Only load projects that you are owner of") - viper.BindPFlag(ViperCacheLoadOwnerOnly, loadCmd.Flag(FlagOwnerOnly)) + viper.BindPFlag(util.ViperCacheLoadOwnerOnly, loadCmd.Flag(util.FlagOwnerOnly)) } diff --git a/cmd/cache/cache_unlock.go b/cmd/cache/cache_unlock.go index 595b02e..93ed97b 100644 --- a/cmd/cache/cache_unlock.go +++ b/cmd/cache/cache_unlock.go @@ -1,9 +1,11 @@ -package cmd +package cache import ( "github.com/pterm/pterm" "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var unlockCmd = &cobra.Command{ @@ -11,21 +13,21 @@ var unlockCmd = &cobra.Command{ Short: "unlock Git project cache", Long: `unlocks cache to display`, Run: func(cmd *cobra.Command, args []string) { - initProjectCache(cmd, args) - if viper.GetBool(ViperCacheUnlockForce) { - projectCache.UnlockCache() + utils = util.MustFromCtx(cmd.Context()) + utils.InitProjectCache(cmd, args) + if viper.GetBool(util.ViperCacheUnlockForce) { + utils.Cache().UnlockCache() } else if yes, _ := pterm.DefaultInteractiveConfirm. WithDefaultValue(false). Show("Are you sure you want to manually unlock?"); yes { - projectCache.UnlockCache() + utils.Cache().UnlockCache() } else { - plog.Error("You failed to confirm cache unlock") + utils.Logger().Error("You failed to confirm cache unlock") } }, } func init() { - cacheCmd.AddCommand(unlockCmd) - unlockCmd.PersistentFlags().BoolP(FlagCacheForce, "f", false, "force unlocks cache (don't ask)") - viper.BindPFlag(ViperCacheUnlockForce, unlockCmd.LocalFlags().Lookup(FlagCacheForce)) + unlockCmd.PersistentFlags().BoolP(util.FlagCacheForce, "f", false, "force unlocks cache (don't ask)") + viper.BindPFlag(util.ViperCacheUnlockForce, unlockCmd.LocalFlags().Lookup(util.FlagCacheForce)) } diff --git a/cmd/config.go b/cmd/config.go deleted file mode 100644 index 262bf37..0000000 --- a/cmd/config.go +++ /dev/null @@ -1,16 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" -) - -var configCmd = &cobra.Command{ - Use: "config", - Short: "Git Project Manager Configuration", - Aliases: []string{"conf"}, - Long: configCmdLong, -} - -func init() { - rootCmd.AddCommand(configCmd) -} diff --git a/cmd/config/config.go b/cmd/config/config.go new file mode 100644 index 0000000..54cab1a --- /dev/null +++ b/cmd/config/config.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/spf13/cobra" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" +) + +var ConfigCmd = &cobra.Command{ + Use: "config", + Short: "Git Project Manager Configuration", + Aliases: []string{"conf"}, + Long: util.ConfigCmdLong, + PersistentPreRun: configCmdPreRun, +} + +var utils *util.Utils + +func configCmdPreRun(cmd *cobra.Command, args []string) { + utils = util.MustFromCtx(cmd.Context()) +} + +func init() { + ConfigCmd.AddCommand(configGenerateCmd) + ConfigCmd.AddCommand(configShowCmd) +} diff --git a/cmd/config_generate.go b/cmd/config/config_generate.go similarity index 78% rename from cmd/config_generate.go rename to cmd/config/config_generate.go index 9cff9d5..7e83ed4 100644 --- a/cmd/config_generate.go +++ b/cmd/config/config_generate.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/viper" "gopkg.in/yaml.v3" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/config" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/info" ) @@ -18,7 +19,7 @@ var configGenerateCmd = &cobra.Command{ Use: "generate", Short: "Generate a default configuration", Aliases: []string{"gen", "new", "default"}, - Long: configGenCmdLong, + Long: util.ConfigGenCmdLong, Run: runConfigGenerateCmd, } @@ -27,34 +28,34 @@ func runConfigGenerateCmd(cmd *cobra.Command, args []string) { if viper.ConfigFileUsed() != "" { configFile = viper.ConfigFileUsed() } else { - configFile = defConfigPath + configFile = util.DefConfigPath } - plog.Debug("Using config file " + configFile) + utils.Logger().Debug("Using config file " + configFile) - configFile, _ = resolvePath(configFile) + configFile, _ = util.ResolvePath(configFile) - newConf := promptConfigSettings(&conf) + newConf := promptConfigSettings(utils.Config()) - if write, _ := cmd.Flags().GetBool(FlagWrite); write { + if write, _ := cmd.Flags().GetBool(util.FlagWrite); write { write, _ := pterm.DefaultInteractiveContinue. WithDefaultText("Really write config file?"). WithOptions([]string{"yes", "no"}). Show() if write != "yes" { - plog.Fatal("Aborting config file write") + utils.Logger().Fatal("Aborting config file write") } writeConfigFile(newConf, configFile) - plog.Info("Wrote config to file", - plog.Args("file", configFile)) + utils.Logger().Info("Wrote config to file", + utils.Logger().Args("file", configFile)) } else { var c bytes.Buffer enc := yaml.NewEncoder(&c) enc.SetIndent(2) enc.Encode(newConf) - plog.Info("Suggest running with --write or redirect (> " + configFile + ")") + utils.Logger().Info("Suggest running with --write or redirect (> " + configFile + ")") fmt.Print(c.String()) } } @@ -62,11 +63,11 @@ func runConfigGenerateCmd(cmd *cobra.Command, args []string) { func writeConfigFile(c *config.Config, path string) { file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o640) if err != nil { - plog.Error("Failed to prepare config for writing", plog.Args("error", err)) + utils.Logger().Error("Failed to prepare config for writing", utils.Logger().Args("error", err)) } enc := yaml.NewEncoder(file) if err := enc.Encode(c); err != nil { - plog.Fatal("Failed writing config file", plog.Args("file", path)) + utils.Logger().Fatal("Failed writing config file", utils.Logger().Args("file", path)) } } @@ -149,7 +150,6 @@ func promptConfigSettings(c *config.Config) *config.Config { } func init() { - configCmd.AddCommand(configGenerateCmd) - configGenerateCmd.PersistentFlags().Bool(FlagPrompt, false, "Prompt for settings") - configGenerateCmd.PersistentFlags().Bool(FlagWrite, false, "Write config to file") + configGenerateCmd.PersistentFlags().Bool(util.FlagPrompt, false, "Prompt for settings") + configGenerateCmd.PersistentFlags().Bool(util.FlagWrite, false, "Write config to file") } diff --git a/cmd/config_show.go b/cmd/config/config_show.go similarity index 58% rename from cmd/config_show.go rename to cmd/config/config_show.go index e0390be..97185ef 100644 --- a/cmd/config_show.go +++ b/cmd/config/config_show.go @@ -6,6 +6,8 @@ import ( "github.com/spf13/cobra" "gopkg.in/yaml.v3" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var configShowCmd = &cobra.Command{ @@ -16,16 +18,16 @@ var configShowCmd = &cobra.Command{ } func runConfigShowCmd(cmd *cobra.Command, args []string) { - c := conf + c := *utils.Config() - showSensitive, _ := cmd.Flags().GetBool(FlagSensitive) + showSensitive, _ := cmd.Flags().GetBool(util.FlagSensitive) if !showSensitive { - plog.Info("Sensitive fields hidden, do not use unreviewed as config") + utils.Logger().Info("Sensitive fields hidden, do not use unreviewed as config") for _, r := range c.Remotes { r.Token = strings.Repeat("*", len(r.Token)) } } else { - plog.Warn("Displaying sensitive fields!") + utils.Logger().Warn("Displaying sensitive fields!") } enc := yaml.NewEncoder(os.Stdout) @@ -34,6 +36,5 @@ func runConfigShowCmd(cmd *cobra.Command, args []string) { } func init() { - configCmd.AddCommand(configShowCmd) - configShowCmd.Flags().BoolP(FlagSensitive, "s", false, "Set to show sensitive fields") + configShowCmd.Flags().BoolP(util.FlagSensitive, "s", false, "Set to show sensitive fields") } diff --git a/cmd/docs.go b/cmd/docs.go index 26b0ae3..eeb2f31 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -5,6 +5,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/cobra/doc" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var docsCmd = &cobra.Command{ @@ -17,9 +19,9 @@ var docsCmd = &cobra.Command{ } func runDocsCmd(cmd *cobra.Command, args []string) { - outDir, err := cmd.Flags().GetString(FlagDocsPath) + outDir, err := cmd.Flags().GetString(util.FlagDocsPath) if err != nil { - plog.Error("missing docs path") + utils.Logger().Error("missing docs path") } prepareDocsDir(cmd, outDir) @@ -35,10 +37,10 @@ func runDocsCmd(cmd *cobra.Command, args []string) { case "yaml": err = doc.GenYamlTree(cmd.Root(), outDir) default: - plog.Error("invalid docs type", plog.Args("type", args[0])) + utils.Logger().Error("invalid docs type", utils.Logger().Args("type", args[0])) } - plog.Info("docs generation complete", plog.Args( + utils.Logger().Info("docs generation complete", utils.Logger().Args( "type", args[0], "docsDir", outDir, "err", err)) } @@ -47,14 +49,14 @@ func prepareDocsDir(_ *cobra.Command, outDir string) { if err != nil { err = os.Mkdir(outDir, 0o755) if err != nil { - plog.Error("failed to create docs path", plog.Args( + utils.Logger().Error("failed to create docs path", utils.Logger().Args( "error", err.Error(), "docsDir", outDir)) } } } func init() { - docsCmd.PersistentFlags().StringP(FlagDocsPath, "d", "./docs", "specify output directory for documentation") + docsCmd.PersistentFlags().StringP(util.FlagDocsPath, "d", "./docs", "specify output directory for documentation") rootCmd.AddCommand(docsCmd) } diff --git a/cmd/project.go b/cmd/project.go deleted file mode 100644 index dbd247f..0000000 --- a/cmd/project.go +++ /dev/null @@ -1,54 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" - "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/cache" - "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects" -) - -var projectCmd = &cobra.Command{ - Use: "project [fuzzy alias search]", - Short: "Use a Git project", - Aliases: []string{"proj", "projects", "p"}, - Args: cobra.MaximumNArgs(1), - ArgAliases: []string{"alias"}, - Long: projCmdLong, - PersistentPreRun: initProjects, - PersistentPostRun: postProjectCmd, - // Run: projectGoCmdRun, -} - -func getProject(args []string) *projects.Project { - remotes := viper.GetStringSlice(util.FlagRemote) - fzfOpts := &util.FzfProjectOpts{ - Ctx: rootCmd.Context(), - Search: utils.SearchStringFromArgs(args), - Remotes: remotes, - } - project := fzfFindProject(fzfOpts) - - if project == nil { - plog.Fatal("Failed to find a project, nothing to do") - } else { - plog.Debug("Houston, we have a project", plog.Args( - "project", project.String(), - "aliases", cache.ProjectAliasesString( - projectCache.GetProjectAliases(project)), - )) - } - - if len(projectCache.GetProjectAliases(project)) == 0 { - plog.Info("New project, set aliases or press enter for default") - addNewAliases(project.ID) - } - - return project -} - -func init() { - rootCmd.AddCommand(projectCmd) -} - diff --git a/cmd/project/project.go b/cmd/project/project.go new file mode 100644 index 0000000..59cc261 --- /dev/null +++ b/cmd/project/project.go @@ -0,0 +1,66 @@ +package project + +import ( + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/alias" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/cache" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects" +) + +var ProjectCmd = &cobra.Command{ + Use: "project [fuzzy alias search]", + Short: "Use a Git project", + Aliases: []string{"proj", "projects", "p"}, + Args: cobra.MaximumNArgs(1), + ArgAliases: []string{"alias"}, + Long: util.ProjCmdLong, + PersistentPreRun: projectCmdPreRun, + PersistentPostRun: util.PostProjectCmd, + // Run: projectGoCmdRun, +} + +var utils *util.Utils + +func projectCmdPreRun(cmd *cobra.Command, args []string) { + utils = util.MustFromCtx(cmd.Context()) + util.InitProjects(cmd, args) +} + +func getProject(cmd *cobra.Command, args []string) *projects.Project { + remotes := viper.GetStringSlice(util.FlagRemote) + fzfOpts := &util.FzfProjectOpts{ + Ctx: cmd.Context(), + Search: utils.SearchStringFromArgs(args), + Remotes: remotes, + } + project := utils.FzfFindProject(fzfOpts) + + if project == nil { + utils.Logger().Fatal("Failed to find a project, nothing to do") + } else { + utils.Logger().Debug("Houston, we have a project", utils.Logger().Args( + "project", project.String(), + "aliases", cache.ProjectAliasesString( + utils.Cache().GetProjectAliases(project)), + )) + } + + if len(utils.Cache().GetProjectAliases(project)) == 0 { + utils.Logger().Info("New project, set aliases or press enter for default") + alias.AddNewAliases(cmd, project.ID) + } + + return project +} + +func init() { + ProjectCmd.AddCommand(projectAddCmd) + ProjectCmd.AddCommand(projectGoCmd) + ProjectCmd.AddCommand(projectListCmd) + ProjectCmd.AddCommand(projectOpenCmd) + ProjectCmd.AddCommand(projectRunCmd) + ProjectCmd.AddCommand(projectShowCmd) +} diff --git a/cmd/project_add.go b/cmd/project/project_add.go similarity index 64% rename from cmd/project_add.go rename to cmd/project/project_add.go index 5942fbe..d71b353 100644 --- a/cmd/project_add.go +++ b/cmd/project/project_add.go @@ -1,21 +1,19 @@ -package cmd +package project import ( "github.com/spf13/cobra" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var projectAddCmd = &cobra.Command{ Use: "add", Short: "Add a new Git project", Aliases: []string{"a", "alias"}, - Long: projAddCmdLong, + Long: util.ProjAddCmdLong, Run: projectAddCmdRun, } func projectAddCmdRun(cmd *cobra.Command, args []string) { - getProject(args) -} - -func init() { - projectCmd.AddCommand(projectAddCmd) + getProject(cmd, args) } diff --git a/cmd/project_go.go b/cmd/project/project_go.go similarity index 50% rename from cmd/project_go.go rename to cmd/project/project_go.go index 60c5e88..f2109df 100644 --- a/cmd/project_go.go +++ b/cmd/project/project_go.go @@ -1,4 +1,4 @@ -package cmd +package project import ( "fmt" @@ -7,6 +7,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var projectGoCmd = &cobra.Command{ @@ -15,30 +17,30 @@ var projectGoCmd = &cobra.Command{ Aliases: []string{"goto", "cd"}, Args: cobra.MaximumNArgs(1), ArgAliases: []string{"project"}, - ValidArgsFunction: validAliasesFunc, - Long: projGoCmdLong, + ValidArgsFunction: util.ValidAliasesFunc, + Long: util.ProjGoCmdLong, Run: projectGoCmdRun, } func projectGoCmdRun(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) - fzfOpts := &fzfProjectOpts{ + remotes := viper.GetStringSlice(util.FlagRemote) + fzfOpts := &util.FzfProjectOpts{ Ctx: cmd.Context(), - Search: searchStringFromArgs(args), + Search: utils.SearchStringFromArgs(args), MustHaveAlias: true, Remotes: remotes, } - project := fzfSearchProjectAliases(fzfOpts) + project := utils.FzfSearchProjectAliases(fzfOpts) if project == nil { - plog.Fatal("No project selected, nowhere to go") + utils.Logger().Fatal("No project selected, nowhere to go") } - projectCache.GoTo(project) - project.SetRepo(projectCache.OpenProject(cmd.Context(), project)) + utils.Cache().GoTo(project) + project.SetRepo(utils.Cache().OpenProject(cmd.Context(), project)) - plog.Debug("Project ready", plog.Args( - "path", projectCache.GetProjectPath(project), + utils.Logger().Debug("Project ready", utils.Logger().Args( + "path", utils.Cache().GetProjectPath(project), "project", project, )) @@ -46,10 +48,6 @@ func projectGoCmdRun(cmd *cobra.Command, args []string) { // This should be read by any source command, for instance // `cd "$(git-project-manager projects cd somealias)"` - fmt.Println(projectCache.GetProjectPath(project)) - exec.Command("cd", projectCache.GetProjectPath(project)).Run() -} - -func init() { - projectCmd.AddCommand(projectGoCmd) + fmt.Println(utils.Cache().GetProjectPath(project)) + exec.Command("cd", utils.Cache().GetProjectPath(project)).Run() } diff --git a/cmd/project/project_list.go b/cmd/project/project_list.go new file mode 100644 index 0000000..4a10646 --- /dev/null +++ b/cmd/project/project_list.go @@ -0,0 +1,28 @@ +package project + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" +) + +var projectListCmd = &cobra.Command{ + Use: "list", + Short: "List Git Projects", + Aliases: []string{"ls", "l"}, + Long: util.ProjListCmdLong, + Run: projectListCmdRun, +} + +func projectListCmdRun(cmd *cobra.Command, args []string) { + remotes := viper.GetStringSlice(util.FlagRemote) + fmt.Println(utils.Cache().DumpString(viper.GetBool(util.ViperProjectListAll), utils.SearchStringFromArgs(args), remotes...)) +} + +func init() { + projectListCmd.PersistentFlags().Bool(util.FlagAll, false, "List all, not just cloned locally") + viper.BindPFlag(util.ViperProjectListAll, projectListCmd.Flag(util.FlagAll)) +} diff --git a/cmd/project_open.go b/cmd/project/project_open.go similarity index 69% rename from cmd/project_open.go rename to cmd/project/project_open.go index 9d6eb35..16048da 100644 --- a/cmd/project_open.go +++ b/cmd/project/project_open.go @@ -1,6 +1,7 @@ -package cmd +package project import ( + "context" "errors" "os" "os/exec" @@ -8,6 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var projectOpenCmd = &cobra.Command{ @@ -15,8 +18,8 @@ var projectOpenCmd = &cobra.Command{ Short: "Open project in your IDE", Aliases: []string{"goto", "cd"}, Args: cobra.OnlyValidArgs, - ValidArgsFunction: validAliasesFunc, - Long: projOpenCmdLong, + ValidArgsFunction: util.ValidAliasesFunc, + Long: util.ProjOpenCmdLong, Run: projectOpenCmdRun, } @@ -48,47 +51,47 @@ func projectOpenCmdRun(cmd *cobra.Command, args []string) { // Find an editor editor := findEditor() if editor == "" { - plog.Fatal("No usable editor found") + utils.Logger().Fatal("No usable editor found") } - remotes := viper.GetStringSlice(FlagRemote) - fzfOpts := &fzfProjectOpts{ + remotes := viper.GetStringSlice(util.FlagRemote) + fzfOpts := &util.FzfProjectOpts{ Ctx: cmd.Context(), - Search: searchStringFromArgs(args), + Search: utils.SearchStringFromArgs(args), Remotes: remotes, } - project := fzfCwdOrSearchProjectAliases(fzfOpts) + project := utils.FzfCwdOrSearchProjectAliases(fzfOpts) if project == nil { - plog.Fatal("No project to open, nothing to do") + utils.Logger().Fatal("No project to open, nothing to do") } // Check the project - path := projectCache.GetProjectPath(project) + path := utils.Cache().GetProjectPath(project) if _, err := os.Stat(path); err != nil { - plog.Fatal("Unable to open project", plog.Args("error", err)) + utils.Logger().Fatal("Unable to open project", utils.Logger().Args("error", err)) } // Open the project with the editor file := getEntrypointFile(path) - openEditor(editor, path+"/"+file) + openEditor(cmd.Context(), editor, path+"/"+file) } -func openEditor(editor string, path string) { +func openEditor(ctx context.Context, editor string, path string) { // Compile arguments args := make([]string, 0, 1) - if conf.Editor.OpenFlags != "" { - args = append(args, conf.Editor.OpenFlags) + if utils.Config().Editor.OpenFlags != "" { + args = append(args, utils.Config().Editor.OpenFlags) } args = append(args, path) // Launch editor - cmd := exec.CommandContext(rootCmd.Context(), editor, args...) + cmd := exec.CommandContext(ctx, editor, args...) cmd.Dir = filepath.Dir(path) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { - plog.Error("Failed to open project", plog.Args( + utils.Logger().Error("Failed to open project", utils.Logger().Args( "error", err.Error(), "command", cmd.String(), )) @@ -100,7 +103,7 @@ func openEditor(editor string, path string) { func getEntrypointFile(projectPath string) string { if err := os.Chdir(projectPath); err != nil { return "" - } else if conf.Editor.OpenDirectory { + } else if utils.Config().Editor.OpenDirectory { return "." } @@ -119,10 +122,10 @@ func findEditor() string { var err error // First try configured editor - if conf.Editor.Binary != "" { - editor, err = getEditor(conf.Editor.Binary) + if utils.Config().Editor.Binary != "" { + editor, err = getEditor(utils.Config().Editor.Binary) if err != nil || editor == "" { - plog.Error("Configured editor is not usable, finding others", plog.Args( + utils.Logger().Error("Configured editor is not usable, finding others", utils.Logger().Args( "error", err, )) } @@ -130,7 +133,7 @@ func findEditor() string { // Then try to find a known editor if editor == "" || err != nil { - conf.Editor.OpenFlags = "" + utils.Config().Editor.OpenFlags = "" for _, e := range knownEditors { path, err := getEditor(e) if err == nil && path != "" { @@ -140,9 +143,9 @@ func findEditor() string { } } - plog.Debug("Editor found for open", plog.Args( + utils.Logger().Debug("Editor found for open", utils.Logger().Args( "editor", editor, - "command", editor+" "+conf.Editor.OpenFlags, + "command", editor+" "+utils.Config().Editor.OpenFlags, )) return editor @@ -164,7 +167,7 @@ func getEditorPath(editor string) (string, error) { editor, _ = exec.LookPath(editor) } - return resolvePath(editor) + return util.ResolvePath(editor) } func isEditorExecutable(editor string) bool { @@ -180,7 +183,6 @@ func isEditorExecutable(editor string) bool { } func init() { - projectCmd.AddCommand(projectOpenCmd) projectOpenCmd.PersistentFlags().String("displayName", "", "Set display name of editor (meant for config file)") projectOpenCmd.PersistentFlags().String("binary", "", "Path to editor binary") projectOpenCmd.PersistentFlags().String("openFlags", "", "Optional flags when opening project (e.g. --reuse-window)") diff --git a/cmd/project_run.go b/cmd/project/project_run.go similarity index 58% rename from cmd/project_run.go rename to cmd/project/project_run.go index 4c8c531..49335f4 100644 --- a/cmd/project_run.go +++ b/cmd/project/project_run.go @@ -1,4 +1,4 @@ -package cmd +package project import ( "fmt" @@ -7,35 +7,37 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" ) var projectRunCmd = &cobra.Command{ Use: "run", Short: "Run the project (e.g. go run .)", Aliases: []string{"exec", "r"}, - Long: projRunCmdLong, + Long: util.ProjRunCmdLong, Run: projectRunCmdRun, } func projectRunCmdRun(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) - fzfOpts := &fzfProjectOpts{ + remotes := viper.GetStringSlice(util.FlagRemote) + fzfOpts := &util.FzfProjectOpts{ Ctx: cmd.Context(), - Search: searchStringFromArgs(args), + Search: utils.SearchStringFromArgs(args), Remotes: remotes, } - project := fzfCwdOrSearchProjectAliases(fzfOpts) + project := utils.FzfCwdOrSearchProjectAliases(fzfOpts) if project == nil { - plog.Fatal("No project selected, nothing to open") + utils.Logger().Fatal("No project selected, nothing to open") } lang := project.GetLanguage() if lang == nil { - plog.Fatal("Git remote isn't sure what language this project is... can't run.") + utils.Logger().Fatal("Git remote isn't sure what language this project is... can't run.") } - plog.Debug(fmt.Sprintf("Project is written in %s, %.2f%% coverage", lang.Name, lang.Percentage)) + utils.Logger().Debug(fmt.Sprintf("Project is written in %s, %.2f%% coverage", lang.Name, lang.Percentage)) switch lang.Name { case "Go": @@ -50,5 +52,5 @@ func projectRunCmdRun(cmd *cobra.Command, args []string) { } func init() { - projectCmd.AddCommand(projectRunCmd) + ProjectCmd.AddCommand(projectRunCmd) } diff --git a/cmd/project_show.go b/cmd/project/project_show.go similarity index 55% rename from cmd/project_show.go rename to cmd/project/project_show.go index fd90325..f92c2da 100644 --- a/cmd/project_show.go +++ b/cmd/project/project_show.go @@ -1,4 +1,4 @@ -package cmd +package project import ( "fmt" @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects" ) @@ -16,7 +17,7 @@ var projectShowCmd = &cobra.Command{ Short: "Show detail for a Git project", Aliases: []string{"cat", "s"}, Args: cobra.ArbitraryArgs, - Long: projShowCmdLong, + Long: util.ProjShowCmdLong, Run: projectShowCmdRun, } @@ -24,24 +25,24 @@ func projectShowCmdRun(cmd *cobra.Command, args []string) { var project *projects.Project var inCwd bool - remotes := viper.GetStringSlice(FlagRemote) - fzfOpts := &fzfProjectOpts{ + remotes := viper.GetStringSlice(util.FlagRemote) + fzfOpts := &util.FzfProjectOpts{ Ctx: cmd.Context(), - Search: searchStringFromArgs(args), + Search: utils.SearchStringFromArgs(args), Remotes: remotes, } // Try to find project from current directory - if viper.GetBool(ViperProjectShowCurrent) { + if viper.GetBool(util.ViperProjectShowCurrent) { var err error - project, err = projectCache.GetProjectFromCwd() + project, err = utils.Cache().GetProjectFromCwd() if err != nil { // Not an error because we're still going to try to find a project - plog.Warn("Failed to get project from current directory", plog.Args( + utils.Logger().Warn("Failed to get project from current directory", utils.Logger().Args( "error", err, )) } else if project == nil { - plog.Warn("Failed to use --current flag, project not found in current path") + utils.Logger().Warn("Failed to use --current flag, project not found in current path") } else { inCwd = true } @@ -49,15 +50,15 @@ func projectShowCmdRun(cmd *cobra.Command, args []string) { // Otherwise find from the given search string if project == nil { - project = fzfFindProject(fzfOpts) + project = utils.FzfFindProject(fzfOpts) } // Do a full fuzzy find if all else fails if project == nil { var err error - project, err = fzfProject(fzfOpts) + project, err = utils.FzfProject(fzfOpts) if err != nil || project == nil { - plog.Fatal("Failed to find project, nothing to show", plog.Args( + utils.Logger().Fatal("Failed to find project, nothing to show", utils.Logger().Args( "error", err, )) } @@ -68,17 +69,17 @@ func projectShowCmdRun(cmd *cobra.Command, args []string) { WithLeftPadding(5).WithRightPadding(5). WithBoxStyle(&pterm.Style{pterm.FgLightBlue}). WithTitle(pterm.Bold.Sprint(pterm.LightGreen("Project Information"))). - Println(projectCache.ProjectString(project)) + Println(utils.Cache().ProjectString(project)) fmt.Println() if inCwd { - project.SetRepo(projectCache.OpenProject(cmd.Context(), project)) + project.SetRepo(utils.Cache().OpenProject(cmd.Context(), project)) fmt.Fprintln(os.Stderr, project.GetGitInfo()+"\n") } } func init() { - projectCmd.AddCommand(projectShowCmd) - projectShowCmd.PersistentFlags().Bool(FlagCurrent, false, "Use project in CWD rather than fuzzy find") - viper.BindPFlag(ViperProjectShowCurrent, projectShowCmd.Flag(FlagCurrent)) + ProjectCmd.AddCommand(projectShowCmd) + projectShowCmd.PersistentFlags().Bool(util.FlagCurrent, false, "Use project in CWD rather than fuzzy find") + viper.BindPFlag(util.ViperProjectShowCurrent, projectShowCmd.Flag(util.FlagCurrent)) } diff --git a/cmd/project_list.go b/cmd/project_list.go deleted file mode 100644 index 79b242d..0000000 --- a/cmd/project_list.go +++ /dev/null @@ -1,27 +0,0 @@ -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -var projectListCmd = &cobra.Command{ - Use: "list", - Short: "List Git Projects", - Aliases: []string{"ls", "l"}, - Long: projListCmdLong, - Run: projectListCmdRun, -} - -func projectListCmdRun(cmd *cobra.Command, args []string) { - remotes := viper.GetStringSlice(FlagRemote) - fmt.Println(projectCache.DumpString(viper.GetBool(ViperProjectListAll), searchStringFromArgs(args), remotes...)) -} - -func init() { - projectCmd.AddCommand(projectListCmd) - projectListCmd.PersistentFlags().Bool(FlagAll, false, "List all, not just cloned locally") - viper.BindPFlag(ViperProjectListAll, projectListCmd.Flag(FlagAll)) -} diff --git a/cmd/root.go b/cmd/root.go index 62f572a..23768a5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,6 +12,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/alias" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/cache" + conf "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/config" + "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/project" "gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/config" ) @@ -32,6 +36,7 @@ var ( // Hook traversal is enabled, so this will be run for all // sub-commands regardless of their registered pre-hooks func initRootCmd(cmd *cobra.Command, args []string) { + cmd.SetContext(util.AddToCtx(cmd.Context(), utils)) utils.InitProjectPath(cmd, args) } @@ -41,9 +46,6 @@ func Execute() { ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt) defer cncl() - // Store provided util.Utils in context - ctx = util.AddToCtx(ctx, utils) - err := rootCmd.ExecuteContext(ctx) if err != nil { pterm.Error.Printfln("%s", pterm.LightYellow("Command failed, "+err.Error())) @@ -67,11 +69,17 @@ func init() { rootCmd.PersistentFlags().StringSlice(util.FlagRemote, []string{}, "Specify remotes by host for any sub-command. Provide multiple times or comma delimited.") + viper.BindPFlags(rootCmd.PersistentFlags()) + // Flag autocompletion rootCmd.RegisterFlagCompletionFunc(util.FlagLogLevel, util.ValidLogLevelsFunc) - rootCmd.RegisterFlagCompletionFunc(util.FlagRemote, utils.ValidRemotesFunc) + rootCmd.RegisterFlagCompletionFunc(util.FlagRemote, util.ValidRemotesFunc) - viper.BindPFlags(rootCmd.PersistentFlags()) + // Subcommands + rootCmd.AddCommand(alias.AliasCmd) + rootCmd.AddCommand(cache.CacheCmd) + rootCmd.AddCommand(conf.ConfigCmd) + rootCmd.AddCommand(project.ProjectCmd) } // initConfig reads in config file and ENV variables if set. @@ -112,6 +120,8 @@ func getInitConfigFunc(utils *util.Utils) func() { plog.Error("Failed loading config", plog.Args("err", err)) } + utils.SetConfig(conf) + if len(os.Args) > 0 && configExemptCommands.Match([]byte(os.Args[1])) { plog.Debug("Permitting missing config for config sub-command") return diff --git a/cmd/util/util_completion.go b/cmd/util/util_completion.go index 2347e40..40fc800 100644 --- a/cmd/util/util_completion.go +++ b/cmd/util/util_completion.go @@ -8,31 +8,34 @@ import ( "golang.org/x/exp/slices" ) -func (u *Utils) ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) ( +func ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective, ) { + u := MustFromCtx(cmd.Context()) u.InitProjectCache(cmd, args) return u.Cache().ProjectStrings(toComplete), cobra.ShellCompDirectiveNoFileComp } -func (u *Utils) ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ( +func ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective, ) { - u.InitProjectCache(cmd, args) - return u.Cache().AliasStrings(toComplete), cobra.ShellCompDirectiveNoFileComp + utils := MustFromCtx(cmd.Context()) + utils.InitProjectCache(cmd, args) + return utils.Cache().AliasStrings(toComplete), cobra.ShellCompDirectiveNoFileComp } func (u *Utils) ValidProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ( []string, cobra.ShellCompDirective, ) { - projectStrings, _ := u.ValidAliasesFunc(cmd, args, toComplete) - aliasStrings, _ := u.ValidProjectsFunc(cmd, args, toComplete) + projectStrings, _ := ValidAliasesFunc(cmd, args, toComplete) + aliasStrings, _ := ValidProjectsFunc(cmd, args, toComplete) return append(projectStrings, aliasStrings...), cobra.ShellCompDirectiveDefault } -func (u *Utils) ValidRemotesFunc(_ *cobra.Command, _ []string, toComplete string) ( +func ValidRemotesFunc(cmd *cobra.Command, _ []string, toComplete string) ( []string, cobra.ShellCompDirective, ) { + u := MustFromCtx(cmd.Context()) remotes := make([]string, 0, len(u.Config().Remotes)) for _, remote := range u.Config().Remotes { if strings.HasPrefix(remote.Host, toComplete) { diff --git a/docs/git-project-manager.md b/docs/git-project-manager.md index 738c65e..c770212 100644 --- a/docs/git-project-manager.md +++ b/docs/git-project-manager.md @@ -27,4 +27,4 @@ shortcuts for moving around in projects and opening your code * [git-project-manager docs](git-project-manager_docs.md) - Generate documentation for git-project-manager * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_alias.md b/docs/git-project-manager_alias.md index ce5ce4d..0f448ba 100644 --- a/docs/git-project-manager_alias.md +++ b/docs/git-project-manager_alias.md @@ -29,4 +29,4 @@ listing, adding, and deleting. * [git-project-manager alias delete](git-project-manager_alias_delete.md) - Delete a project alias * [git-project-manager alias list](git-project-manager_alias_list.md) - List Aliases -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_alias_add.md b/docs/git-project-manager_alias_add.md index bcc77c5..83b5568 100644 --- a/docs/git-project-manager_alias_add.md +++ b/docs/git-project-manager_alias_add.md @@ -31,4 +31,4 @@ git-project-manager alias add [flags] * [git-project-manager alias](git-project-manager_alias.md) - Manage project aliases -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_alias_delete.md b/docs/git-project-manager_alias_delete.md index e5ae2be..64761ab 100644 --- a/docs/git-project-manager_alias_delete.md +++ b/docs/git-project-manager_alias_delete.md @@ -31,4 +31,4 @@ git-project-manager alias delete [fuzzy project or alias] [flags] * [git-project-manager alias](git-project-manager_alias.md) - Manage project aliases -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_alias_list.md b/docs/git-project-manager_alias_list.md index 097f06c..4b72b4c 100644 --- a/docs/git-project-manager_alias_list.md +++ b/docs/git-project-manager_alias_list.md @@ -29,4 +29,4 @@ git-project-manager alias list [flags] * [git-project-manager alias](git-project-manager_alias.md) - Manage project aliases -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_cache.md b/docs/git-project-manager_cache.md index ad73377..6c0d343 100644 --- a/docs/git-project-manager_cache.md +++ b/docs/git-project-manager_cache.md @@ -32,4 +32,4 @@ API every time a new project is added / searched for * [git-project-manager cache load](git-project-manager_cache_load.md) - Load Git Project Cache * [git-project-manager cache unlock](git-project-manager_cache_unlock.md) - unlock Git project cache -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_cache_clear.md b/docs/git-project-manager_cache_clear.md index 21c73ba..4e2792f 100644 --- a/docs/git-project-manager_cache_clear.md +++ b/docs/git-project-manager_cache_clear.md @@ -33,4 +33,4 @@ git-project-manager cache clear [flags] * [git-project-manager cache](git-project-manager_cache.md) - Manage Git project cache -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_cache_dump.md b/docs/git-project-manager_cache_dump.md index d2524d5..8f13059 100644 --- a/docs/git-project-manager_cache_dump.md +++ b/docs/git-project-manager_cache_dump.md @@ -31,4 +31,4 @@ git-project-manager cache dump [flags] * [git-project-manager cache](git-project-manager_cache.md) - Manage Git project cache -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_cache_load.md b/docs/git-project-manager_cache_load.md index 44e3612..86f80f8 100644 --- a/docs/git-project-manager_cache_load.md +++ b/docs/git-project-manager_cache_load.md @@ -33,4 +33,4 @@ git-project-manager cache load [flags] * [git-project-manager cache](git-project-manager_cache.md) - Manage Git project cache -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_cache_unlock.md b/docs/git-project-manager_cache_unlock.md index 7444b8e..2b16aca 100644 --- a/docs/git-project-manager_cache_unlock.md +++ b/docs/git-project-manager_cache_unlock.md @@ -31,4 +31,4 @@ git-project-manager cache unlock [flags] * [git-project-manager cache](git-project-manager_cache.md) - Manage Git project cache -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_completion.md b/docs/git-project-manager_completion.md index a144a59..0027f61 100644 --- a/docs/git-project-manager_completion.md +++ b/docs/git-project-manager_completion.md @@ -31,4 +31,4 @@ See each sub-command's help for details on how to use the generated script. * [git-project-manager completion powershell](git-project-manager_completion_powershell.md) - Generate the autocompletion script for powershell * [git-project-manager completion zsh](git-project-manager_completion_zsh.md) - Generate the autocompletion script for zsh -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_completion_bash.md b/docs/git-project-manager_completion_bash.md index 2dcfe2d..b04e37f 100644 --- a/docs/git-project-manager_completion_bash.md +++ b/docs/git-project-manager_completion_bash.md @@ -50,4 +50,4 @@ git-project-manager completion bash * [git-project-manager completion](git-project-manager_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_completion_fish.md b/docs/git-project-manager_completion_fish.md index bba4515..bc15512 100644 --- a/docs/git-project-manager_completion_fish.md +++ b/docs/git-project-manager_completion_fish.md @@ -41,4 +41,4 @@ git-project-manager completion fish [flags] * [git-project-manager completion](git-project-manager_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_completion_powershell.md b/docs/git-project-manager_completion_powershell.md index c840dec..31fbf81 100644 --- a/docs/git-project-manager_completion_powershell.md +++ b/docs/git-project-manager_completion_powershell.md @@ -38,4 +38,4 @@ git-project-manager completion powershell [flags] * [git-project-manager completion](git-project-manager_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_completion_zsh.md b/docs/git-project-manager_completion_zsh.md index cc01d68..2212675 100644 --- a/docs/git-project-manager_completion_zsh.md +++ b/docs/git-project-manager_completion_zsh.md @@ -52,4 +52,4 @@ git-project-manager completion zsh [flags] * [git-project-manager completion](git-project-manager_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_config.md b/docs/git-project-manager_config.md index 8d5ef78..55e6326 100644 --- a/docs/git-project-manager_config.md +++ b/docs/git-project-manager_config.md @@ -28,4 +28,4 @@ useful for seeding a new config file * [git-project-manager config generate](git-project-manager_config_generate.md) - Generate a default configuration * [git-project-manager config show](git-project-manager_config_show.md) - Show Git Project Manager Configuration -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_config_generate.md b/docs/git-project-manager_config_generate.md index 78d44c5..7bb459d 100644 --- a/docs/git-project-manager_config_generate.md +++ b/docs/git-project-manager_config_generate.md @@ -32,4 +32,4 @@ git-project-manager config generate [flags] * [git-project-manager config](git-project-manager_config.md) - Git Project Manager Configuration -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_config_show.md b/docs/git-project-manager_config_show.md index 96f390f..449d68e 100644 --- a/docs/git-project-manager_config_show.md +++ b/docs/git-project-manager_config_show.md @@ -26,4 +26,4 @@ git-project-manager config show [flags] * [git-project-manager config](git-project-manager_config.md) - Git Project Manager Configuration -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_docs.md b/docs/git-project-manager_docs.md index 1773093..817240a 100644 --- a/docs/git-project-manager_docs.md +++ b/docs/git-project-manager_docs.md @@ -26,4 +26,4 @@ git-project-manager docs [flags] * [git-project-manager](git-project-manager.md) - Find and use Git projects locally -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project.md b/docs/git-project-manager_project.md index 2fd79d4..5718a21 100644 --- a/docs/git-project-manager_project.md +++ b/docs/git-project-manager_project.md @@ -31,6 +31,8 @@ the project locally. * [git-project-manager project list](git-project-manager_project_list.md) - List Git Projects * [git-project-manager project open](git-project-manager_project_open.md) - Open project in your IDE * [git-project-manager project run](git-project-manager_project_run.md) - Run the project (e.g. go run .) +* [git-project-manager project run](git-project-manager_project_run.md) - Run the project (e.g. go run .) +* [git-project-manager project show](git-project-manager_project_show.md) - Show detail for a Git project * [git-project-manager project show](git-project-manager_project_show.md) - Show detail for a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_add.md b/docs/git-project-manager_project_add.md index fd7e53d..838cecf 100644 --- a/docs/git-project-manager_project_add.md +++ b/docs/git-project-manager_project_add.md @@ -30,4 +30,4 @@ git-project-manager project add [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_go.md b/docs/git-project-manager_project_go.md index 22f81ae..541e59d 100644 --- a/docs/git-project-manager_project_go.md +++ b/docs/git-project-manager_project_go.md @@ -33,4 +33,4 @@ git-project-manager project go [fuzzy alias search] [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_list.md b/docs/git-project-manager_project_list.md index 609995d..8863325 100644 --- a/docs/git-project-manager_project_list.md +++ b/docs/git-project-manager_project_list.md @@ -31,4 +31,4 @@ git-project-manager project list [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_open.md b/docs/git-project-manager_project_open.md index 0b57b19..80d8fdb 100644 --- a/docs/git-project-manager_project_open.md +++ b/docs/git-project-manager_project_open.md @@ -36,4 +36,4 @@ git-project-manager project open [fuzzy alias search] [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_run.md b/docs/git-project-manager_project_run.md index 2745841..06749c1 100644 --- a/docs/git-project-manager_project_run.md +++ b/docs/git-project-manager_project_run.md @@ -30,4 +30,4 @@ git-project-manager project run [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024 diff --git a/docs/git-project-manager_project_show.md b/docs/git-project-manager_project_show.md index c976b9c..9c4a9e3 100644 --- a/docs/git-project-manager_project_show.md +++ b/docs/git-project-manager_project_show.md @@ -31,4 +31,4 @@ git-project-manager project show [fuzzy alias search] [flags] * [git-project-manager project](git-project-manager_project.md) - Use a Git project -###### Auto generated by spf13/cobra on 27-Dec-2024 +###### Auto generated by spf13/cobra on 30-Dec-2024