git-project-manager/cmd/project.go

55 lines
1.5 KiB
Go
Raw Normal View History

2023-12-08 21:52:26 +00:00
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
2024-10-01 18:29:14 +00:00
2024-12-30 19:54:32 +00:00
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
2024-12-19 19:55:49 +00:00
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/cache"
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects"
2023-12-08 21:52:26 +00:00
)
var projectCmd = &cobra.Command{
Use: "project [fuzzy alias search]",
2024-12-27 22:42:44 +00:00
Short: "Use a Git project",
2023-12-09 04:13:17 +00:00
Aliases: []string{"proj", "projects", "p"},
2023-12-08 21:52:26 +00:00
Args: cobra.MaximumNArgs(1),
ArgAliases: []string{"alias"},
Long: projCmdLong,
2024-12-30 19:54:32 +00:00
PersistentPreRun: initProjects,
2023-12-08 21:52:26 +00:00
PersistentPostRun: postProjectCmd,
2023-12-10 04:19:19 +00:00
// Run: projectGoCmdRun,
2023-12-09 04:13:17 +00:00
}
2024-01-15 20:39:35 +00:00
func getProject(args []string) *projects.Project {
2024-12-30 19:54:32 +00:00
remotes := viper.GetStringSlice(util.FlagRemote)
fzfOpts := &util.FzfProjectOpts{
Ctx: rootCmd.Context(),
2024-12-30 19:54:32 +00:00
Search: utils.SearchStringFromArgs(args),
Remotes: remotes,
}
project := fzfFindProject(fzfOpts)
2023-12-08 21:52:26 +00:00
if project == nil {
plog.Fatal("Failed to find a project, nothing to do")
} else {
2023-12-10 04:19:19 +00:00
plog.Debug("Houston, we have a project", plog.Args(
2023-12-08 21:52:26 +00:00
"project", project.String(),
2024-01-15 21:02:15 +00:00
"aliases", cache.ProjectAliasesString(
projectCache.GetProjectAliases(project)),
2023-12-08 21:52:26 +00:00
))
}
2023-12-09 04:13:17 +00:00
2024-01-15 21:02:15 +00:00
if len(projectCache.GetProjectAliases(project)) == 0 {
2023-12-09 04:13:17 +00:00
plog.Info("New project, set aliases or press enter for default")
addNewAliases(project.ID)
}
return project
2023-12-08 21:52:26 +00:00
}
func init() {
rootCmd.AddCommand(projectCmd)
}
2023-12-10 15:10:46 +00:00