github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/git.go (about)

     1  package parser
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/teamhephy/workflow-cli/cmd"
     7  	docopt "github.com/docopt/docopt-go"
     8  )
     9  
    10  // Git routes git commands to their specific function.
    11  func Git(argv []string, cmdr cmd.Commander) error {
    12  	usage := `
    13  Valid commands for git:
    14  
    15  git:remote          Adds git remote of application to repository
    16  git:remove          Removes git remote of application from repository
    17  
    18  Use 'deis help [command]' to learn more.
    19  `
    20  
    21  	switch argv[0] {
    22  	case "git:remote":
    23  		return gitRemote(argv, cmdr)
    24  	case "git:remove":
    25  		return gitRemove(argv, cmdr)
    26  	case "git":
    27  		fmt.Print(usage)
    28  		return nil
    29  	default:
    30  		PrintUsage(cmdr)
    31  		return nil
    32  	}
    33  }
    34  
    35  func gitRemote(argv []string, cmdr cmd.Commander) error {
    36  	usage := `
    37  Adds git remote of application to repository
    38  
    39  Usage: deis git:remote [options]
    40  
    41  Options:
    42    -a --app=<app>
    43      the uniquely identifiable name for the application.
    44    -r --remote=REMOTE
    45      name of remote to create. [default: deis]
    46    -f --force
    47      overwrite remote of the given name if it already exists.
    48  `
    49  
    50  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    51  
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	app := safeGetValue(args, "--app")
    57  	remote := safeGetValue(args, "--remote")
    58  	force := args["--force"].(bool)
    59  
    60  	return cmdr.GitRemote(app, remote, force)
    61  }
    62  
    63  func gitRemove(argv []string, cmdr cmd.Commander) error {
    64  	usage := `
    65  Removes git remotes of application from repository.
    66  
    67  Usage: deis git:remove [options]
    68  
    69  Options:
    70    -a --app=<app>
    71      the uniquely identifiable name for the application.
    72  `
    73  
    74  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    75  
    76  	if err != nil {
    77  		return err
    78  	}
    79  
    80  	return cmdr.GitRemove(safeGetValue(args, "--app"))
    81  }