Skip to content

Commit 60784b4

Browse files
feat(config): allow inline include
resolves #191
1 parent 038022b commit 60784b4

File tree

4 files changed

+94
-28
lines changed

4 files changed

+94
-28
lines changed

src/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ func TestLoadConfig(t *testing.T) {
5454
config: "aliae.invalid.yaml",
5555
expectError: true,
5656
},
57+
{
58+
name: "Valid with generic",
59+
config: "aliae.valid_generic.yaml",
60+
expected: &Aliae{
61+
Aliae: shell.Aliae{
62+
{Name: "test", Value: shell.Template("test")},
63+
{Name: "test2", Value: shell.Template("test2")},
64+
{Name: "test3", Value: shell.Template("test3")},
65+
},
66+
},
67+
},
5768
}
5869

5970
for _, tc := range tests {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
alias:
2+
- !include_dir ./aliases
3+
- name: test3
4+
value: test3

src/config/unmarshal.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,17 @@ func includeUnmarshaler(b []byte) ([]byte, error) {
8686

8787
indented := bytes.Join(splitted, newline)
8888

89-
result := append(parts[0][0:], newline...) //nolint:gocritic
89+
result := parts[0][0:]
90+
91+
switch string(result) {
92+
case "-":
93+
// check if we're in the list instead of the key
94+
// if so, drop the dash and start with a newline
95+
result = newline
96+
default:
97+
result = append(result, newline...)
98+
}
99+
90100
result = append(result, indented...)
91101

92102
s[i] = result

website/docs/setup/include.mdx

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,68 @@
1-
---
2-
id: include
3-
title: Include
4-
sidebar_label: ➕ Include files
5-
---
6-
7-
## Example
8-
9-
```yaml title=".aliae.yaml"
10-
aliae: !include "{{ .Home }}/.aliae/aliases.yaml"
11-
env: !include_dir "{{ .Home }}/.aliae/envs"
12-
```
13-
14-
```yaml title="$HOME/.aliae/aliases.yaml"
15-
- name: g
16-
value: git
17-
- name: k
18-
value: kubectl
19-
```
20-
21-
## Description
22-
23-
The `!include` and `!include_dir` yaml tags allow you to include a single file or a directory of .yaml files respectively.
24-
This allows for clean organization of aliae, envs, and all other things handled by Aliae.
25-
File/Directory paths support [templating][templates]
26-
27-
[templates]: templates.mdx
1+
---
2+
id: include
3+
title: Include
4+
sidebar_label: ➕ Include files
5+
---
6+
7+
## Example
8+
9+
```yaml title=".aliae.yaml"
10+
aliae: !include "{{ .Home }}/.aliae/aliases.yaml"
11+
env: !include_dir "{{ .Home }}/.aliae/envs"
12+
```
13+
14+
```yaml title="$HOME/.aliae/aliases.yaml"
15+
- name: g
16+
value: git
17+
- name: k
18+
value: kubectl
19+
```
20+
21+
## Description
22+
23+
The `!include` and `!include_dir` yaml tags allow you to include a single file or a directory of .yaml files respectively.
24+
This allows for clean organization of aliae, envs, and all other things handled by Aliae.
25+
File/Directory paths support [templating][templates].
26+
27+
## Inline Include
28+
29+
If you want to have a more fine grained control over the included file, you can use the `!include` tag inline in combination
30+
with other defined aliases.
31+
32+
```yaml title=".aliae.yaml"
33+
aliae:
34+
- !include "{{ .Home }}/.aliae/kubernetes.yaml"
35+
- name: g
36+
value: git
37+
```
38+
39+
```yaml title="$HOME/.aliae/kubernetes.yaml"
40+
- name: k
41+
value: kubectl
42+
- name: kg
43+
value: kubectl get
44+
- name: kgpo
45+
value: kubectl get pod
46+
- name: ksysgpo
47+
value: kubectl --namespace=kube-system get pod
48+
- name: krm
49+
value: kubectl delete
50+
- name: krmf
51+
value: kubectl delete -f
52+
- name: krming
53+
value: kubectl delete ingress
54+
- name: krmingl
55+
value: kubectl delete ingress -l
56+
- name: krmingall
57+
value: kubectl delete ingress --all-namespaces
58+
- name: kgsvcoyaml
59+
value: kubectl get service -o=yaml
60+
- name: kgsvcwn
61+
value: kubectl get service --watch --namespace
62+
- name: kgsvcslwn
63+
value: kubectl get service --show-labels --watch --namespace
64+
- name: kgwf
65+
value: kubectl get --watch -f
66+
```
67+
68+
[templates]: templates.mdx

0 commit comments

Comments
 (0)