starting client/server connection
This commit is contained in:
152
client/client.go
152
client/client.go
@@ -25,7 +25,7 @@ func main() {
|
||||
var err error
|
||||
rootPath, err = os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Can't get working dir, permissions issue %s", err)
|
||||
log.Fatalf("Can't get working dir, permissions issue? %s", err)
|
||||
}
|
||||
|
||||
// Setting up a blank config to read the .toml file in if one exists
|
||||
@@ -34,7 +34,8 @@ func main() {
|
||||
if isRepo {
|
||||
err := store.Load(configPath, &conf)
|
||||
if err != nil {
|
||||
fmt.Println("Error loading config file into struct! ", err)
|
||||
fmt.Printf("Error loading config file into struct, please fix config, panic! \n%s", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
err = clientconfig.ValidateConfig(&conf, version)
|
||||
if err != nil {
|
||||
@@ -54,10 +55,17 @@ func main() {
|
||||
// Adding the ignore commands
|
||||
ignoreCommands(cli, &conf)
|
||||
|
||||
// Adding the test commands
|
||||
infoCommands(cli, &conf)
|
||||
|
||||
err = cli.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred: %v\n", err)
|
||||
}
|
||||
err = store.Save(configPath, conf)
|
||||
if err != nil {
|
||||
fmt.Println("Error saving config to file, changes were not writted! Check config file... ", err)
|
||||
}
|
||||
}
|
||||
|
||||
// injectVariables just injects the global variables into the packages
|
||||
@@ -211,16 +219,16 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||
}
|
||||
if file != "" { // if the file flag was used it won't be empty
|
||||
fmt.Println("Ignoring file to tracked files: ", file)
|
||||
err := clientcmd.IgnoreFiles(file, "file", conf.Ignores)
|
||||
//fmt.Println("Ignoring file: ", file)
|
||||
err := clientcmd.IgnoreFiles(file, "file", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if folder != "" { // if the folder flag was used it won't be empty
|
||||
fmt.Println("Ignoring contents of folder to tracked files: ", folder)
|
||||
err := clientcmd.IgnoreFiles(folder, "folder", conf.Ignores)
|
||||
fmt.Println("Ignoring contents of folder: ", folder)
|
||||
err := clientcmd.IgnoreFiles(folder, "folder", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -228,7 +236,62 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
|
||||
err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf.Ignores)
|
||||
err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// Adding the remove ignore command (remove from the ignore list)
|
||||
removeIgnoreCmd(ignoreCmd, conf)
|
||||
|
||||
}
|
||||
|
||||
// removeIgnoreCmd removes files/folders/wildcard from the ignore list
|
||||
func removeIgnoreCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
|
||||
removeIgnoreCmd := ignoreCmd.NewSubCommand("remove", "remove from ignores file(s)/folder(s) (recursively for folder) to repo")
|
||||
removeIgnoreCmd.LongDescription("You can remove from ignore all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt")
|
||||
//File/Folder/Wildcard Ignoring
|
||||
var file string
|
||||
var folder string
|
||||
var wildcard string
|
||||
fileFlag := removeIgnoreCmd.StringFlag("file", "removes ignored file from config", &file)
|
||||
fileFlag.FlagShortCut("file", "f")
|
||||
folderFlag := removeIgnoreCmd.StringFlag("folder", "removes ignored folder", &folder)
|
||||
folderFlag.FlagShortCut("folder", "fd")
|
||||
wildCardFlag := removeIgnoreCmd.StringFlag("wildcard", "removes wildcard from ignores", &wildcard)
|
||||
wildCardFlag.FlagShortCut("wildcard", "wc")
|
||||
removeIgnoreCmd.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(removeIgnoreCmd.OtherArgs()) > 0 {
|
||||
removeIgnoreCmd.PrintHelp()
|
||||
return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||
}
|
||||
if file != "" { // if the file flag was used it won't be empty
|
||||
//fmt.Println("Ignoring file: ", file)
|
||||
err := clientcmd.RemoveIgnoreFiles(file, "file", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if folder != "" { // if the folder flag was used it won't be empty
|
||||
fmt.Println("Ignoring contents of folder: ", folder)
|
||||
err := clientcmd.RemoveIgnoreFiles(folder, "folder", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
|
||||
err := clientcmd.RemoveIgnoreFiles(wildcard, "wildcard", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -237,3 +300,78 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
//All the test 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")
|
||||
|
||||
remoteInfoCmd := infoCmd.NewSubCommand("remote", "takes the suppled server name and gets information about the server")
|
||||
remoteInfoCmd.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(remoteInfoCmd.OtherArgs()) == 0 {
|
||||
remoteInfoCmd.PrintHelp()
|
||||
return fmt.Errorf("Please supply a server name to test a remote")
|
||||
}
|
||||
server := remoteInfoCmd.OtherArgs()[0]
|
||||
conn, err := clientcmd.ConnectToServer(server, "master", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = clientcmd.GetServerInfo(conn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// //File/Folder/Wildcard Ignoring
|
||||
// var file string
|
||||
// var folder string
|
||||
// var wildcard string
|
||||
// fileFlag := ignoreCmd.StringFlag("file", "adds a file to ignore to the config", &file)
|
||||
// fileFlag.FlagShortCut("file", "f")
|
||||
// folderFlag := ignoreCmd.StringFlag("folder", "tracks all contents of a folder to ignore", &folder)
|
||||
// folderFlag.FlagShortCut("folder", "fd")
|
||||
// wildCardFlag := ignoreCmd.StringFlag("wildcard", "treats the input as a wildcard and ignores all files that match the wildcard", &wildcard)
|
||||
// wildCardFlag.FlagShortCut("wildcard", "wc")
|
||||
// ignoreCmd.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(ignoreCmd.OtherArgs()) > 0 {
|
||||
// ignoreCmd.PrintHelp()
|
||||
// return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||
// }
|
||||
// if file != "" { // if the file flag was used it won't be empty
|
||||
// //fmt.Println("Ignoring file: ", file)
|
||||
// err := clientcmd.IgnoreFiles(file, "file", conf)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// if folder != "" { // if the folder flag was used it won't be empty
|
||||
// fmt.Println("Ignoring contents of folder: ", folder)
|
||||
// err := clientcmd.IgnoreFiles(folder, "folder", conf)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||
// fmt.Println("Ignoring files with wildcard filter: ", wildcard)
|
||||
// err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
}
|
||||
|
Reference in New Issue
Block a user