func (v *vcsCmd) run(dir string, cmd string, keyval ...string) error {
	_, err := v.run1(dir, cmd, keyval, true)
	return err
}
run runs the command line cmd in the given directory.
keyval is a list of key, value pairs.  run expands
instances of {key} in cmd into value, but only after
splitting cmd into individual arguments.
If an error occurs, run prints the command line and the
command's combined stdout+stderr to standard error.
Otherwise run discards the command's output.
package main
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"go/build"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strings"
)
type vcsCmd struct {
	name string
	cmd  string  
	createCmd   string  
	downloadCmd string  
	tagCmd         []tagCmd  
	tagLookupCmd   []tagCmd  
	tagSyncCmd     string    
	tagSyncDefault string    
	scheme  []string
	pingCmd string
}
type tagCmd struct {
	cmd     string  
	pattern string  
}
var vcsList = []*vcsCmd{
	vcsHg,
	vcsGit,
	vcsSvn,
	vcsBzr,
}
func vcsByCmd(cmd string) *vcsCmd {
	for _, vcs := range vcsList {
		if vcs.cmd == cmd {
			return vcs
		}
	}
	return nil
}
var vcsHg = &vcsCmd{
	name: "Mercurial",
	cmd:  "hg",
	createCmd:   "clone -U {repo} {dir}",
	downloadCmd: "pull",
	tagCmd: []tagCmd{
		{"tags", `^(\S+)`},
		{"branches", `^(\S+)`},
	},
	tagSyncCmd:     "update -r {tag}",
	tagSyncDefault: "update default",
	scheme:  []string{"https", "http", "ssh"},
	pingCmd: "identify {scheme}://{repo}",
}
var vcsGit = &vcsCmd{
	name: "Git",
	cmd:  "git",
	createCmd:   "clone {repo} {dir}",
	downloadCmd: "pull --ff-only --tags",
	tagCmd: []tagCmd{
		{"show-ref", `(?:tags|origin)/(\S+)$`},
	},
	tagLookupCmd: []tagCmd{
		{"show-ref tags/{tag} origin/{tag}", `((?:tags|origin)/\S+)$`},
	},
	tagSyncCmd:     "checkout -f {tag} --",
	tagSyncDefault: "checkout -f master --",
	scheme:  []string{"git", "https", "http", "git+ssh"},
	pingCmd: "ls-remote {scheme}://{repo}",
}
var vcsBzr = &vcsCmd{
	name: "Bazaar",
	cmd:  "bzr",
	createCmd: "branch {repo} {dir}",
	downloadCmd: "pull --overwrite",
	tagCmd:         []tagCmd{{"tags", `^(\S+)`}},
	tagSyncCmd:     "update -r {tag}",
	tagSyncDefault: "update -r revno:-1",
	scheme:  []string{"https", "http", "bzr", "bzr+ssh"},
	pingCmd: "info {scheme}://{repo}",
}
var vcsSvn = &vcsCmd{
	name: "Subversion",
	cmd:  "svn",
	createCmd:   "checkout {repo} {dir}",
	downloadCmd: "update",
	scheme:  []string{"https", "http", "svn", "svn+ssh"},
	pingCmd: "info {scheme}://{repo}",
}
func (v *vcsCmd) String() string {
	return v.name
}