Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Support looping over simple lists #78

Open
niedzielski opened this issue Mar 11, 2023 · 3 comments
Open

[feature request] Support looping over simple lists #78

niedzielski opened this issue Mar 11, 2023 · 3 comments

Comments

@niedzielski
Copy link

Historically, looping has been pretty handy. Simple support is wanted to avoid lengthier JavaScripts:

$ for i in a b c; do echo 1 $i 2; done
1 a 2
1 b 2
1 c 2

The intended use case is simple lists and differs from xargs which is useful for mapping stdin to a command.

References

@dsherret
Copy link
Member

A big criticism of deno task when it was initially made was about how we already have a scripting language (JavaScript) in Deno, but I argued that it's good to be used as a bookmarking system of common commands that are almost 1:1 with what you type on the command line. That way the command you execute on the command line that you want to save for the future and others doesn't need to be rewritten into JavaScript (you just copy and paste the command into your Deno config, then it hopefully works cross platform). I also argued that deno task should mostly just be used for simple orchestration and not anything complex which could be moved into JavaScript (writing large scripts in a json string is a pain anyway)

Due to that, it might be difficult to get this one in. Right now if people need loops the recommened thing to do would be to create a JavaScript file that does this and call it from a deno task via deno run ....

@niedzielski
Copy link
Author

That's fair 👍 FWIW, Deno has a reputation for not needing a bunch of scripts and configs. I think that's a little at odds though with this feature. Right now the ability to write practical Deno one-liners is pretty limited without more robust task support like looping.

I do think this opens a can of worms though for a vein of work the Deno team might not want to focus on. However, between no longer having a deno bundle command and limited NPM script-like support, I find myself having to write a handful of supplemental files in Deno projects that my NPM projects skirt around because they use plain shell for tasks.

deno_task_shell is brilliant(!) and I'm not suggesting I want to use shell in Deno but idiomatic NPM scripts assume shell and that gives a lot of succinct flexibility that Deno tasks doesn't have right now.

@jsejcksn
Copy link

for i in a b c; do echo 1 $i 2; done

@niedzielski For comparison, here's what it looks like to implement your example loop using Deno's eval command without a separate script file — slightly longer, but only just:

// deno.jsonc
{
  "tasks": {
    "loop": "deno eval 'for (const i of \"abc\") console.log(1, i, 2);'"
  }
}
% deno task loop
Task loop deno eval 'for (const i of "abc") console.log(1, i, 2);'
1 a 2
1 b 2
1 c 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants