SamVerschueren/listr

Passing context to sub-listr tasks

cryptiklemur opened this issue · 5 comments

Something like:

new Listr([
	{
		title: 'start',
		task: (ctx) => {
			ctx.baz = 'foobar';
		}
	},
	{
		title: 'Something',
		task: (ctx) => {

			return new Listr([
				{
					title: 'Else',
					task: (ctx) => ctx.foo // Outputs foobar
				}
			], {}, {foo: ctx.baz});
		}
	}
]).run();

You should just be able to reference the outer ctx if you name it differently to avoid collisions.

	{
		title: 'Something',
		task: (outerContext) => {
			return new Listr([
				{
					title: 'Else',
					task: (innerContext) => outerContext.baz
				}
			]);
		}
	}

intrestingly if I separate outerTask and innerTask, then changing the innerTask.title results in the outer task title being changed.

That works perfectly for me though. Do you happen to have a small example showcasing the bug? Would help pinpointing it.

ah, sorry I had mistaken two different problems. The one I mentioned is not actually a thing. I'll open another issue.

Closing this. Let me know if my answer is not enough.