wip
This commit is contained in:
@ -13,7 +13,7 @@ var dumpCmd = &cobra.Command{
|
||||
Long: `Dumps cache to display`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if conf.Dump.Full {
|
||||
fmt.Println(cache.DumpString())
|
||||
fmt.Println(cache.DumpString(true))
|
||||
} else {
|
||||
plog.Info(cache.String())
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var loadCmd = &cobra.Command{
|
||||
@ -19,4 +20,9 @@ func loadCache(cmd *cobra.Command, args []string) {
|
||||
|
||||
func init() {
|
||||
cacheCmd.AddCommand(loadCmd)
|
||||
|
||||
loadCmd.PersistentFlags().Bool("ownerOnly", true,
|
||||
"Only load projects that you are owner of")
|
||||
|
||||
viper.BindPFlag("cache.load.ownerOnly", loadCmd.Flag("ownerOnly"))
|
||||
}
|
||||
|
@ -16,11 +16,7 @@ var projectCmd = &cobra.Command{
|
||||
Long: projCmdLong,
|
||||
PersistentPreRun: initProjectCmd,
|
||||
PersistentPostRun: postProjectCmd,
|
||||
Run: projectCmdRun,
|
||||
}
|
||||
|
||||
func projectCmdRun(cmd *cobra.Command, args []string) {
|
||||
goToProject(getProject(args))
|
||||
// Run: projectGoCmdRun,
|
||||
}
|
||||
|
||||
func getProject(args []string) *gitlab.Project {
|
||||
@ -34,7 +30,7 @@ func getProject(args []string) *gitlab.Project {
|
||||
if project == nil {
|
||||
plog.Fatal("Failed to find a project, nothing to do")
|
||||
} else {
|
||||
plog.Info("Houston, we have a project", plog.Args(
|
||||
plog.Debug("Houston, we have a project", plog.Args(
|
||||
"project", project.String(),
|
||||
"aliases", projects.ProjectAliasesString(
|
||||
cache.GetProjectAliases(project)),
|
||||
|
21
cmd/project_add.go
Normal file
21
cmd/project_add.go
Normal file
@ -0,0 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var projectAddCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add a new GitLab project",
|
||||
Aliases: []string{"a", "alias"},
|
||||
Long: projAddCmdLong,
|
||||
Run: projectAddCmdRun,
|
||||
}
|
||||
|
||||
func projectAddCmdRun(cmd *cobra.Command, args []string) {
|
||||
getProject(args)
|
||||
}
|
||||
|
||||
func init() {
|
||||
projectCmd.AddCommand(projectAddCmd)
|
||||
}
|
@ -1,25 +1,47 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
)
|
||||
|
||||
var projectGoCmd = &cobra.Command{
|
||||
Use: "go [fuzzy alias search]",
|
||||
Short: "Go to a GitLab project",
|
||||
Aliases: []string{"goto", "projects", "p"},
|
||||
Aliases: []string{"goto", "cd"},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ArgAliases: []string{"project"},
|
||||
ValidArgsFunction: validAliasesFunc,
|
||||
Long: projGoCmdLong,
|
||||
Run: projectCmdRun,
|
||||
Run: projectGoCmdRun,
|
||||
}
|
||||
|
||||
func projectGoCmdRun(cmd *cobra.Command, args []string) {
|
||||
goToProject(getProject(args))
|
||||
var term string
|
||||
if len(args) > 0 {
|
||||
term = args[0]
|
||||
}
|
||||
// project := getProject(args)
|
||||
project := fzfSearchProjectAliases(term)
|
||||
cache.GoTo(project)
|
||||
project.SetRepo(cache.OpenProject(cmd.Context(), project))
|
||||
|
||||
plog.Debug("Project ready", plog.Args(
|
||||
"path", cache.GetProjectPath(project),
|
||||
"project", project,
|
||||
))
|
||||
|
||||
fmt.Fprintln(os.Stderr, project.GetGitInfo())
|
||||
|
||||
// This should be read by any source command, for instance
|
||||
// `cd "$(gitlab-project-manager projects cd somealias)"`
|
||||
fmt.Println(cache.GetProjectPath(project))
|
||||
exec.Command("cd", cache.GetProjectPath(project)).Run()
|
||||
}
|
||||
|
||||
func goToProject(project *gitlab.Project) {
|
||||
cache.GoTo(project)
|
||||
func init() {
|
||||
projectCmd.AddCommand(projectGoCmd)
|
||||
}
|
||||
|
26
cmd/project_list.go
Normal file
26
cmd/project_list.go
Normal file
@ -0,0 +1,26 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var projectListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List GitLab Projects",
|
||||
Aliases: []string{"ls", "show"},
|
||||
Long: projListCmdLong,
|
||||
Run: projectListCmdRun,
|
||||
}
|
||||
|
||||
func projectListCmdRun(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(cache.DumpString(viper.GetBool("project.list.all")))
|
||||
}
|
||||
|
||||
func init() {
|
||||
projectCmd.AddCommand(projectListCmd)
|
||||
projectListCmd.PersistentFlags().Bool("all", false, "List all, not just cloned locally")
|
||||
viper.BindPFlag("project.list.all", projectListCmd.Flag("all"))
|
||||
}
|
@ -83,7 +83,9 @@ func initConfig() {
|
||||
checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config
|
||||
|
||||
// Configure pretty logger
|
||||
plog = pterm.DefaultLogger.WithLevel(getPtermLogLevel(viper.GetString("logLevel")))
|
||||
plog = pterm.DefaultLogger.
|
||||
WithLevel(getPtermLogLevel(viper.GetString("logLevel"))).
|
||||
WithWriter(os.Stderr)
|
||||
if plog.Level == pterm.LogLevelDebug {
|
||||
pterm.EnableDebugMessages()
|
||||
}
|
||||
|
@ -35,5 +35,11 @@ will be cloned from source control.
|
||||
|
||||
If conf.projects.alwaysPull, a git pull will be ran automatically`
|
||||
|
||||
const projListCmdLong = `List locally cloned projects. Optionally
|
||||
lists all projects in project cache`
|
||||
|
||||
const projAddCmdLong = `Adds a new project to the local project path
|
||||
uses fuzzy find to locate the project`
|
||||
|
||||
const projShowCmdLong = `Shows detail for a particular project
|
||||
Will always fuzzy find`
|
||||
|
@ -33,6 +33,7 @@ func initProjectCache(cmd *cobra.Command, args []string) {
|
||||
TTL: conf.Cache.Ttl,
|
||||
Logger: plog,
|
||||
Gitlab: gitlabClient,
|
||||
Config: &conf,
|
||||
}
|
||||
if cache, err = projects.NewProjectCache(cacheOpts); err != nil {
|
||||
plog.Error("Failed to prepare project cache", plog.Args("error", err))
|
||||
|
Reference in New Issue
Block a user