This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
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.
- Loading branch information
0 parents
commit 4540b57
Showing
27 changed files
with
1,184 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
vendor | ||
main | ||
dist | ||
examples/output.* |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
builds: | ||
- binary: rise | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: go | ||
dist: trusty | ||
go: | ||
- 1.8.4 | ||
- 1.9.1 | ||
os: | ||
- linux | ||
go_import_path: github.com/openpixel/rise | ||
script: | ||
- go test -race -v ./... |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# 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" | ||
|
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Cameron Stitt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
[![Build Status](https://travis-ci.org/OpenPixel/rise.svg?branch=master)](https://travis-ci.org/OpenPixel/rise) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/openpixel/rise)](https://goreportcard.com/report/github.com/openpixel/rise) | ||
|
||
# rise | ||
|
||
Powerful text interpolation. | ||
|
||
## Installation | ||
|
||
### Binaries | ||
|
||
You can find binaries for the latest release on the [releases](https://github.com/OpenPixel/rise/releases) page. | ||
|
||
### Go toolchain | ||
|
||
``` | ||
$ go get -u github.com/openpixel/rise | ||
``` | ||
|
||
## Usage | ||
|
||
You can see the usage documation for the CLI by running `rise --help`. | ||
|
||
``` | ||
$ rise --help | ||
A powerful text interpolation tool. | ||
Usage: | ||
rise [flags] | ||
Flags: | ||
-h, --help help for rise | ||
-i, --input string The file to perform interpolation on | ||
-o, --output string The file to output | ||
--varFile stringSlice The files that contains the variables to be interpolated | ||
``` | ||
|
||
### Input (required) | ||
|
||
The input should be a string that references a file to run the interpolation against. | ||
|
||
### Output (optional) | ||
|
||
The output is the location that the interpolated content should be written to. If not set, it will print to stdout. | ||
|
||
### Variable Files (optional) | ||
|
||
The variable files should be in hcl compatible formats. See https://github.com/hashicorp/hcl for reference. Rise loads the files in the order they are supplied, so the latest reference of a variable will always be used. For example, if we had two files that looked like this | ||
|
||
vars.hcl | ||
``` | ||
variable "i" { | ||
value = 6 | ||
} | ||
``` | ||
|
||
vars2.hcl | ||
``` | ||
variable "i" { | ||
value = 10 | ||
} | ||
``` | ||
|
||
And ran the following command | ||
|
||
``` | ||
$ rise ... --varFile vars.hcl --varFile vars2.hcl | ||
``` | ||
|
||
The value of `i` would be `10`. | ||
|
||
## Basic Example | ||
|
||
Look in the [examples](https://github.com/OpenPixel/rise/tree/master/examples) directory for an example, including inheritance: | ||
|
||
``` | ||
$ rise -i ./examples/input.json -o ./examples/output.json --varFile ./examples/vars.hcl --varFile ./examples/vars2.hcl | ||
``` | ||
|
||
## Interpolation Methods | ||
|
||
- lower | ||
- Convert the provided argument to lowercase | ||
- upper | ||
- Convert the provided argument to uppercase | ||
- env | ||
- Find the provided environment variable | ||
|
||
## Coming Soon | ||
|
||
- More interpolation methods | ||
- join | ||
- split | ||
- replace | ||
- and many more! | ||
- Deeper documentation with examples for interpolation methods | ||
- More configuration CLI arguments | ||
- Support for directories as inputs/outputs | ||
- Support for globs (eg: /tmp/*.json) | ||
- Support for var overrides at cli level (eg: --var "foo=bar") |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/openpixel/rise/runner" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var inputs string | ||
var outputs string | ||
var varFiles []string | ||
|
||
func init() { | ||
RootCmd.PersistentFlags().StringVarP(&inputs, "input", "i", "", "The file to perform interpolation on") | ||
RootCmd.PersistentFlags().StringVarP(&outputs, "output", "o", "", "The file to output") | ||
RootCmd.PersistentFlags().StringSliceVar(&varFiles, "varFile", []string{}, "The files that contains the variables to be interpolated") | ||
} | ||
|
||
// RootCmd is the root command for the entire cli | ||
var RootCmd = &cobra.Command{ | ||
Use: "rise", | ||
Short: "Rise is a powerful text interpolation tool.", | ||
Long: `A powerful text interpolation tool.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if inputs == "" { | ||
log.Fatal("Must have an input") | ||
} | ||
err := runner.Run(&inputs, &outputs, &varFiles) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"i": ${i}, | ||
"j": "${join(", ", h)}", | ||
"other": "${upper("foobar")}" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
${i}: | ||
- ${join(", ", h)} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variable "i" { | ||
value = 6 | ||
} | ||
|
||
variable "j" { | ||
value = 100 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
variable "j" { | ||
value = "${env("J_VAL")}" | ||
} | ||
|
||
variable "k" { | ||
value = { | ||
t = "z" | ||
} | ||
} | ||
|
||
variable "h" { | ||
value = ["Foo", "Bar"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package interpolation | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/hashicorp/hil/ast" | ||
) | ||
|
||
// CoreFunctions are the custom funtions for interpolation | ||
var CoreFunctions = map[string]ast.Function{ | ||
"lower": interpolationFuncLower(), | ||
"upper": interpolationFuncUpper(), | ||
"env": interpolationFuncEnv(), | ||
"join": interpolationFuncJoin(), | ||
"has": interpolationFuncHas(), | ||
"map": interpolationFuncMap(), | ||
"list": interpolationFuncList(), | ||
} | ||
|
||
// interpolationFuncEnv will extract a variable out of the env | ||
func interpolationFuncEnv() ast.Function { | ||
return ast.Function{ | ||
ArgTypes: []ast.Type{ast.TypeString}, | ||
ReturnType: ast.TypeString, | ||
Variadic: false, | ||
Callback: func(inputs []interface{}) (interface{}, error) { | ||
varName := inputs[0].(string) | ||
if varName == "" { | ||
return "", errors.New("Must provide a variable name") | ||
} | ||
return os.Getenv(varName), nil | ||
}, | ||
} | ||
} |
Oops, something went wrong.