96 lines
3.1 KiB
Go
96 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
clir "github.com/deranjer/clir"
|
|
clientcmd "github.com/deranjer/gvc/client/clientcmd"
|
|
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
|
"github.com/deranjer/store"
|
|
)
|
|
|
|
var version = "0.1.5"
|
|
|
|
func main() {
|
|
var conf clientconfig.Gvcconfig
|
|
|
|
err := store.Load(".gvcconfig.toml", &conf)
|
|
if err != nil {
|
|
fmt.Println("Error loading config file into struct! ", err)
|
|
}
|
|
clientconfig.ValidateConfig(&conf, version)
|
|
|
|
// Initialize our new cli
|
|
cli := clir.NewCli("gvcc", "Version control client for GVC", version)
|
|
|
|
// Adding the init command
|
|
initCommand(cli, &conf)
|
|
|
|
// Adding all the "add" commands
|
|
addCommands(cli, &conf)
|
|
|
|
err = cli.Run()
|
|
if err != nil {
|
|
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 = store.Save(".gvcconfigNew.toml", &conf)
|
|
if err != nil {
|
|
fmt.Println("Error saving config back to toml file: ", err)
|
|
}
|
|
|
|
}
|
|
|
|
// validateRepo just ensures that the command is being run against an actual repo (bool yes or no)
|
|
func validateRepo() bool {
|
|
if _, err := os.Stat(".gvcconfig.toml"); os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
|
//The init subcommand
|
|
initCmd := cli.NewSubCommand("init", "initializes a new gvc repo")
|
|
initCmd.LongDescription("This will create the .gvcconfig.toml (with defaults) file in this directory. You can edit this file directly (unsafe) or with the client(safe)")
|
|
initCmd.Action(func() error {
|
|
isRepo := validateRepo()
|
|
if !isRepo {
|
|
err := clientcmd.InitializeRepo()
|
|
if err != nil {
|
|
err = fmt.Errorf("unable to initialize repo: %s", err)
|
|
fmt.Println(err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
fmt.Println("appears that this directory is already a gvc repo")
|
|
return nil
|
|
})
|
|
}
|
|
|
|
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")
|
|
//File/Folder/Wildcard adding
|
|
addCmd.Action(clientcmd.AddFiles)
|
|
//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
|
|
remoteCmd := cli.NewSubCommand("remote", "add/delete/show remotes")
|
|
var name string
|
|
var host string
|
|
var port int
|
|
remoteAddCmd := remoteCmd.NewSubCommand("add", "add a remote, requires -name -host and -port")
|
|
remoteAddCmd.LongDescription("Adds a remote to the .gvcconfig.toml. Requires the -name, -host and -port flags. Example: gvc remote add -name exampleRemote -host examplehost.com -port 8080")
|
|
remoteAddCmd.StringFlag("name", "the name you want for your remote server", &name)
|
|
remoteAddCmd.StringFlag("host", "the hostname or IP Address of the remote", &host)
|
|
remoteAddCmd.IntFlag("port", "the port the remote server is listening on", &port)
|
|
|
|
}
|