Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrich committed Aug 9, 2019
1 parent b14500a commit b55dc71
Show file tree
Hide file tree
Showing 112 changed files with 19,031 additions and 1 deletion.
78 changes: 78 additions & 0 deletions Gopkg.lock

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

38 changes: 38 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/Masterminds/sprig"
version = "2.19.0"

[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.2"

[prune]
go-tests = true
unused-packages = true
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2019 IBM
Copyright 2019 Brian Richardson <brianthemathguy@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BINARIES = scribe
GOBIN=$(or ${GOPATH},~/go)/bin
CMD_PACKAGE_PATH = $(PWD)/cmd

all: $(BINARIES)

$(BINARIES): setup
@mkdir -p bin
go build -o bin/$@ $(CMD_PACKAGE_PATH)/$@
cp bin/$@ $(GOBIN)/$@

setup:
if [ ! -d $(GOBIN) ] ; then mkdir $(GOBIN); fi

clean:
rm -rf bin/
Binary file added bin/scribe
Binary file not shown.
61 changes: 61 additions & 0 deletions cmd/scribe/scribe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright © 2019 IBM
Copyright © 2019 Brian Richardson <brianthemathguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"flag"
"fmt"
"os"

"github.com/bdrich/scribe/pkg/fileSystem"
"github.com/bdrich/scribe/pkg/templates"
)

func main() {

pwd, _ := os.Getwd()
const usage = "USAGE:\tscribe \n\t\t-in <input_path>\n\t\t-out <output_path>\n\t\t-templates <dir_path>\n"

// flags
inputFileName := flag.String("in", "", "Input Values File -- input file which populates templates")
outputPathName := flag.String("out", "", "Output Path -- path with populated templates")
templatesPath := flag.String("templates", "", "Template File(s) -- path to recursively populate")
flag.Parse()

if *outputPathName == "" || *inputFileName == "" || *templatesPath == "" {
fmt.Println("Error: Input Values File, Output, Templates paths cannot be empty.")
fmt.Printf("----------------------------------------\n%s\n", usage)
os.Exit(1)
}

outputPath := pwd + "/" + *outputPathName
inputPath := pwd + "/" + *inputFileName
fmt.Printf("Input Values File: %s\n", inputPath)

// Ensure input file exists
if !fileSystem.PathExists(inputPath) {
fmt.Printf("Error: Input Values File '%s' does not exist.\n", inputPath)
return
}

// If env directory doesn't exist, create it
if !fileSystem.PathExists(outputPath) {
fileSystem.CreateDir(outputPath)
}

templates.WalkExecuteTemplates(*templatesPath, inputPath, outputPath)
}
54 changes: 54 additions & 0 deletions pkg/fileSystem/fileSystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright © 2019 IBM
Copyright © 2019 Brian Richardson <brianthemathguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fileSystem

import (
"os"
)

// PathExists returns true if given path exists, false otherwise
func PathExists(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}

// CreateDir creates a directory at given path, permission mode option
func CreateDir(path string, _mode ...int) error {
var mode = 0777
if len(_mode) > 0 {
mode = _mode[0]
}
fileMode := os.FileMode(uint32(mode))
err := os.MkdirAll(path, fileMode)
return err
}

// CreateFile creates a file at given path
func CreateFile(path string) (*os.File, error) {
file, err := os.Create(path)
return file, err
}

// DeleteFile deletes a file at given path
func DeleteFile(path string) error {
err := os.Remove(path)
return err
}
Loading

0 comments on commit b55dc71

Please sign in to comment.