Skip to content

Commit

Permalink
Rewrite structure. Fixes #4 and #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
yawn committed Feb 4, 2016
1 parent 1458b8d commit bf0b9b4
Show file tree
Hide file tree
Showing 55 changed files with 5,521 additions and 412 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE=db.example.com
NULL=
MODE=debug
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.4
- 1.5
- tip
sudo: false
install:
Expand Down
28 changes: 28 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Godeps/Readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ release:
github-release upload --user $(USER) --repo $(REPO) --tag $(VERSION) -s $(TOKEN) --name ep-linux --file out/linux/ep

test:
DATABASE=db.example.com NULL= MODE=debug go test -cover
go test -cover
50 changes: 0 additions & 50 deletions bin/envplate.go

This file was deleted.

90 changes: 90 additions & 0 deletions bin/ep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"fmt"
"log"
"os"
"syscall"

"github.com/kreuzwerker/envplate"
"github.com/spf13/cobra"
"github.com/yawn/doubledash"
)

var (
build string
version string
)

func main() {

var ( // flags
backup *bool
dryRun *bool
strict *bool
verbose *bool
)

os.Args = doubledash.Args

// commands
root := &cobra.Command{
Use: "ep",
Short: "envplate provides trivial templating for configuration files using environment keys",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
envplate.Logger.Verbose = *verbose
},
}

parse := &cobra.Command{
Use: "parse",
Short: "Parse globs and exec after doubledash",
Run: func(cmd *cobra.Command, args []string) {

var h = envplate.Handler{
Backup: *backup,
DryRun: *dryRun,
Strict: *strict,
}

if err := h.Apply(args); err != nil {
os.Exit(1)
}

if h.DryRun {
os.Exit(0)
}

if len(doubledash.Xtra) > 0 {

if err := syscall.Exec(doubledash.Xtra[0], doubledash.Xtra, os.Environ()); err != nil {
log.Fatalf("Cannot exec '%v': %v", doubledash.Xtra, err)
}

}

},
}

version := &cobra.Command{
Use: "version",
Short: "Print the version information of ep",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Envplate %s (%s)\n", version, build)
},
}

root.AddCommand(parse)
root.AddCommand(version)

// flag parsing
backup = parse.Flags().BoolP("backup", "b", false, "Create a backup file when using inline mode")
dryRun = parse.Flags().BoolP("dry-run", "d", false, "Dry-run - output templates to stdout instead of inline replacement")
strict = parse.Flags().BoolP("strict", "s", false, "Strict-mode - fail when falling back on defaults")
verbose = parse.Flags().BoolP("verbose", "v", false, "Verbose logging")

if err := root.Execute(); err != nil {
log.Fatalf("Failed to start the application: %v", err)
}

}
5 changes: 0 additions & 5 deletions conf.go

This file was deleted.

Loading

0 comments on commit bf0b9b4

Please sign in to comment.