adjust output and add exist repo warning

This commit is contained in:
Zoker 2020-06-13 01:40:35 +08:00
parent 250c8a029d
commit 3ef79b2d1f
2 changed files with 25 additions and 6 deletions

View File

@ -26,7 +26,7 @@ const (
EXIST int = 1
ERROR int = 2
SKIP string = "1"
SPL string = "------------------------------"
SPL string = "\n"
)
func GiteeCommand() *gcli.Command {
@ -292,9 +292,10 @@ func printRepo(repoRes []RepoResult, status int) int {
} else {
result = item.uri
}
p = fmt.Sprintf("Dir: (%s)\n Status: %s\n Result: %s", item.local, repoStatus, result)
p = fmt.Sprintf("Dir: (%s)\n Status: %s\n Result: ", item.local, repoStatus)
colorRepo(status, p)
fmt.Println(SPL)
colorResult(status, result)
fmt.Printf(SPL)
}
}
return errorNum
@ -314,9 +315,10 @@ func printSync(syncRes []RepoResult, status int) {
} else {
result = item.error
}
p = fmt.Sprintf("Dir: (%s)\n Gitee: %s\n Result: %s", item.local, item.uri, result)
p = fmt.Sprintf("Dir: (%s)\n Gitee: %s\n Result: ", item.local, item.uri)
colorRepo(EXIST, p)
fmt.Println(SPL)
colorResult(item.status, result)
fmt.Printf(SPL)
}
}
}
@ -339,7 +341,20 @@ func repoStatus(status int) string {
func colorRepo(status int, p string) {
switch status {
case SUCCESS:
color.Blue.Println(p)
color.Green.Printf(p)
case EXIST:
color.Yellow.Printf(p)
case ERROR:
color.Red.Printf(p)
default:
color.Red.Printf(p)
}
}
func colorResult(status int, p string) {
switch status {
case SUCCESS:
color.Green.Println(p)
case EXIST:
color.Yellow.Println(p)
case ERROR:

View File

@ -215,6 +215,7 @@ func AskError() string {
}
func AskExist() string {
color.Notice.Println("WARNING: The exist project will remain private attribute as what it was!")
howTo := []string{"Exit and fix them",
"Skip them",
"Overwrite the remote (same as git push --force, you need exactly know what you do before you select this item)"}
@ -228,12 +229,15 @@ func selectOne(items []string, ques string) string {
func SyncRepo(auth *http.BasicAuth ,local string, uri string, force string) error {
var forceStr string
// generate a tmp remote
remote := fmt.Sprintf("up2GitX-%d", time.Now().Unix())
r, err := git.PlainOpen(local)
if err != nil {
return err
}
// delete this remote after sync whether success or not
defer deleteRemote(r, remote)
_, err = r.CreateRemote(&config.RemoteConfig{
Name: remote,