59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
|
"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",
|
|
Aliases: []string{"proj", "projects", "p"},
|
|
Args: cobra.MaximumNArgs(1),
|
|
ArgAliases: []string{"alias"},
|
|
ValidArgsFunction: validAliasesFunc,
|
|
Long: projCmdLong,
|
|
PersistentPreRun: initProjectCmd,
|
|
PersistentPostRun: postProjectCmd,
|
|
// Run: projectGoCmdRun,
|
|
}
|
|
|
|
func getProject(args []string) *gitlab.Project {
|
|
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.Debug("Houston, we have a project", plog.Args(
|
|
"project", project.String(),
|
|
"aliases", projects.ProjectAliasesString(
|
|
cache.GetProjectAliases(project)),
|
|
))
|
|
}
|
|
|
|
if len(cache.GetProjectAliases(project)) == 0 {
|
|
plog.Info("New project, set aliases or press enter for default")
|
|
addNewAliases(project.ID)
|
|
}
|
|
|
|
return 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)
|
|
}
|