mirror of
https://github.com/Luzifer/gen-dockerfile.git
synced 2024-12-20 10:41:18 +00:00
Add parameter to write Dockerfile directly
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
599bb8caf3
commit
88792c4bda
1 changed files with 13 additions and 1 deletions
14
main.go
14
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -23,6 +24,7 @@ var (
|
||||||
Timezone string `flag:"timezone,t" default:"" description:"Set timezone in Dockerfile (format 'Europe/Berlin')"`
|
Timezone string `flag:"timezone,t" default:"" description:"Set timezone in Dockerfile (format 'Europe/Berlin')"`
|
||||||
VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"`
|
VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"`
|
||||||
Volumes []string `flag:"volume,v" default:"" description:"Volumes to create mount points for (format '/data')"`
|
Volumes []string `flag:"volume,v" default:"" description:"Volumes to create mount points for (format '/data')"`
|
||||||
|
Write bool `flag:"write,w" default:"false" description:"Directly write into Dockerfile"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
version = "dev"
|
version = "dev"
|
||||||
|
@ -86,7 +88,17 @@ func main() {
|
||||||
log.WithError(err).Fatalf("Could not render template %q", tplPath)
|
log.WithError(err).Fatalf("Could not render template %q", tplPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(strings.TrimSpace(regexp.MustCompile(`\n{3,}`).ReplaceAllString(buf.String(), "\n\n")))
|
var output io.Writer = os.Stdout
|
||||||
|
if cfg.Write {
|
||||||
|
f, err := os.Create("Dockerfile")
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Fatal("Could not open Dockerfile for writing")
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
output = f
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(output, strings.TrimSpace(regexp.MustCompile(`\n{3,}`).ReplaceAllString(buf.String(), "\n\n")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPackage() (string, error) {
|
func getPackage() (string, error) {
|
||||||
|
|
Loading…
Reference in a new issue