зеркало из https://github.com/mislav/hub.git
Expand git alias
This commit is contained in:
Родитель
ba29a057c0
Коммит
91b4a17102
|
@ -1,6 +1,7 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jingweno/gh/git"
|
||||
"os"
|
||||
)
|
||||
|
@ -15,6 +16,8 @@ func (r *Runner) Execute() error {
|
|||
usage()
|
||||
}
|
||||
|
||||
expandAlias(args)
|
||||
|
||||
for _, cmd := range All() {
|
||||
if cmd.Name() == args.First() && cmd.Runnable() {
|
||||
cmdArgs := args.Rest()
|
||||
|
@ -54,3 +57,12 @@ func (r *Runner) Execute() error {
|
|||
|
||||
return git.SysExec(args.First(), args.Rest()...)
|
||||
}
|
||||
|
||||
func expandAlias(args *Args) {
|
||||
cmd := args.First()
|
||||
expandedCmd, err := git.Config(fmt.Sprintf("alias.%s", cmd))
|
||||
if err == nil && expandedCmd != "" {
|
||||
args.Remove(0)
|
||||
args.Prepend(expandedCmd)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,15 @@ func Log(sha1, sha2 string) (string, error) {
|
|||
return outputs, nil
|
||||
}
|
||||
|
||||
func Config(name string) (string, error) {
|
||||
output, err := execGitCmd("config", name)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unknown config %s", name)
|
||||
}
|
||||
|
||||
return output[0], nil
|
||||
}
|
||||
|
||||
func SysExec(command string, args ...string) error {
|
||||
cmd := cmd.New("git")
|
||||
cmd.WithArg(command)
|
||||
|
|
Загрузка…
Ссылка в новой задаче