working on lock command

This commit is contained in:
2020-06-08 22:52:40 -04:00
parent c2e74ce7f4
commit 441a9ed233
9 changed files with 132 additions and 48 deletions

View File

@@ -36,7 +36,7 @@ remotebranches = ["master", "test", "test2"]
default = false
[locked]
files = ["test1\\client8.exe", "client1.exe"]
files = ["test1\\client8.exe", "client1.exe", "client.go"]
exts = [".png"]
[ignore]

View File

@@ -55,6 +55,9 @@ func main() {
// Adding the ignore commands
ignoreCommands(cli, &conf)
// Adding the lock commands
lockCommands(cli, &conf)
// Adding the test commands
infoCommands(cli, &conf)
@@ -98,7 +101,7 @@ func refreshCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
err := clientcmd.RefreshContent(conf)
err := clientcmd.RefreshContent(conf, conf.RepoName)
if err != nil {
return fmt.Errorf("unable to refresh content: %s", err)
}
@@ -432,7 +435,7 @@ func remoteCommands(cli *clir.Cli, conf *config.Gvcconfig) {
})
}
func lockCommands(cli clir.Cli, conf *clientconfig.Gvcconfig) {
func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
//All the lock commands and subcommands
//The lock subcommand
@@ -454,7 +457,11 @@ func lockCommands(cli clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
if len(lockCmd.OtherArgs()) > 0 {
if len(lockCmd.OtherArgs()) == 0 && file == "" && folder == "" && wildcard == "" { // if no input
lockCmd.PrintHelp()
return fmt.Errorf("please provide a file/folder/ext flag and name to be locked")
}
if len(lockCmd.OtherArgs()) > 1 {
lockCmd.PrintHelp()
return fmt.Errorf("incorrect input detected, please fix and retry")
}

View File

@@ -36,11 +36,18 @@ func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconf
if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch
branchName = "master"
}
if serverName == "" { // if no serverName is specified, just use the default
for _, remote := range conf.Remotes {
if remote.Default {
serverName = remote.Name
}
}
}
for _, remote := range conf.Remotes {
if serverName == remote.Name {
fmt.Printf("Server found in config, connecting to: %s, host: %s, port: %d \n", remote.Name, remote.Host, remote.Port)
port := ":" + strconv.Itoa(remote.Port)
connectionString := "http://" + remote.Host + port + "/" + conf.RepoName //Create our connection string //'http://server:port/:repo' //TODO, what about admin commands for entire server management, not just one repo?
connectionString := "http://" + remote.Host + port //Create our connection string //'http://server:port'
fmt.Println("Generated connection string: ", connectionString)
return connectionString, nil
}

View File

@@ -9,7 +9,11 @@ import (
// GetServerInfo queries the supplied connection string for server info and uses the provided repoName to get repo specific information
func GetServerInfo(connectionString string, repoName string) error {
client := resty.New()
resp, err := client.R().Get(connectionString + "/info") //creating the full string to get info
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
}).
Get(connectionString + "/info/" + "{repoName}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}

View File

@@ -5,6 +5,7 @@ import (
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
"github.com/go-resty/resty/v2"
)
//LockFiles locks file(s)/folder based on name/wildcard, etc
@@ -14,7 +15,8 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
return err
}
locked := conf.Locked
switch inputType { // TODO: add default case for generic error handling
connectionString, err := FindServer("", conf.CurrentBranch, conf) //TODO: Maybe allow user to specify lock server? Seems like they should just use the default server though
switch inputType { // TODO: add default case for generic error handling // TODO: there is no user supplied input here, so WHY?
case "file":
err := common.CheckFileTypes(input, "file", locked)
if err != nil {
@@ -22,6 +24,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
}
fmt.Println("Adding file to locked: ", input)
conf.Locked.Files = append(conf.Locked.Files, input)
err = SendLockToServer(connectionString, conf.RepoName, "file", input)
if err != nil {
return fmt.Errorf("error sending lock to server: %s", err)
}
return nil
case "folder":
err := common.CheckFileTypes(input, "folder", locked)
@@ -109,3 +115,26 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
}
return fmt.Errorf("This... should not have happened, some kind of internal error on RemoveLockFiles function call, switch failure")
}
// SendLockToServer sends an updated lock file to the server
func SendLockToServer(connectionString string, repoName string, fileType string, fileName string) error {
client := resty.New()
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
"type": fileType,
"name": fileName,
}).
Get(connectionString + "/lock/" + "{repoName}/" + "{type}/" + "{name}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}

View File

@@ -8,33 +8,26 @@ import (
)
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
func RefreshContent(conf *clientconfig.Gvcconfig) error {
remotes := conf.Remotes
for _, remote := range remotes {
if remote.Default {
connectionString, err := FindServer(remote.Name, conf.CurrentBranch, conf)
if err != nil {
return err
}
client := resty.New()
resp, err := client.R().
// SetPathParams(map[string]string{
// "repoName": repoName,
// }).
//Get(connectionString + "{repoName}" + "/info") //creating the full string to get info
Get(connectionString + "/refresh")
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}
func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TODO: need to change command to be able to target user specified servers
connectionString, err := FindServer("", conf.CurrentBranch, conf)
if err != nil {
return err
}
client := resty.New()
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
}).
Get(connectionString + "/refresh" + "{repoName}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}