Rename project to git-project-manager
All checks were successful
Build and Publish / release (push) Successful in 1m10s
All checks were successful
Build and Publish / release (push) Successful in 1m10s
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/cache"
|
||||
)
|
||||
|
||||
@ -13,7 +14,7 @@ var projectCache *cache.Cache
|
||||
var cacheCmd = &cobra.Command{
|
||||
Use: "cache",
|
||||
Aliases: []string{"a", "ln"},
|
||||
Short: "Manage GitLab project cache",
|
||||
Short: "Manage Git project cache",
|
||||
Long: cacheCmdLong,
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ If --clearAliases is provided, will also reset aliases. Use with caution.`
|
||||
|
||||
var clearCmd = &cobra.Command{
|
||||
Use: "clear",
|
||||
Short: "Clear GitLab Project Cache",
|
||||
Short: "Clear Git Project Cache",
|
||||
PreRun: runCacheCmd,
|
||||
PostRun: postCacheCmd,
|
||||
Long: longDesc,
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
var dumpCmd = &cobra.Command{
|
||||
Use: "dump",
|
||||
Short: "Dump GitLab project cache",
|
||||
Short: "Dump Git project cache",
|
||||
Long: `Dumps cache to display`,
|
||||
PreRun: runCacheCmd,
|
||||
PostRun: postCacheCmd,
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
|
||||
var loadCmd = &cobra.Command{
|
||||
Use: "load",
|
||||
Short: "Load GitLab Project Cache",
|
||||
Long: `Used to initialize or update a new GitLab cache. With thousands
|
||||
Short: "Load Git Project Cache",
|
||||
Long: `Used to initialize or update a new Git cache. With thousands
|
||||
of projects, it would be too much work to hit the API every time a user
|
||||
wants to find a new project.`,
|
||||
PreRun: runCacheCmd,
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
var unlockCmd = &cobra.Command{
|
||||
Use: "unlock",
|
||||
Short: "unlock GitLab project cache",
|
||||
Short: "unlock Git project cache",
|
||||
Long: `unlocks cache to display`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
initProjectCache(cmd, args)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "GitLab Project Manager Configuration",
|
||||
Short: "Git Project Manager Configuration",
|
||||
Aliases: []string{"conf"},
|
||||
Long: configCmdLong,
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
var configShowCmd = &cobra.Command{
|
||||
Use: "show",
|
||||
Short: "Show GitLab Project Manager Configuration",
|
||||
Short: "Show Git Project Manager Configuration",
|
||||
Aliases: []string{"s", "dump", "cat", "ls"},
|
||||
Run: runConfigShowCmd,
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ func runDocsCmd(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
plog.Info("docs generation complete", plog.Args(
|
||||
"type", args[0], "docsDir", outDir))
|
||||
"type", args[0], "docsDir", outDir, "err", err))
|
||||
}
|
||||
|
||||
func prepareDocsDir(cmd *cobra.Command, outDir string) {
|
||||
func prepareDocsDir(_ *cobra.Command, outDir string) {
|
||||
_, err := os.Stat(outDir)
|
||||
if err != nil {
|
||||
err = os.Mkdir(outDir, 0o755)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
var projectCmd = &cobra.Command{
|
||||
Use: "project [fuzzy alias search]",
|
||||
Short: "Use a GitLab project",
|
||||
Short: "Use a Git project",
|
||||
Aliases: []string{"proj", "projects", "p"},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ArgAliases: []string{"alias"},
|
||||
@ -60,7 +60,7 @@ func init() {
|
||||
rootCmd.AddCommand(projectCmd)
|
||||
}
|
||||
|
||||
func mustHaveProjects(cmd *cobra.Command, args []string) {
|
||||
func mustHaveProjects(cmd *cobra.Command, _ []string) {
|
||||
if len(projectCache.Projects) == 0 {
|
||||
plog.Fatal("No projects to " + cmd.Name() + ", try running cache load")
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
var projectAddCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add a new GitLab project",
|
||||
Short: "Add a new Git project",
|
||||
Aliases: []string{"a", "alias"},
|
||||
Long: projAddCmdLong,
|
||||
Run: projectAddCmdRun,
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
var projectGoCmd = &cobra.Command{
|
||||
Use: "go [fuzzy alias search]",
|
||||
Short: "Go to a GitLab project",
|
||||
Short: "Go to a Git project",
|
||||
Aliases: []string{"goto", "cd"},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ArgAliases: []string{"project"},
|
||||
@ -45,7 +45,7 @@ func projectGoCmdRun(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintln(os.Stderr, project.GetGitInfo())
|
||||
|
||||
// This should be read by any source command, for instance
|
||||
// `cd "$(gitlab-project-manager projects cd somealias)"`
|
||||
// `cd "$(git-project-manager projects cd somealias)"`
|
||||
fmt.Println(projectCache.GetProjectPath(project))
|
||||
exec.Command("cd", projectCache.GetProjectPath(project)).Run()
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
var projectListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List GitLab Projects",
|
||||
Short: "List Git Projects",
|
||||
Aliases: []string{"ls", "l"},
|
||||
Long: projListCmdLong,
|
||||
Run: projectListCmdRun,
|
||||
|
@ -152,7 +152,7 @@ func getEditor(editor string) (string, error) {
|
||||
path, err := getEditorPath(editor)
|
||||
if path != "" && err == nil {
|
||||
if !isEditorExecutable(path) {
|
||||
err = errors.New("Editor is not executable")
|
||||
err = errors.New("editor is not executable")
|
||||
}
|
||||
}
|
||||
return path, err
|
||||
|
@ -32,7 +32,7 @@ func projectRunCmdRun(cmd *cobra.Command, args []string) {
|
||||
lang := project.GetLanguage()
|
||||
|
||||
if lang == nil {
|
||||
plog.Fatal("GitLab isn't sure what language this project is... can't run.")
|
||||
plog.Fatal("Git remote isn't sure what language this project is... can't run.")
|
||||
}
|
||||
|
||||
plog.Debug(fmt.Sprintf("Project is written in %s, %.2f%% coverage", lang.Name, lang.Percentage))
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
|
||||
var projectShowCmd = &cobra.Command{
|
||||
Use: "show [fuzzy alias search]",
|
||||
Short: "Show detail for a GitLab project",
|
||||
Short: "Show detail for a Git project",
|
||||
Aliases: []string{"cat", "s"},
|
||||
Args: cobra.ArbitraryArgs,
|
||||
Long: projShowCmdLong,
|
||||
|
21
cmd/root.go
21
cmd/root.go
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
@ -19,13 +21,15 @@ var (
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "gitlab-project-manager",
|
||||
Use: "git-project-manager",
|
||||
Aliases: []string{"gpm"},
|
||||
Short: "Find and use GitLab projects locally",
|
||||
Short: "Find and use Git projects locally",
|
||||
Long: rootCmdLong,
|
||||
PersistentPreRun: initRootCmd,
|
||||
}
|
||||
|
||||
var configExemptCommands = regexp.MustCompile(`^(doc|conf)`)
|
||||
|
||||
// Hook traversal is enabled, so this will be run for all
|
||||
// sub-commands regardless of their registered pre-hooks
|
||||
func initRootCmd(cmd *cobra.Command, args []string) {
|
||||
@ -40,7 +44,7 @@ func Execute() {
|
||||
|
||||
err := rootCmd.ExecuteContext(ctx)
|
||||
if err != nil {
|
||||
pterm.Error.Printfln(pterm.LightYellow("Command failed, " + err.Error()))
|
||||
pterm.Error.Printfln("%s", pterm.LightYellow("Command failed, "+err.Error()))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@ -77,10 +81,11 @@ func initConfig() {
|
||||
home, err := os.UserHomeDir()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Search config in home directory with name ".gitlab-project-manager" (without extension).
|
||||
viper.AddConfigPath(home + "/.config")
|
||||
// Search config in home directory with name ".git-project-manager" (without extension).
|
||||
configPath := filepath.Join(home, ".config")
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.SetConfigType("yaml")
|
||||
viper.SetConfigName("gitlab-project-manager")
|
||||
viper.SetConfigName(getConfigName(configPath))
|
||||
}
|
||||
|
||||
viper.AutomaticEnv()
|
||||
@ -100,13 +105,13 @@ func initConfig() {
|
||||
plog.Error("Failed loading config", plog.Args("err", err))
|
||||
}
|
||||
|
||||
if len(os.Args) > 0 && strings.HasPrefix(os.Args[1], "conf") {
|
||||
if len(os.Args) > 0 && configExemptCommands.Match([]byte(os.Args[1])) {
|
||||
plog.Debug("Permitting missing config for config sub-command")
|
||||
return
|
||||
} else if conf.ProjectPath == "" {
|
||||
plog.Fatal("Minimal configuration missing, must have projectPath", plog.Args(
|
||||
"do",
|
||||
"Try running `gitlab-project-manager config default > "+defConfigPath,
|
||||
"Try running `git-project-manager config default > "+defConfigPath,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,11 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
defGitlabHost = "https://gitlab.com"
|
||||
defLogLevel = "info"
|
||||
defConfigPath = "~/.config/gitlab-project-manager.yaml"
|
||||
defGitlabHost = "https://gitlab.com"
|
||||
defLogLevel = "info"
|
||||
defConfigPath = "~/.config/git-project-manager.yaml"
|
||||
configName = "git-project-manager"
|
||||
legacyConfigName = "gitlab-project-manager"
|
||||
)
|
||||
|
||||
const aliasCmdLong = `Manages project aliases, with options for
|
||||
@ -42,14 +44,14 @@ const aliasDeleteCmdLong = `Deletes aliases from projects
|
||||
project ID can be provided, or will otherwise use fuzzy find`
|
||||
|
||||
const cacheCmdLong = `Contains sub-commands for managing project cache.
|
||||
The project cache keeps this speedy, without smashing against the GitLab
|
||||
The project cache keeps this speedy, without smashing against the Git
|
||||
API every time a new project is added / searched for`
|
||||
|
||||
const rootCmdLong = `Finds GitLab projects using fuzzy-find, remembering
|
||||
const rootCmdLong = `Finds Git projects using fuzzy-find, remembering
|
||||
your chosen term for the project as an alias, and offers helpful
|
||||
shortcuts for moving around in projects and opening your code`
|
||||
|
||||
const projCmdLong = `Switches to a GitLab project by name or alias
|
||||
const projCmdLong = `Switches to a Git project by name or alias
|
||||
If not found, will enter fzf mode. If not cloned, will clone
|
||||
the project locally.`
|
||||
|
||||
|
@ -1,12 +1,20 @@
|
||||
// This file contains init methods that may be used by
|
||||
// multiple sub-commands. For instance, the cach and projects
|
||||
// sub-commands both depend on a cache and may both call the initProjectCache
|
||||
// func from their PersistentPreRun commands
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/cache"
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes"
|
||||
@ -14,15 +22,9 @@ import (
|
||||
githubremote "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/github"
|
||||
gitlabremote "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/gitlab"
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/remote"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// This file contains init methods that may be used by
|
||||
// multiple sub-commands. For instance, the cach and projects
|
||||
// sub-commands both depend on a cache and may both call the initProjectCache
|
||||
// func from their PersistentPreRun commands
|
||||
|
||||
func initProjectCache(cmd *cobra.Command, args []string) {
|
||||
func initProjectCache(cmd *cobra.Command, _ []string) {
|
||||
var err error
|
||||
plog.Debug("Running pre-run for cacheCmd")
|
||||
conf.Cache.File = conf.ProjectPath + "/.cache.yaml"
|
||||
@ -80,11 +82,11 @@ func getRemotes(cmd *cobra.Command) *remotes.Remotes {
|
||||
return gitRemotes
|
||||
}
|
||||
|
||||
func postProjectCache(cmd *cobra.Command, args []string) {
|
||||
func postProjectCache(_ *cobra.Command, _ []string) {
|
||||
projectCache.Write()
|
||||
}
|
||||
|
||||
func initProjectPath(cmd *cobra.Command, args []string) {
|
||||
func initProjectPath(_ *cobra.Command, _ []string) {
|
||||
plog.Debug("Running persistent pre-run for rootCmd")
|
||||
var err error
|
||||
if conf.ProjectPath == "" {
|
||||
@ -98,7 +100,7 @@ func initProjectPath(cmd *cobra.Command, args []string) {
|
||||
_, err = os.Stat(conf.ProjectPath)
|
||||
if err != nil {
|
||||
plog.Error("Failed to stat project path, trying to create", plog.Args("error", err))
|
||||
if err := os.MkdirAll(conf.ProjectPath, 0750); err != nil {
|
||||
if err = os.MkdirAll(conf.ProjectPath, 0o750); err != nil {
|
||||
plog.Error("Failed to create project path", plog.Args("error", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -120,3 +122,22 @@ func resolvePath(path string) (string, error) {
|
||||
}
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
||||
func getConfigName(configPath string) string {
|
||||
// Check existing config
|
||||
for _, ext := range []string{"yml", "yaml"} {
|
||||
configFile := fmt.Sprintf("%s/%s.%s", configPath, configName, ext)
|
||||
legacyConfigFile := fmt.Sprintf("%s/%s.%s", configPath, legacyConfigName, ext)
|
||||
|
||||
if _, err := os.Stat(configFile); err == nil {
|
||||
return configName
|
||||
} else if _, err := os.Stat(legacyConfigFile); err == nil {
|
||||
pterm.DefaultLogger.WithWriter(os.Stderr).
|
||||
Warn(fmt.Sprintf("using legacy config path, suggest using %s/%s.yaml", configPath, configName))
|
||||
return legacyConfigName
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing found, do what we want
|
||||
return configName
|
||||
}
|
||||
|
Reference in New Issue
Block a user