git-project-manager/cmd/project.go

55 lines
1.5 KiB
Go

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)
}