Skip to content

Commit 3f67107

Browse files
committed
Allow environment variables to have a value.
1 parent d5c8413 commit 3f67107

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
major_changes:
22
- "Extend plugin reference ``P(...)`` to allow referencing a role's entrypoint (https://github.com/ansible-community/antsibull-docs-ts/pull/442)."
3+
- "Extend environment variable ``E(...)`` to allow specifying a value (https://github.com/ansible-community/antsibull-docs-ts/pull/442)."

src/dom.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface OptionValuePart extends Part {
9494
export interface EnvVariablePart extends Part {
9595
type: PartType.ENV_VARIABLE;
9696
name: string;
97+
value: string | undefined;
9798
}
9899

99100
export interface ReturnValuePart extends Part {

src/parser.spec.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ describe('parser', (): void => {
126126
]);
127127
});
128128
it('semantic markup test', (): void => {
129-
expect(parse('foo E(a\\),b) P(foo.bar.baz#bam) baz V( b\\,\\na\\)\\\\m\\, ) O(foo) ')).toEqual([
129+
expect(parse('foo E(a\\),b) E(foo=bar=baz) P(foo.bar.baz#bam) baz V( b\\,\\na\\)\\\\m\\, ) O(foo) ')).toEqual([
130130
[
131131
{ type: PartType.TEXT, text: 'foo ', source: undefined },
132-
{ type: PartType.ENV_VARIABLE, name: 'a),b', source: undefined },
132+
{ type: PartType.ENV_VARIABLE, name: 'a),b', value: undefined, source: undefined },
133+
{ type: PartType.TEXT, text: ' ', source: undefined },
134+
{ type: PartType.ENV_VARIABLE, name: 'foo', value: 'bar=baz', source: undefined },
133135
{ type: PartType.TEXT, text: ' ', source: undefined },
134136
{
135137
type: PartType.PLUGIN,
@@ -171,34 +173,38 @@ describe('parser', (): void => {
171173
]);
172174
});
173175
it('semantic markup test (with source)', (): void => {
174-
expect(parse('foo E(a\\),b) P(foo.bar.baz#bam) baz V( b\\,\\na\\)\\\\m\\, ) O(foo) ', { addSource: true })).toEqual(
175-
[
176-
[
177-
{ type: PartType.TEXT, text: 'foo ', source: 'foo ' },
178-
{ type: PartType.ENV_VARIABLE, name: 'a),b', source: 'E(a\\),b)' },
179-
{ type: PartType.TEXT, text: ' ', source: ' ' },
180-
{
181-
type: PartType.PLUGIN,
182-
plugin: { fqcn: 'foo.bar.baz', type: 'bam' },
183-
entrypoint: undefined,
184-
source: 'P(foo.bar.baz#bam)',
185-
},
186-
{ type: PartType.TEXT, text: ' baz ', source: ' baz ' },
187-
{ type: PartType.OPTION_VALUE, value: ' b,na)\\m, ', source: 'V( b\\,\\na\\)\\\\m\\, )' },
188-
{ type: PartType.TEXT, text: ' ', source: ' ' },
189-
{
190-
type: PartType.OPTION_NAME,
191-
plugin: undefined,
192-
entrypoint: undefined,
193-
link: ['foo'],
194-
name: 'foo',
195-
value: undefined,
196-
source: 'O(foo)',
197-
},
198-
{ type: PartType.TEXT, text: ' ', source: ' ' },
199-
],
176+
expect(
177+
parse('foo E(a\\),b) E(foo=bar=baz) P(foo.bar.baz#bam) baz V( b\\,\\na\\)\\\\m\\, ) O(foo) ', {
178+
addSource: true,
179+
}),
180+
).toEqual([
181+
[
182+
{ type: PartType.TEXT, text: 'foo ', source: 'foo ' },
183+
{ type: PartType.ENV_VARIABLE, name: 'a),b', value: undefined, source: 'E(a\\),b)' },
184+
{ type: PartType.TEXT, text: ' ', source: ' ' },
185+
{ type: PartType.ENV_VARIABLE, name: 'foo', value: 'bar=baz', source: 'E(foo=bar=baz)' },
186+
{ type: PartType.TEXT, text: ' ', source: ' ' },
187+
{
188+
type: PartType.PLUGIN,
189+
plugin: { fqcn: 'foo.bar.baz', type: 'bam' },
190+
entrypoint: undefined,
191+
source: 'P(foo.bar.baz#bam)',
192+
},
193+
{ type: PartType.TEXT, text: ' baz ', source: ' baz ' },
194+
{ type: PartType.OPTION_VALUE, value: ' b,na)\\m, ', source: 'V( b\\,\\na\\)\\\\m\\, )' },
195+
{ type: PartType.TEXT, text: ' ', source: ' ' },
196+
{
197+
type: PartType.OPTION_NAME,
198+
plugin: undefined,
199+
entrypoint: undefined,
200+
link: ['foo'],
201+
name: 'foo',
202+
value: undefined,
203+
source: 'O(foo)',
204+
},
205+
{ type: PartType.TEXT, text: ' ', source: ' ' },
200206
],
201-
);
207+
]);
202208
expect(parse('P(foo.bar.baz#role) P(foo.bar.baz#role:entrypoint)')).toEqual([
203209
[
204210
{

src/parser.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,14 @@ const PARSER: CommandParserEx[] = [
290290
parameters: 1,
291291
escapedArguments: true,
292292
process: (args, _, source, whitespace) => {
293-
const env = processWhitespace(args[0] as string, whitespace, true, true);
294-
return <EnvVariablePart>{ type: PartType.ENV_VARIABLE, name: env, source: source };
293+
let env = processWhitespace(args[0] as string, whitespace, true, true);
294+
let value: string | undefined;
295+
const eq = env.indexOf('=');
296+
if (eq >= 0) {
297+
value = env.substring(eq + 1, env.length);
298+
env = env.substring(0, eq);
299+
}
300+
return <EnvVariablePart>{ type: PartType.ENV_VARIABLE, name: env, value: value, source: source };
295301
},
296302
},
297303
{

0 commit comments

Comments
 (0)