adding lock command, generalizing the checkfiletypes function

This commit is contained in:
2020-06-04 17:38:26 -04:00
parent 0276a1d776
commit db2221c515
8 changed files with 348 additions and 118 deletions

View File

@@ -0,0 +1,52 @@
package clientcmd
import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
// 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
}