github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/genny/vcs/vcs.go (about)

     1  package vcs
     2  
     3  import (
     4  	"embed"
     5  	"fmt"
     6  	"os/exec"
     7  
     8  	"github.com/gobuffalo/genny/v2"
     9  )
    10  
    11  //go:embed templates/*
    12  var templates embed.FS
    13  
    14  // New generator for adding VCS to an application
    15  func New(opts *Options) (*genny.Generator, error) {
    16  	g := genny.New()
    17  
    18  	if err := opts.Validate(); err != nil {
    19  		return g, err
    20  	}
    21  
    22  	if opts.Provider == "none" {
    23  		return g, nil
    24  	}
    25  
    26  	f, err := templates.Open("templates/ignore.tmpl")
    27  	if err != nil {
    28  		return g, err
    29  	}
    30  
    31  	p := opts.Provider
    32  	n := fmt.Sprintf(".%signore", p)
    33  	g.File(genny.NewFile(n, f))
    34  	g.Command(exec.Command(p, "init"))
    35  
    36  	args := []string{"add", "."}
    37  	if p == "bzr" {
    38  		// Ensure Bazaar is as quiet as Git
    39  		args = append(args, "-q")
    40  	}
    41  	g.Command(exec.Command(p, args...))
    42  	g.Command(exec.Command(p, "commit", "-q", "-m", "Initial Commit"))
    43  	return g, nil
    44  }