mirror of
https://github.com/taigrr/mg.git
synced 2026-04-02 03:28:42 -07:00
update env var expansion logic
This commit is contained in:
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/taigrr/mg/parse"
|
||||
)
|
||||
@@ -28,11 +27,6 @@ func GetConfig() parse.MGConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
for i, repo := range conf.Repos {
|
||||
if strings.HasPrefix(repo.Path, "$HOME") {
|
||||
conf.Repos[i].Path = strings.Replace(repo.Path, "$HOME", homeDir, 1)
|
||||
}
|
||||
}
|
||||
conf.ExpandPaths()
|
||||
return conf
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -54,15 +53,6 @@ var registerCmd = &cobra.Command{
|
||||
}
|
||||
path = newPath.Filesystem.Root()
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Println("Unable to get home directory")
|
||||
os.Exit(1)
|
||||
}
|
||||
if strings.HasPrefix(path, homeDir) {
|
||||
path = "$HOME" + path[len(homeDir):]
|
||||
}
|
||||
|
||||
for _, v := range conf.Repos {
|
||||
if v.Path == path {
|
||||
fmt.Printf("repo %s already registered\n", path)
|
||||
|
||||
@@ -2,14 +2,44 @@ package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func getVersion() string {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "dev"
|
||||
}
|
||||
if info.Main.Version != "" && info.Main.Version != "(devel)" {
|
||||
return info.Main.Version
|
||||
}
|
||||
var revision, dirty string
|
||||
for _, s := range info.Settings {
|
||||
switch s.Key {
|
||||
case "vcs.revision":
|
||||
revision = s.Value
|
||||
case "vcs.modified":
|
||||
if s.Value == "true" {
|
||||
dirty = "-dirty"
|
||||
}
|
||||
}
|
||||
}
|
||||
if revision != "" {
|
||||
if len(revision) > 7 {
|
||||
revision = revision[:7]
|
||||
}
|
||||
return revision + dirty
|
||||
}
|
||||
return "dev"
|
||||
}
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "mg",
|
||||
Short: "go replacement for myrepos which only supports git repos",
|
||||
Use: "mg",
|
||||
Short: "go replacement for myrepos which only supports git repos",
|
||||
Version: getVersion(),
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
|
||||
Reference in New Issue
Block a user