Skip to content

Commit

Permalink
Add argument to specify the template url
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Weinert committed Jun 2, 2021
1 parent f9c6b65 commit 4cb82f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cmd/felix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
initCommand = app.Command("init", "creates new service in current directory")
newCommand = app.Command("new", "creates new service in new directory")
name = newCommand.Arg("name", "the name of the new service and directory you want to create").Required().String()

templateURL = app.Flag("template", "github url for the template").Short('t').String()
)

func main() {
Expand All @@ -48,7 +50,9 @@ func getVersion(c *kingpin.ParseContext) error {
}

func felixInit(c *kingpin.ParseContext) error {
tmp := builder.Template{}
tmp := builder.Template{
URL: *templateURL,
}

if err := builder.Init(&tmp); err != nil {
fmt.Printf("Something went wrong: %s", err.Error())
Expand All @@ -62,6 +66,7 @@ func felixInit(c *kingpin.ParseContext) error {
func felixNew(c *kingpin.ParseContext) error {
tmp := builder.Template{
Name: *name,
URL: *templateURL,
}

if err := builder.Init(&tmp); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func Init(template *Template) error {
return err
}

cmd := exec.Command("curl", "-L", defaultTemplateURL, "-o", file.Name())
templateURL := template.URL
if templateURL == "" {
templateURL = defaultTemplateURL
}

cmd := exec.Command("curl", "-L", templateURL, "-o", file.Name())
cmd.Run()

reader, err := zip.OpenReader(file.Name())
Expand Down
7 changes: 3 additions & 4 deletions internal/builder/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func copyToTempDir(tmpDir string, reader *zip.ReadCloser) (string, error) {
return "", err
}

defer zipped.Close()

// get the individual file name and extract the current directory
path := filepath.Join(tmpDir, f.Name)
if f.FileInfo().IsDir() {
Expand All @@ -35,12 +33,13 @@ func copyToTempDir(tmpDir string, reader *zip.ReadCloser) (string, error) {
return "", err
}

defer writer.Close()

if _, err = io.Copy(writer, zipped); err != nil {
return "", err
}
writer.Close()
}

zipped.Close()
}

return rootDir, nil
Expand Down
1 change: 1 addition & 0 deletions internal/builder/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Template struct {
Org string
Proj string
Name string
URL string
}

func (b *Builder) parseTemplate(file string) ([]byte, error) {
Expand Down

0 comments on commit 4cb82f5

Please sign in to comment.