Skip to content

Commit 3d4d229

Browse files
author
Alexander Weber
committed
env var injector
1 parent 746001d commit 3d4d229

3 files changed

Lines changed: 66 additions & 48 deletions

File tree

.complate/config.yaml

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
version: 0.10
22
templates:
3-
one:
4-
content:
5-
file: ./.complate/templates/arbitraty-template-file.tpl
6-
values:
7-
a.summary:
8-
static: "random summary"
9-
two:
10-
content:
11-
inline: |-
12-
{{ a.alpha }}
13-
{{ b.bravo }}
14-
{{ c.charlie }}
15-
{{ d.delta }}
16-
{{ e.echo }}
17-
values:
18-
a.alpha:
19-
prompt: "alpha"
20-
b.bravo:
21-
shell: "printf bravo"
22-
c.charlie:
23-
static: "charlie"
24-
d.delta:
25-
select:
26-
text: Select the version level that shall be incremented
27-
options:
28-
alpha:
29-
display: alpha
30-
value:
31-
static: alpha
32-
bravo:
33-
display: bravo
34-
value:
35-
shell: printf bravo
36-
e.echo:
37-
check:
38-
text: Select the components that are affected
39-
separator: ", "
40-
options:
41-
alpha:
42-
display: alpha
43-
value:
44-
static: alpha
45-
bravo:
46-
display: bravo
47-
value:
48-
shell: printf bravo
3+
zero:
4+
content:
5+
inline: |-
6+
{{ a.alpha }}
7+
values:
8+
a.alpha:
9+
env: ALPHA
10+
one:
11+
content:
12+
file: ./.complate/templates/arbitraty-template-file.tpl
13+
values:
14+
a.summary:
15+
static: "random summary"
16+
two:
17+
content:
18+
inline: |-
19+
{{ a.alpha }}
20+
{{ b.bravo }}
21+
{{ c.charlie }}
22+
{{ d.delta }}
23+
{{ e.echo }}
24+
values:
25+
a.alpha:
26+
prompt: "alpha"
27+
b.bravo:
28+
shell: "printf bravo"
29+
c.charlie:
30+
static: "charlie"
31+
d.delta:
32+
select:
33+
text: Select the version level that shall be incremented
34+
options:
35+
alpha:
36+
display: alpha
37+
value:
38+
static: alpha
39+
bravo:
40+
display: bravo
41+
value:
42+
shell: printf bravo
43+
e.echo:
44+
check:
45+
text: Select the components that are affected
46+
separator: ", "
47+
options:
48+
alpha:
49+
display: alpha
50+
value:
51+
static: alpha
52+
bravo:
53+
display: bravo
54+
value:
55+
shell: printf bravo

src/config/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct Option {
3737
#[derive(Debug, serde::Serialize, serde::Deserialize)]
3838
#[serde(rename_all = "snake_case")]
3939
pub enum VariableDefinition {
40+
Env(String),
4041
Static(String),
4142
Prompt(String),
4243
Shell(String),
@@ -72,12 +73,19 @@ impl Template {
7273
pub async fn default_config() -> String {
7374
r###"version: 0.10
7475
templates:
76+
zero:
77+
content:
78+
inline: |-
79+
{{ a.alpha }}
80+
values:
81+
a.alpha:
82+
env: ALPHA
7583
one:
7684
content:
7785
file: ./.complate/templates/arbitraty-template-file.tpl
7886
values:
7987
a.summary:
80-
static: "random summary"
88+
env: "random summary"
8189
two:
8290
content:
8391
inline: |-
@@ -118,7 +126,8 @@ templates:
118126
display: bravo
119127
value:
120128
shell: printf bravo
121-
129+
f.foxtrot:
130+
env: "FOXTROT"
122131
"###
123132
.to_owned()
124133
}

src/render/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::args::{Backend, ShellTrust};
22
use crate::config::{Config, Content, Option, OptionValue, Template, VariableDefinition};
33
use async_trait::async_trait;
44
use std::collections::BTreeMap;
5+
use std::env;
56
use std::result::Result;
67

78
#[cfg(feature = "backend+cli")]
@@ -175,6 +176,7 @@ impl Resolve for VariableDefinition {
175176
let backend_impl = backend.to_input(shell_trust)?;
176177

177178
match self {
179+
VariableDefinition::Env(v) => Ok(env::var(v)?),
178180
VariableDefinition::Static(v) => Ok(v.to_owned()),
179181
VariableDefinition::Prompt(v) => backend_impl.prompt(v).await,
180182
VariableDefinition::Shell(cmd) => backend_impl.shell(cmd, shell_trust).await,

0 commit comments

Comments
 (0)