git-project-manager/cmd/project.go
2023-12-08 16:52:26 -05:00

49 lines
1.2 KiB
Go

package cmd
import (
"github.com/spf13/cobra"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
)
var projectCmd = &cobra.Command{
Use: "project [fuzzy alias search]",
Short: "Use a GitLab project",
Args: cobra.MaximumNArgs(1),
ArgAliases: []string{"alias"},
ValidArgsFunction: validAliasesFunc,
Long: projCmdLong,
PersistentPreRun: initProjectCmd,
PersistentPostRun: postProjectCmd,
Run: projectCmdRun,
}
func projectCmdRun(cmd *cobra.Command, args []string) {
var searchString string
if len(args) > 0 {
searchString = args[0]
}
project := fzfFindProject(searchString)
if project == nil {
plog.Fatal("Failed to find a project, nothing to do")
} else {
plog.Info("Houston, we have a project", plog.Args(
"project", project.String(),
"aliases", projects.ProjectAliasesString(
cache.GetProjectAliases(project)),
))
}
}
func initProjectCmd(cmd *cobra.Command, args []string) {
initProjectCache(cmd, args)
}
func postProjectCmd(cmd *cobra.Command, args []string) {
postProjectCache(cmd, args)
}
func init() {
rootCmd.AddCommand(projectCmd)
}