2023-12-09 04:13:17 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-12-10 04:19:19 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2023-12-09 04:13:17 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var projectGoCmd = &cobra.Command{
|
|
|
|
Use: "go [fuzzy alias search]",
|
|
|
|
Short: "Go to a GitLab project",
|
2023-12-10 04:19:19 +00:00
|
|
|
Aliases: []string{"goto", "cd"},
|
2023-12-09 04:13:17 +00:00
|
|
|
Args: cobra.MaximumNArgs(1),
|
|
|
|
ArgAliases: []string{"project"},
|
|
|
|
ValidArgsFunction: validAliasesFunc,
|
|
|
|
Long: projGoCmdLong,
|
2023-12-10 04:19:19 +00:00
|
|
|
Run: projectGoCmdRun,
|
2023-12-09 04:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func projectGoCmdRun(cmd *cobra.Command, args []string) {
|
2023-12-10 04:19:19 +00:00
|
|
|
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()
|
2023-12-09 04:13:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-10 04:19:19 +00:00
|
|
|
func init() {
|
|
|
|
projectCmd.AddCommand(projectGoCmd)
|
2023-12-09 04:13:17 +00:00
|
|
|
}
|