bard / emacs-run-command

Efficient and ergonomic external command invocation for Emacs
https://bard.github.io/emacs-run-command
GNU General Public License v3.0
102 stars 8 forks source link

How to: use user inputs in commands, add interdependency among same-group tasks #22

Closed sfavazza closed 1 year ago

sfavazza commented 1 year ago

Hello, I was looking for a package which does a similar job to what offered from VSCode tasks.json file and I bumped in this package, which I believe to be the closest out there.

Though I cannot figure out how to:

Cheers, Samuele

bard commented 1 year ago
  • let a task take an optional command from user

I'm not familiar with the tasks.json VSCode extension, could you provide an example?

  • add task dependency, i.e. when running a task, this will first run the one(s) it depends on

Perhaps this helps? https://bard.github.io/emacs-run-command/writing-recipes#hooks Though it's for Lisp functions, not command recipes.

sfavazza commented 1 year ago

I'm not familiar with the tasks.json VSCode extension, could you provide an example?

I shared a link where the concept is illustrated. Though for your convenience, this link.

Perhaps this helps? https://bard.github.io/emacs-run-command/writing-recipes#hooks Though it's for Lisp functions, not command recipes.

I am afraid not, because it runs code after the concerning task.

Ok I will have to implement it myself, thanks for the info, I just did not want to work on something already existing.

bard commented 1 year ago

I'm not familiar with the tasks.json VSCode extension, could you provide an example?

I shared a link where the concept is illustrated. Though for your convenience, this link.

I saw the link, but I cannot go through the text, which is fairly long, to figure out what is meant by "let a task take an optional command from user" — there's no concept of "task" in this package, only of "command", which could take optional input. If you can provide a short example, I might be able to advise.

Perhaps this helps? https://bard.github.io/emacs-run-command/writing-recipes#hooks Though it's for Lisp functions, not command recipes.

I am afraid not, because it runs code after the concerning task.

Ok I will have to implement it myself, thanks for the info, I just did not want to work on something already existing.

Ok, I see.

If the intention is to run two commands, one starting after the other ends, I wonder whether a simple sh -c "cmd1 && cmd2" could suffice.

Please note (just to set expectations) that full-blown dependency management is unlikely to become part of the scope of this package.

sfavazza commented 1 year ago

I saw the link, but I cannot go through the text, which is fairly long, to figure out what is meant by "let a task take an optional command from user" — there's no concept of "task" in this package, only of "command", which could take optional input. If you can provide a short example, I might be able to advise.

Apologies, I guess it is a matter of wording, what is called a "task" is a "command" in this package. In the link above the "commands" are described in a JSON file according to well determined specifications.

In addition to this concept I was considering the possibility to customize a command taking inputs from user, but I cannot see a way here. Though I perfectly understand the simplistic approach, which I like! Though I have more specific needs for the projects I work on daily.

If the intention is to run two commands, one starting after the other ends, I wonder whether a simple sh -c "cmd1 && cmd2" could suffice.

True, but what if one wants to keep them separated, such that there is the freedom to select which one to run and if a task depends on another the dependencies are executed first.

Please note (just to set expectations) that full-blown dependency management is unlikely to become part of the scope of this package.

I love the simplistic approach here, this statement does not come with great surprise 😁. I am seriously considering to create my own package with run-command as dependency.

To be honest I have other feature extension proposal for this package (which I would contribute to). For organization purposes, should I open a new issue or here is still OK? (maybe adapting the title)

bard commented 1 year ago

In addition to this concept I was considering the possibility to customize a command taking inputs from user, but I cannot see a way here. Though I perfectly understand the simplistic approach, which I like! Though I have more specific needs for the projects I work on daily.

The :command-line entry in a recipe can be a function, and the function can build the command line string in any way it sees fit, including requesting input from the user. See https://github.com/bard/emacs-run-command/blob/master/cookbook/run-command-recipe-watchexec.el for an example. Does that help?

To be honest I have other feature extension proposal for this package (which I would contribute to). For organization purposes, should I open a new issue or here is still OK? (maybe adapting the title)

I'd say open a new issue, in case other people want to "+1" the idea.

sfavazza commented 1 year ago

The :command-line entry in a recipe can be a function, and the function can build the command line string in any way it sees fit, including requesting input from the user. See https://github.com/bard/emacs-run-command/blob/master/cookbook/run-command-recipe-watchexec.el for an example. Does that help?

Yes indeed, it is a good starting point. Sorry I didn't go through the whole cookbook.

I'd say open a new issue, in case other people want to "+1" the idea.

Sure thing, I just have to find the time 😊

Thank you for your prompt support!

bard commented 1 year ago

The :command-line entry in a recipe can be a function, and the function can build the command line string in any way it sees fit, including requesting input from the user. See https://github.com/bard/emacs-run-command/blob/master/cookbook/run-command-recipe-watchexec.el for an example. Does that help?

Yes indeed, it is a good starting point. Sorry I didn't go through the whole cookbook.

My fault — it should have been part of the Writing Recipes guide. I'll fix that soon.

bard commented 1 year ago

The :command-line entry in a recipe can be a function, and the function can build the command line string in any way it sees fit, including requesting input from the user. See https://github.com/bard/emacs-run-command/blob/master/cookbook/run-command-recipe-watchexec.el for an example. Does that help?

Yes indeed, it is a good starting point. Sorry I didn't go through the whole cookbook.

My fault — it should have been part of the Writing Recipes guide. I'll fix that soon.

And done: https://bard.github.io/emacs-run-command/writing-recipes#requesting-user-input-before-executing-command

Thanks for bringing this up.

sfavazza commented 1 year ago

Thank you, now it's way easier to search this info. I can definitely work with it!