working on 'add remote' command and 'refresh' command

This commit is contained in:
2020-05-31 23:16:15 -04:00
parent 4fee4cec7d
commit 1a76a8f2aa
9 changed files with 192 additions and 16 deletions

View File

@@ -0,0 +1,43 @@
package clientcmd
import (
"bufio"
"fmt"
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
func RefreshContent(conf *clientconfig.Gvcconfig) error {
remotes := conf.Remotes
for _, remote := range remotes {
if remote.Default {
conn, err := ConnectToServer(remote.Name, conf.CurrentBranch, conf)
if err != nil {
return err
}
for { // Server should send 'Connected\n' to client after connect, then client can ask for server details
message, err := bufio.NewReader(*conn).ReadString('\n')
if err != nil {
return fmt.Errorf("error reading from connection: %s", err)
}
fmt.Printf("Message from server: %s", message)
switch message {
case "Connected\n":
fmt.Println("Server has acknowledged connection, asking for server details")
bytesSent, err := fmt.Fprintf(*conn, "Details\n")
if err != nil {
fmt.Println("Error sending message to server! ", err)
os.Exit(0)
}
if bytesSent > 0 {
fmt.Println("Message Sent")
}
default:
fmt.Println("Details: ", message)
os.Exit(0)
}
}
}
}
}