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 for multiline commands (sync) #420

Closed
a-y-u-s-h opened this issue Apr 22, 2020 · 2 comments
Closed

Feature Request: Support for multiline commands (sync) #420

a-y-u-s-h opened this issue Apr 22, 2020 · 2 comments

Comments

@a-y-u-s-h
Copy link

Feature Suggestion

Hey. I'm exporting execa.commandSync function and then importing it as shell, so that I can use it as: shell("mkdir something").

It would be awesome to have a function that could work with multiline (and multi-commands) (like a bash script) at once with one command. Not sure if suggested before.

  shell(`
    mkdir ${foo}
    cd ${foo}
    touch ${foo}.txt
  `)
@ehmicky
Copy link
Collaborator

ehmicky commented Apr 22, 2020

I think it would make more sense to use an array of strings:

execa.command([
  `mkdir ${foo}`,
  `cd ${foo}`,
  `touch ${foo}.txt`,
], options)

That being said, I think this is about orchestrating commands and Execa should focus on single command execution and let users build utilities on top of it instead. So I would vote for keeping those features of Execa itself. What do you think @sindresorhus?

@sindresorhus
Copy link
Owner

I think this is outside the scope of Execa.

You have two options here:

1

const commands = [
  `mkdir ${foo}`,
  `cd ${foo}`,
  `touch ${foo}.txt`,
];

for (const command of commands) {
	await execa.command(command);
}

2

execa.command([
  `mkdir ${foo}`,
  `cd ${foo}`,
  `touch ${foo}.txt`,
].join('&&'), {shell: true});

I would strongly recommend 1.

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

No branches or pull requests

3 participants