run icon indicating copy to clipboard operation
run copied to clipboard

[Feature request] do you plan to support prerequisites-like?

Open CircleCode opened this issue 6 years ago • 2 comments

I like run approach to scripts management. I find it clever, and I think it can be much more understandable in a lot of situations. However, what I would miss is something similar to prerequisities. Since run does not "produce files", but instead "runs scripts", I would assume this would be a list of commands to be run before the choosen one.

For example:

hello-world: get-name
    echo "Hello, ${NAME}"

get-name:
    read _NAME
    export NAME=${_NAME}

Of course, this example makes no sense, but shows the idea.

CircleCode avatar Dec 27 '19 11:12 CircleCode

Greetings @CircleCode !

do you plan to support prerequisites

Indeed I do! There are a lot of nuances to consider. Just off the top of my head:

  • Passing arguments to the other commands
  • Passing variables to the other commands
  • Orchestrating multiple commands
  • Deciding when/if to pass STDIN and when/if to capture STDOUT (i.e. Piping)
  • Invoking general shell commands as well as run commands

Figuring out what features are desirable / feasible and what the syntax might look like is going to take some thinking.

But yes I do plan to support the idea and now we have a place for discussion on it so thanks for opening the issue !

-TW

NOTE: Regarding your example: A sub-shell's environment variables are not available to the parent, so trying to support a use case where a command script can set variables that can be available to other commands is going to be tricky. We will likely need a convention where the script generates "nam=value" pairs as STDOUT and Run captures the output and parses the variables.

TekWizely avatar Dec 27 '19 19:12 TekWizely

@CircleCode I just wanted to let you know that I recently added a feature that brings some support for calling other commands from within your command script. See here:

Using your example, this would look like:

Runfile

EXPORT RUN := ${.RUN}
EXPORT RF  := ${.RUNFILE}

hello-world:
    eval $( ${RUN} -r ${RF} get-name )
    echo "Hello, ${NAME}"

get-name:
    read _NAME
    echo export NAME=${_NAME}

usage

$ echo Newman | run hello-world

Hello, Newman

I'm actually using a similar technique in a project so that multiple scripts can haves access to a bunch of config variables.

Hope that helps!

-TW

TekWizely avatar Jan 22 '20 21:01 TekWizely

@CircleCode You may be interested in my recent PR ( #63 ) which introduces the ability to easily invoke other commands before or after your command executes.

I'm still grinding on ways to consume variables from other commands.

TekWizely avatar Nov 27 '22 17:11 TekWizely

Going to close this as some form of command dependency has been introduced - thank you for your interested in my project !

TekWizely avatar Jan 18 '23 06:01 TekWizely