working on 'add remote' command and 'refresh' command
This commit is contained in:
@@ -58,6 +58,9 @@ func main() {
|
||||
// Adding the test commands
|
||||
infoCommands(cli, &conf)
|
||||
|
||||
// Adding the refresh command
|
||||
refreshCommand(cli, &conf)
|
||||
|
||||
err = cli.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred: %v\n", err)
|
||||
@@ -82,6 +85,20 @@ func validateRepo() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func refreshCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
refreshCmd := cli.NewSubCommand("refresh", "pulls down all locks unknown to client pushes")
|
||||
refreshCmd.LongDescription("Works similar to git fetch where it shows the number of commits pushed to server/branches that the client doesn't know as well as file/folder locks")
|
||||
refreshCmd.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
//The init subcommand
|
||||
initCmd := cli.NewSubCommand("init", "initializes a new gvc repo")
|
||||
@@ -91,7 +108,8 @@ func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
if !isRepo {
|
||||
clientcmd.InitializeRepo() // creates and checks the paths
|
||||
newConf := clientconfig.Gvcconfig{
|
||||
Version: version,
|
||||
Version: version,
|
||||
CurrentBranch: "master",
|
||||
}
|
||||
err := store.Save(configPath, &newConf)
|
||||
if err != nil {
|
||||
@@ -157,8 +175,13 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
})
|
||||
|
||||
//Add all files recursively to repo
|
||||
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) recursively to repo")
|
||||
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) in root dir recursively to repo")
|
||||
addall.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(addall.OtherArgs()) > 0 {
|
||||
addCmd.PrintHelp()
|
||||
return fmt.Errorf("the 'all' subcommand does not accept additional arguments")
|
||||
@@ -176,6 +199,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
var name string
|
||||
var host string
|
||||
var port int
|
||||
var defaultRemote bool
|
||||
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")
|
||||
nameFlag := remoteAddCmd.StringFlag("name", "the name you want for your remote server", &name)
|
||||
@@ -187,7 +211,23 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
portFlag := remoteAddCmd.IntFlag("port", "the port the remote server is listening on", &port)
|
||||
portFlag.FlagShortCut("port", "p")
|
||||
remoteAddCmd.FlagRequired("port")
|
||||
defaultFlag := remoteAddCmd.BoolFlag("default", "is used, the repo is set as default. (if first remote automatically set as default)", &defaultRemote)
|
||||
defaultFlag.FlagShortCut("default", "d")
|
||||
remoteAddCmd.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 name == "" || host == "" || port == 0 || port == 1 || port > 65535 {
|
||||
fmt.Println("incorrect input found, exiting, ensure you entered a valid port")
|
||||
os.Exit(0)
|
||||
}
|
||||
newRemotes, err := clientcmd.AddRemote(name, host, port, defaultRemote, conf.Remotes)
|
||||
conf.Remotes = newRemotes //Overwriting the old Remote list with new list
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding remote: %s", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -302,7 +342,7 @@ func removeIgnoreCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
|
||||
func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
//All the test commands
|
||||
//All the info 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")
|
||||
|
||||
|
Reference in New Issue
Block a user