grim/hgkeeper

all: use standard Go reflect.StructTag format.
styling
2019-04-17, Wagner Riffel
028c0cc77dd3
all: use standard Go reflect.StructTag format.
Mainly because go vet marks this as "suspicious construct", refs:
https://golang.org/pkg/reflect/#StructTag
https://golang.org/cmd/vet
package setup
import (
"io/ioutil"
"os"
"path/filepath"
"bitbucket.org/rw_grim/hgkeeper/hg"
)
type SetupCommand struct {
AdminRepo string `kong:"flag,name='admin-repo',default='hgkeeper',help='the name of the admin repo to create'"`
adminRepoPath string
}
type setupFunc func(string) error
var (
hgrc = `# this file was created by hgkeeper, do not modify
[extensions]
hgext.purge =
[hooks]
changegroup.aaab = hg update -C default > /dev/null
changegroup.aaac = hg purge --all > /dev/null
changegroup.aaad = hgkeeper refresh-auth
`
)
func (c *SetupCommand) Run(reposPath string) error {
c.adminRepoPath = filepath.Join(reposPath, c.AdminRepo)
funcs := []setupFunc{
c.createReposDir,
c.createAdminRepo,
}
for _, f := range funcs {
err := f(reposPath)
if err != nil {
return err
}
}
return nil
}
func (c *SetupCommand) createReposDir(reposPath string) error {
if _, err := os.Stat(reposPath); os.IsNotExist(err) {
err := os.MkdirAll(reposPath, 0755)
if err != nil {
return err
}
}
return nil
}
func (c *SetupCommand) createAdminRepo(reposPath string) error {
repo, err := hg.NewRepository(c.adminRepoPath)
if err != nil {
return err
}
err = repo.Init(0700)
if err != nil {
return err
}
hgrc_path := filepath.Join(c.adminRepoPath, ".hg", "hgrc")
return ioutil.WriteFile(hgrc_path, []byte(hgrc), 0644)
}