working on 'add remote' command and 'refresh' command
This commit is contained in:
@@ -1,10 +1,36 @@
|
||||
version = "0.1.5"
|
||||
rootPath = ""
|
||||
currentBranch = "master"
|
||||
|
||||
[[remote]]
|
||||
name = "test"
|
||||
name = "test2"
|
||||
host = "localhost"
|
||||
port = 9999
|
||||
default = false
|
||||
|
||||
[[remote]]
|
||||
name = "test4"
|
||||
host = "localhost"
|
||||
port = 9998
|
||||
default = false
|
||||
|
||||
[[remote]]
|
||||
name = "test3"
|
||||
host = "localhost"
|
||||
port = 9997
|
||||
default = false
|
||||
|
||||
[[remote]]
|
||||
name = "test5"
|
||||
host = "localhost1"
|
||||
port = 9997
|
||||
default = true
|
||||
|
||||
[[remote]]
|
||||
name = "test6"
|
||||
host = "localhost1"
|
||||
port = 9995
|
||||
default = false
|
||||
|
||||
[ignore]
|
||||
files = ["client1.exe", "client2.exe", "client3.exe", "client4.exe", "client5.exe", "client6.exe", "client7.exe", "test1\\client8.exe", "clientcmd\\init.go"]
|
||||
|
@@ -5,11 +5,13 @@ rootPath = "client"
|
||||
name = "origin"
|
||||
host = "testorigin.com"
|
||||
port = 8694
|
||||
default = true
|
||||
|
||||
[[remote]]
|
||||
name = "secondOrigin"
|
||||
host = "170.5.95.195"
|
||||
port = 4253
|
||||
default = false
|
||||
|
||||
[ignore]
|
||||
files = ["file1.txt", "file2.txt"]
|
||||
|
@@ -58,6 +58,9 @@ func main() {
|
||||
// Adding the test commands
|
||||
infoCommands(cli, &conf)
|
||||
|
||||
// Adding the refresh command
|
||||
refreshCommand(cli, &conf)
|
||||
|
||||
err = cli.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred: %v\n", err)
|
||||
@@ -82,6 +85,20 @@ func validateRepo() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func refreshCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
refreshCmd := cli.NewSubCommand("refresh", "pulls down all locks unknown to client pushes")
|
||||
refreshCmd.LongDescription("Works similar to git fetch where it shows the number of commits pushed to server/branches that the client doesn't know as well as file/folder locks")
|
||||
refreshCmd.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
//The init subcommand
|
||||
initCmd := cli.NewSubCommand("init", "initializes a new gvc repo")
|
||||
@@ -91,7 +108,8 @@ func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
if !isRepo {
|
||||
clientcmd.InitializeRepo() // creates and checks the paths
|
||||
newConf := clientconfig.Gvcconfig{
|
||||
Version: version,
|
||||
Version: version,
|
||||
CurrentBranch: "master",
|
||||
}
|
||||
err := store.Save(configPath, &newConf)
|
||||
if err != nil {
|
||||
@@ -157,8 +175,13 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
})
|
||||
|
||||
//Add all files recursively to repo
|
||||
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) recursively to repo")
|
||||
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) in root dir recursively to repo")
|
||||
addall.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||
os.Exit(0)
|
||||
}
|
||||
if len(addall.OtherArgs()) > 0 {
|
||||
addCmd.PrintHelp()
|
||||
return fmt.Errorf("the 'all' subcommand does not accept additional arguments")
|
||||
@@ -176,6 +199,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
var name string
|
||||
var host string
|
||||
var port int
|
||||
var defaultRemote bool
|
||||
remoteAddCmd := remoteCmd.NewSubCommand("add", "add a remote, requires -name -host and -port")
|
||||
remoteAddCmd.LongDescription("Adds a remote to the .gvcconfig.toml. Requires the -name, -host and -port flags. Example: gvc remote add -name exampleRemote -host examplehost.com -port 8080")
|
||||
nameFlag := remoteAddCmd.StringFlag("name", "the name you want for your remote server", &name)
|
||||
@@ -187,7 +211,23 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
portFlag := remoteAddCmd.IntFlag("port", "the port the remote server is listening on", &port)
|
||||
portFlag.FlagShortCut("port", "p")
|
||||
remoteAddCmd.FlagRequired("port")
|
||||
defaultFlag := remoteAddCmd.BoolFlag("default", "is used, the repo is set as default. (if first remote automatically set as default)", &defaultRemote)
|
||||
defaultFlag.FlagShortCut("default", "d")
|
||||
remoteAddCmd.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||
os.Exit(0)
|
||||
}
|
||||
if name == "" || host == "" || port == 0 || port == 1 || port > 65535 {
|
||||
fmt.Println("incorrect input found, exiting, ensure you entered a valid port")
|
||||
os.Exit(0)
|
||||
}
|
||||
newRemotes, err := clientcmd.AddRemote(name, host, port, defaultRemote, conf.Remotes)
|
||||
conf.Remotes = newRemotes //Overwriting the old Remote list with new list
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding remote: %s", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -302,7 +342,7 @@ func removeIgnoreCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
|
||||
func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
//All the test commands
|
||||
//All the info commands
|
||||
infoCmd := cli.NewSubCommand("info", "tests various aspects of the client/files/etc and server")
|
||||
infoCmd.LongDescription("You can get information on remotes, files, etc")
|
||||
|
||||
|
@@ -131,8 +131,62 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRemote adds a remote to the config file
|
||||
func AddRemote(name string, host string, port int, conf *clientconfig.Gvcconfig) error {
|
||||
fmt.Println("name: ", name, "host: ", host, "port: ", port)
|
||||
// checkRemotesSlice just ranges through the remotes looking for duplicates
|
||||
func checkRemotesSlice(name, host string, port int, remotes []clientconfig.Remote) error {
|
||||
for _, remote := range remotes { // Names of remotes must be unique so make sure they are
|
||||
if name == remote.Name {
|
||||
return fmt.Errorf("remote with that name already exits: %s", name)
|
||||
}
|
||||
}
|
||||
for _, remote := range remotes { // make sure we don't have another remote with same host and port
|
||||
if host == remote.Host && port == remote.Port {
|
||||
return fmt.Errorf("remote with that host and port config already exists: %s:%d", host, port)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRemote adds a remote to the config file
|
||||
func AddRemote(name string, host string, port int, defaultRemote bool, remotes []clientconfig.Remote) (newRemotes []clientconfig.Remote, err error) {
|
||||
if len(remotes) == 0 { //first remote no need to check for duplicates and will set this remote as default
|
||||
newRemote := clientconfig.Remote{
|
||||
Name: name,
|
||||
Host: host,
|
||||
Port: port,
|
||||
Default: true,
|
||||
}
|
||||
remotes = append(remotes, newRemote)
|
||||
fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
|
||||
return remotes, nil
|
||||
}
|
||||
err = checkRemotesSlice(name, host, port, remotes)
|
||||
if err != nil {
|
||||
return remotes, err
|
||||
}
|
||||
if defaultRemote { // If the new repo was flagged as default, find old default and remove it
|
||||
for i, remote := range remotes {
|
||||
if remote.Default {
|
||||
remotes[i].Default = false
|
||||
}
|
||||
}
|
||||
newRemote := clientconfig.Remote{
|
||||
Name: name,
|
||||
Host: host,
|
||||
Port: port,
|
||||
Default: true,
|
||||
}
|
||||
remotes = append(remotes, newRemote)
|
||||
fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
|
||||
return remotes, nil
|
||||
}
|
||||
// If passes all checks and is not default, create it and add it
|
||||
newRemote := clientconfig.Remote{
|
||||
Name: name,
|
||||
Host: host,
|
||||
Port: port,
|
||||
Default: false,
|
||||
}
|
||||
remotes = append(remotes, newRemote)
|
||||
fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
|
||||
return remotes, nil
|
||||
}
|
||||
|
@@ -80,5 +80,5 @@ func ConnectToServer(serverName string, branchName string, conf *clientconfig.Gv
|
||||
return &conn, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("unable to find server name in config...")
|
||||
return nil, fmt.Errorf("unable to find server name in config")
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// GetServerInfo queries the supplied server name for information about the server
|
||||
func GetServerInfo(conn *net.Conn) error {
|
||||
for { // Server should send 'Connected\n' to client after connect, then client can ask for server details
|
||||
message, err := bufio.NewReader(*conn).ReadString('\n')
|
||||
|
43
client/clientcmd/refresh.go
Normal file
43
client/clientcmd/refresh.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,18 +2,20 @@ package config
|
||||
|
||||
//Gvcconfig will be the struct that holds the entire client settings
|
||||
type Gvcconfig struct {
|
||||
Version string `toml:"version"`
|
||||
RootPath string `toml:"rootPath"`
|
||||
Remotes []Remote `toml:"remote"` //The remote servers for the repo
|
||||
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
|
||||
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
|
||||
Version string `toml:"version"`
|
||||
RootPath string `toml:"rootPath"`
|
||||
CurrentBranch string `toml:"currentbranch"`
|
||||
Remotes []Remote `toml:"remote"` //The remote servers for the repo
|
||||
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
|
||||
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
|
||||
}
|
||||
|
||||
//Remote will be a slice of remote server information
|
||||
type Remote struct {
|
||||
Name string `toml:"name"`
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
Name string `toml:"name"`
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
Default bool `toml:"default"` //Is this repo the default repo?
|
||||
}
|
||||
|
||||
//Ignore is for ignoring files to add or ignoring compress
|
||||
@@ -22,3 +24,10 @@ type Ignore struct {
|
||||
Exts []string `toml:"exts"`
|
||||
Folders []string `toml:"folders"`
|
||||
}
|
||||
|
||||
//Locked is a list of locked files/folders/wildcards
|
||||
type Locked struct {
|
||||
Files []string `toml:"files"`
|
||||
Exts []string `toml:"exts"`
|
||||
Folders []string `toml:"folders"`
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ func main() {
|
||||
})
|
||||
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
|
||||
// connection with client lost
|
||||
fmt.Println("Connection with client closed")
|
||||
})
|
||||
|
||||
server.Listen()
|
||||
|
Reference in New Issue
Block a user