Improve project show and add pshow func with cwd support
This commit is contained in:
@ -3,7 +3,10 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
)
|
||||
|
||||
var projectShowCmd = &cobra.Command{
|
||||
@ -21,8 +24,28 @@ func projectShowCmdRun(cmd *cobra.Command, args []string) {
|
||||
searchString = args[0]
|
||||
}
|
||||
|
||||
project := fzfFindProject(searchString)
|
||||
var project *gitlab.Project
|
||||
|
||||
// Try to find project from current directory
|
||||
if viper.GetBool("project.show.current") {
|
||||
var err error
|
||||
project, err = 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(
|
||||
"error", err,
|
||||
))
|
||||
} else if project == nil {
|
||||
plog.Warn("Failed to use --current flag, project not found in current path")
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise find from the given search string
|
||||
if project == nil {
|
||||
project = fzfFindProject(searchString)
|
||||
}
|
||||
|
||||
// Do a full fuzzy find if all else fails
|
||||
if project == nil {
|
||||
var err error
|
||||
project, err = fzfProject(cmd.Context())
|
||||
@ -33,9 +56,17 @@ func projectShowCmdRun(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(cache.ProjectString(project))
|
||||
fmt.Println()
|
||||
pterm.DefaultBox.
|
||||
WithLeftPadding(5).WithRightPadding(5).
|
||||
WithBoxStyle(&pterm.Style{pterm.FgLightBlue}).
|
||||
WithTitle(pterm.Bold.Sprint(pterm.LightGreen("Project Information"))).
|
||||
Println(cache.ProjectString(project))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func init() {
|
||||
projectCmd.AddCommand(projectShowCmd)
|
||||
projectShowCmd.PersistentFlags().Bool("current", false, "Use project in CWD rather than fuzzy find")
|
||||
viper.BindPFlag("project.show.current", projectShowCmd.Flag("current"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user