improving client/server info command
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
version = "0.1.5"
|
||||
rootPath = ""
|
||||
rootpath = ""
|
||||
reponame = "gvc"
|
||||
currentbranch = "master"
|
||||
localbranches = ["master"]
|
||||
remotebranches = ["master", "test", "test2"]
|
||||
|
@@ -113,8 +113,9 @@ func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
initCmd.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
clientcmd.InitializeRepo() // creates and checks the paths
|
||||
repoName := clientcmd.InitializeRepo() // creates and checks the paths
|
||||
newConf := clientconfig.Gvcconfig{
|
||||
RepoName: repoName,
|
||||
Version: version,
|
||||
CurrentBranch: "master",
|
||||
}
|
||||
@@ -327,11 +328,11 @@ func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
return fmt.Errorf("Please supply a server name to test a remote")
|
||||
}
|
||||
server := remoteInfoCmd.OtherArgs()[0]
|
||||
err := clientcmd.PingServer(server, "master", conf)
|
||||
connectionString, err := clientcmd.FindServer(server, "master", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = clientcmd.GetServerInfo()
|
||||
err = clientcmd.GetServerInfo(connectionString, conf.RepoName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
// ConfigPath is the global path to the config that is injected from the main client package.
|
||||
@@ -62,8 +61,8 @@ func checkFileTypes(input string, inputType string, ignores clientconfig.FileTyp
|
||||
return nil
|
||||
}
|
||||
|
||||
// PingServer sends a quick hello to the server to make sure it is live and we can connect to it. //TODO Remove this is just extra shit
|
||||
func PingServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) error {
|
||||
// FindServer finds the supplied server connection settings, creates a connection string and returns it
|
||||
func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) (connectionString string, err error) {
|
||||
if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch
|
||||
branchName = "master"
|
||||
}
|
||||
@@ -71,19 +70,10 @@ func PingServer(serverName string, branchName string, conf *clientconfig.Gvcconf
|
||||
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 + "/hello" //Create our hello request
|
||||
fmt.Println("Attempting connection on: ", connectionString)
|
||||
client := resty.New()
|
||||
|
||||
resp, err := client.R().EnableTrace().Get(connectionString)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
|
||||
}
|
||||
if resp.StatusCode() == 200 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("response from server was not 200, was instead %d", resp.StatusCode())
|
||||
connectionString := "http://" + remote.Host + port //Create our connection string
|
||||
fmt.Println("Generated connection string: ", connectionString)
|
||||
return connectionString, nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("unable to find server name in config")
|
||||
return "", fmt.Errorf("unable to find server name in config")
|
||||
}
|
||||
|
@@ -6,18 +6,24 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
// GetServerInfo queries the supplied server name for information about the current repo from the server
|
||||
func GetServerInfo() error {
|
||||
serverURL := "http://localhost:80/info/"
|
||||
// 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 {
|
||||
serverURL := connectionString + "/info/" //creating the full string to get info
|
||||
client := resty.New()
|
||||
resp, err := client.R().
|
||||
SetPathParams(map[string]string{
|
||||
"repoName": "testRepo",
|
||||
"repoName": repoName,
|
||||
}).
|
||||
Get(serverURL + "{repoName}")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", serverURL, 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
|
||||
}
|
||||
|
@@ -4,10 +4,11 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// InitializeRepo creates the repo directory and a new config file
|
||||
func InitializeRepo() {
|
||||
func InitializeRepo() string {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal("unable to get current working directory.. permissions issue?")
|
||||
@@ -17,4 +18,7 @@ func InitializeRepo() {
|
||||
if err != nil {
|
||||
fmt.Println(".gvc directory already exists, but no config file... continuing")
|
||||
}
|
||||
repoName := filepath.Base(cwd)
|
||||
fmt.Println("Adding new repo with name: ", repoName)
|
||||
return repoName
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package clientcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
)
|
||||
|
||||
@@ -9,10 +11,11 @@ func RefreshContent(conf *clientconfig.Gvcconfig) error {
|
||||
remotes := conf.Remotes
|
||||
for _, remote := range remotes {
|
||||
if remote.Default {
|
||||
err := PingServer(remote.Name, conf.CurrentBranch, conf)
|
||||
connectionString, err := FindServer(remote.Name, conf.CurrentBranch, conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Connection String; ", connectionString) //TODO: Remove not needed
|
||||
//TODO: Now refresh content
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,8 @@ package config
|
||||
//Gvcconfig will be the struct that holds the entire client settings
|
||||
type Gvcconfig struct {
|
||||
Version string `toml:"version"`
|
||||
RootPath string `toml:"rootPath"`
|
||||
RootPath string `toml:"rootpath"`
|
||||
RepoName string `toml:"reponame"`
|
||||
Remotes []Remote `toml:"remote"` //The remote servers for the repo
|
||||
CurrentBranch string `toml:"currentbranch"`
|
||||
LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches
|
||||
|
Reference in New Issue
Block a user