From 2d743d17c3ee66070db4ffbf680fbb0c66a23508 Mon Sep 17 00:00:00 2001 From: deranjer Date: Wed, 27 May 2020 20:55:33 -0400 Subject: [PATCH] working on the add command --- client/.gvcconfigNew.toml | 13 ++---- client/client.go | 68 ++++++++++++++++++++++++++++--- client/clientcmd/add.go | 10 +---- client/clientconfig/structures.go | 2 +- 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/client/.gvcconfigNew.toml b/client/.gvcconfigNew.toml index 22df86a..c39a6ea 100644 --- a/client/.gvcconfigNew.toml +++ b/client/.gvcconfigNew.toml @@ -1,21 +1,16 @@ -version = 1.0 -RootPath = "client" +version = "0.1.5" +rootPath = "client" [[remote]] name = "origin" - host = "" + host = "testorigin.com" port = 8694 [[remote]] name = "secondOrigin" - host = "" + host = "170.5.95.195" port = 4253 -[[remote]] - name = "my new Remote" - host = "hostname.com" - port = 1234 - [ignore] files = ["file1.txt", "file2.txt"] exts = [".jpg", ".png"] diff --git a/client/client.go b/client/client.go index d7745d4..5190d1b 100644 --- a/client/client.go +++ b/client/client.go @@ -32,10 +32,14 @@ func main() { err = cli.Run() if err != nil { - fmt.Printf("Error occurred: : %v\n", err) + fmt.Printf("Error occurred: %v\n", err) } // After the cli is finished running and writing new values, then validate the input and write it back to the TOML config file - clientconfig.ValidateConfig(&conf, version) + err = clientconfig.ValidateConfig(&conf, version) + if err != nil { + fmt.Println("Error validating config, no changes from the command saved! ", err) + os.Exit(0) + } err = store.Save(".gvcconfigNew.toml", &conf) if err != nil { fmt.Println("Error saving config back to toml file: ", err) @@ -75,13 +79,65 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) { //All the add commands and subcommands //The add subcommand addCmd := cli.NewSubCommand("add", "adds file(s)/folder(s) (recursively for folder) to repo") - addCmd.LongDescription("You can add all: all, a -file: file.txt, or a -folder: folder, or a -wildcard: *.txt") + addCmd.LongDescription("You can add all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt") //File/Folder/Wildcard adding - addCmd.Action(clientcmd.AddFiles) + var file string + var folder string + var wildcard string + fileFlag := addCmd.StringFlag("file", "tracks a file to add to the repo", &file) + fileFlag.FlagShortCut("file", "f") + folderFlag := addCmd.StringFlag("folder", "tracks all contents of a folder to add to the repo", &folder) + folderFlag.FlagShortCut("folder", "fd") + wildCardFlag := addCmd.StringFlag("wildcard", "treats the input as a wildcard and tracks all files that match the wildcard", &wildcard) + wildCardFlag.FlagShortCut("wildcard", "wc") + addCmd.Action(func() error { + if len(addCmd.OtherArgs()) > 0 { + addCmd.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("adding file to tracked files: ", file) + err := clientcmd.AddFiles(file, "file") + if err != nil { + return err + } + return nil + } + if folder != "" { // if the folder flag was used it won't be empty + fmt.Println("adding contents of folder to tracked files: ", folder) + err := clientcmd.AddFiles(folder, "folder") + if err != nil { + return err + } + return nil + } + if wildcard != "" { // if the wildcard flag was used it won't be empty + fmt.Println("adding files with wildcard filter: ", wildcard) + err := clientcmd.AddFiles(wildcard, "wildcard") + if err != nil { + return err + } + return nil + } + return nil + }) + //Add all files recursively to repo addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) recursively to repo") - addall.Action(clientcmd.AddAll) - //The remote command + addall.Action(func() error { + if len(addall.OtherArgs()) > 0 { + addCmd.PrintHelp() + return fmt.Errorf("the 'all' subcommand does not accept additional arguments") + } + fmt.Println("adding all files recursively in directory to tracked files") + err := clientcmd.AddFiles("", "all") + if err != nil { + return err + } + return nil + }) + + //The add remote command remoteCmd := cli.NewSubCommand("remote", "add/delete/show remotes") var name string var host string diff --git a/client/clientcmd/add.go b/client/clientcmd/add.go index 5ad98b4..4f56b46 100644 --- a/client/clientcmd/add.go +++ b/client/clientcmd/add.go @@ -5,14 +5,8 @@ import ( "os" ) -//AddFiles adds files to the repo -func AddFiles() error { +//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all +func AddFiles(input string, inputType string) error { fmt.Println("File/folder/wildcard to add", os.Args[2]) return nil } - -//AddAll adds all files in working dir -func AddAll() error { - fmt.Println("Adding all files", os.Args[2]) - return nil -} diff --git a/client/clientconfig/structures.go b/client/clientconfig/structures.go index ec291e7..a5a2e4f 100644 --- a/client/clientconfig/structures.go +++ b/client/clientconfig/structures.go @@ -3,7 +3,7 @@ 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"` 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