~nilium/secenv

secenv/secenv.1.scd -rw-r--r-- 1.7 KiB
d3fd296dNoel Cower Add usage text, scdoc man page, and README 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
secenv(1)

# Name

secenv - env-exec using SOPs files

# Synopsis

*secenv* [options] [envfiles] -- [cmd arg...]

# Description

secenv is used to run commands with specific environment variables, similar to
env. It loads environment variables as key-value pairs from SOPS-encrypted JSON
or YAML files. Values from the files can be inserted into command lines using
CLI templating (*-T*).

# Options

*-T*
	Template arguments using Go templates. See secenv(1) for template
	information.
*-t*=FMT
	Set the SOPS file format (only json and yaml are currently supported).
	Defaults to inferring from the file's extension.
*-i*
	Drop the current process environment and only set variables found in
	envfiles.
*-n*
	Do not set env vars for values found in the env file. This can be set
	alongside -T to only set values via CLI
argument templating.

## Templating

Templates use Go text/template to expand CLI arguments when the *-T* option is
set. Functions from sprig are available for formatting data.

In addition, there are three additional template functions for turning a single
CLI argument into multiple arguments:

*take* vals...
	Take one or more values and turn them into individual CLI arguments. The
	current CLI argument's final value will be dropped from the command line.
*drop* vals...
	Drop the final value of the current CLI argument from the command line.
	Any value passed to drop is ignored.
*exit* vals...
	Drop the final value of the current CLI argument from the command line
	and stop processing CLI arguments.

For example, to turn every value in the parsed env file(s) into --arg=value
command line arguments, you can use the following:

```
$ secenv -T -n env.json -- \\
	echo '{{ range $k, $v := . }}{{ printf "--%v=%v" $k $v | take }}{{ end }}'
```