Passing context to sub-listr tasks
cryptiklemur opened this issue · 5 comments
cryptiklemur commented
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();
SamVerschueren commented
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
}
]);
}
}
KristerV commented
intrestingly if I separate outerTask and innerTask, then changing the innerTask.title
results in the outer task title being changed.
SamVerschueren commented
That works perfectly for me though. Do you happen to have a small example showcasing the bug? Would help pinpointing it.
KristerV commented
ah, sorry I had mistaken two different problems. The one I mentioned is not actually a thing. I'll open another issue.
SamVerschueren commented
Closing this. Let me know if my answer is not enough.