Skip to content
Permalink
Browse files

improve subpackage support

  • Loading branch information...
bobheadxi committed May 13, 2019
1 parent 7af8a92 commit a6a5c78051b7a15bdd832bc436d965d34b8b19df
Showing with 16 additions and 11 deletions.
  1. +7 −10 generate.go
  2. +3 −1 main.go
  3. +6 −0 twist.yml
@@ -21,26 +21,23 @@ func generate(source string, canon canonical) {
panic(err)
}

parts := strings.Split(canon.Path, "/")
packageName := parts[len(parts)-1]
var (
parts = strings.Split(canon.Path, "/")
packageName = parts[len(parts)-1]
)
for _, p := range append(canon.Subpackages, "") {
var (
path = filepath.Join(packageName, p)
pkgPath = filepath.Join(canon.Path, p)
target = filepath.Join(*outDir, path)
)
target := filepath.Join(*outDir, packageName, p)
os.MkdirAll(target, os.ModePerm)
output := filepath.Join(target, "index.html")
fmt.Printf("generating template in '%s' (for '%s' => '%s')\n", output, source, pkgPath)
fmt.Printf("generating template in '%s' (for '%s' => '%s')\n", output, source, canon.Path)
os.Remove(output)
f, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, os.ModePerm)
if err != nil {
panic(err)
}

if err := t.Execute(f, pkg{
Source: source,
Canonical: pkgPath,
Canonical: canon.Path,
}); err != nil {
panic(err)
}
@@ -29,6 +29,7 @@ func main() {
switch arg := flag.Arg(0); arg {
case "help":
showHelp()
os.Exit(0)
case "config":
if *cfgPath == "" {
*cfgPath = "./twist.yml"
@@ -41,10 +42,11 @@ func main() {
panic(err)
}
fmt.Printf("config generated in '%s'\n", *cfgPath)
os.Exit(0)
default:
println("insufficient arguments provided")
os.Exit(1)
}
os.Exit(1)
}

// otherwise generate
@@ -0,0 +1,6 @@
packages:
github.com/my/package:
path: go.my.domain/package
subpackages:
- subpackage1
- subpackage2

0 comments on commit a6a5c78

Please sign in to comment.
You can’t perform that action at this time.