-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from albertrdixon/feature/multi-os
Feature/multi os
- Loading branch information
Showing
3 changed files
with
90 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
os: linux | ||
language: go | ||
go: 1.4.1 | ||
|
||
install: go get github.com/tools/godep | ||
after_success: make build | ||
script: make test-verbose | ||
after_success: make package | ||
|
||
deploy: | ||
provider: releases | ||
api_key: | ||
secure: gE+O8G3DK0jhYc7lIIz9wlRLSZTXau7WdWz3dQqG/DAPvkJbjcGAjA3WmW81KcEs4Ob0ODIdChSGJY5+px/w0aFTdAAP27NvoPRwute2VcLRevpjCglroqz3girj3KUVJmACtya4h/nJZ3Eo20/6/lTJTE6y6W9dVhbwx1DpKlM= | ||
file: t2 | ||
file: | ||
- tnator-linux-amd64.tar.gz | ||
- tnator-darwin-amd64.tar.gz | ||
on: | ||
repo: albertrdixon/tmplnator | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/albertrdixon/tmplnator/template" | ||
"github.com/albertrdixon/tmplnator/version" | ||
"io/ioutil" | ||
"os" | ||
"sync" | ||
"flag" | ||
"fmt" | ||
"github.com/albertrdixon/tmplnator/template" | ||
"github.com/albertrdixon/tmplnator/version" | ||
"io/ioutil" | ||
"os" | ||
"sync" | ||
) | ||
|
||
func exitErr(err error) { | ||
fmt.Printf("There's been a problem: %v", err) | ||
os.Exit(1) | ||
fmt.Printf("There's been a problem: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
func main() { | ||
var ( | ||
V = flag.Bool("version", false, "Print version") | ||
src = flag.String("td", "", "template dir to render") | ||
del = flag.Bool("d", false, "Remove templates after processing") | ||
pre = flag.String("P", "", "Dir prefix") | ||
threads = flag.Int("T", 4, "Render threads") | ||
) | ||
var ( | ||
V = flag.Bool("v", false, "Print version") | ||
src = flag.String("td", "", "template dir to render") | ||
del = flag.Bool("d", false, "Remove templates after processing") | ||
pre = flag.String("P", "", "Dir prefix") | ||
threads = flag.Int("T", 4, "Render threads") | ||
) | ||
|
||
flag.Parse() | ||
if *V { | ||
fmt.Printf("Version: %s\n", version.RuntimeVersion(version.CodeVersion, version.Build)) | ||
os.Exit(0) | ||
} | ||
flag.Parse() | ||
if *V { | ||
fmt.Printf("%s\n", version.RuntimeVersion(version.CodeVersion, version.Build)) | ||
os.Exit(0) | ||
} | ||
|
||
if *src == "" { | ||
fmt.Printf("Sorry, you need to provide the src dir.\n") | ||
os.Exit(1) | ||
} | ||
if *threads < 1 { | ||
*threads = 1 | ||
} | ||
if *src == "" { | ||
fmt.Printf("Sorry, you need to provide the src dir.\n") | ||
os.Exit(1) | ||
} | ||
if *threads < 1 { | ||
*threads = 1 | ||
} | ||
|
||
s, p := *src, *pre | ||
var err error | ||
s, p := *src, *pre | ||
var err error | ||
|
||
if p == "tmp" { | ||
if p, err = ioutil.TempDir("", "tnator"); err != nil { | ||
fmt.Printf("Couldn't get tmp dir.") | ||
exitErr(err) | ||
} | ||
fmt.Println(pre) | ||
} | ||
if p == "tmp" { | ||
if p, err = ioutil.TempDir("", "tnator"); err != nil { | ||
fmt.Printf("Couldn't get tmp dir.") | ||
exitErr(err) | ||
} | ||
fmt.Println(pre) | ||
} | ||
|
||
fmt.Printf("==> Parsing Templates in %q\n", s) | ||
tStack, err := template.ParseDirectory(s, p) | ||
if err != nil { | ||
fmt.Printf("Failed to parse templates.") | ||
exitErr(err) | ||
} | ||
fmt.Printf("==> Parsing Templates in %q\n", s) | ||
tStack, err := template.ParseDirectory(s, p) | ||
if err != nil { | ||
fmt.Printf("Failed to parse templates.") | ||
exitErr(err) | ||
} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(*threads) | ||
for i := 0; i < *threads; i++ { | ||
go func() { | ||
defer wg.Done() | ||
for tStack.Len() > 0 { | ||
if t, ok := tStack.Pop().(*template.Template); ok { | ||
if err := t.Write(); err == nil { | ||
if *del { | ||
os.Remove(t.Src) | ||
} | ||
} else { | ||
fmt.Printf("Error writing template: %v", err) | ||
} | ||
} else { | ||
fmt.Printf("Could not cast stack item as template: %v", t) | ||
} | ||
} | ||
}() | ||
} | ||
var wg sync.WaitGroup | ||
wg.Add(*threads) | ||
for i := 0; i < *threads; i++ { | ||
go func() { | ||
defer wg.Done() | ||
for tStack.Len() > 0 { | ||
if t, ok := tStack.Pop().(*template.Template); ok { | ||
if err := t.Write(); err == nil { | ||
if *del { | ||
os.Remove(t.Src) | ||
} | ||
} else { | ||
fmt.Printf("Error writing template: %v", err) | ||
} | ||
} else { | ||
fmt.Printf("Could not cast stack item as template: %v", t) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
os.Exit(0) | ||
wg.Wait() | ||
os.Exit(0) | ||
} |