Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/ejson2env/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func main() {
Name: "quiet, q",
Usage: "Suppress export statement",
},
cli.BoolFlag{
Name: "raw, r",
Usage: "Skip shell-escaping values",
},
}

app.Action = func(c *cli.Context) {
Expand All @@ -46,12 +50,16 @@ func main() {

keydir := c.String("keydir")
quiet := c.Bool("quiet")
raw := c.Bool("raw")

// select the ExportFunction to use
exportFunc := ejson2env.ExportEnv
if quiet {
exportFunc = ejson2env.ExportQuiet
}
if raw {
exportFunc = ejson2env.ExportRaw
}

if c.Bool("key-from-stdin") {
var err error
Expand Down
8 changes: 8 additions & 0 deletions exportfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ func ExportQuiet(w io.Writer, values map[string]string) {
fmt.Fprintf(w, "%s=%s\n", key, shell.Escape(value))
}
}

// ExportRaw writes the passed environment values to the passed
// io.Writer in %s=%s format without shell escaping.
func ExportRaw(w io.Writer, values map[string]string) {
for key, value := range values {
fmt.Fprintf(w, "%s=%s\n", key, value)
}
}
5 changes: 5 additions & 0 deletions secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func TestReadAndExportEnv(t *testing.T) {
exportFunc: ExportQuiet,
expectedOutput: "test_key='test value'\n",
},
{
name: "ExportRaw",
exportFunc: ExportRaw,
expectedOutput: "test_key=test value\n",
},
}

for _, test := range tests {
Expand Down