Writing #159 I thought that it could be good to have a way to use the stdout of a command executed with Exec as parameter of a following Exec call.
For being even more useful, it could be possible to support several Exec calls.
And to even go further (sorry, I'm blowing my mind), they could also be used as values to replace on a specific format string.
NOTE I'm not familiar with the script implementation, so I don't know if this is feasible, or if it's hard to implement or not.
Let me write some example of an hypothetical API for each of the above wacky ideas.
Right now, script allows to do this
script.Exec("echo hello world").Exec("cut -d ' ' -f 1").Output()
This translate to the shell script
echo hello world | cut -d ' ' -f 1
I'm exposing an example with shell script that I think that I cannot translate using script to a pipe execution as before; each numbered item relates, in the same order, to the three things that I exposed at the beginning of this issue.
For keeping the examples concise, they are ilustrative examples rather than a specific use case that I'm having.
-
-
ls $(lsb_release -cs) $(dpkg --print-architecture)
-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
In script isn't currently possible without having to execute each of them speartelly. I'm going to show how script could offer it with some unexisting methods without stating if their names are good nor if it's a good idea to have them.
- There should be somehow to indicates that the output of the previous
Exec is passed as an argument on the following Exec call.
script.Exec("lsb_release -cs").AsArg().Exec("ls").Output()
- There should be somehow as 1 but with the possibility to pipe several
Exec calls.
script.Exec("lsb_release -cs").AsArg().Exec("dpkg --print-architecture").AsArg().Exec("ls").Output()
- There should be somehow to indicates that the outputs are kept as an internal value that can be referenced in the formatter.
script.Exec("lsb_release -cs").AsFmt().Exec("dpk --print-architecture").AsFmt().Exec(`echo "deb [arch=@{1} signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian @{2} stable"`).Output()
In this case I used echo inside of an Exec, but it could be extended to each source functions that receive a string as a parameter, hence it could be also done as
script.Exec("lsb_release -cs").AsFmt().Exec("dpk --print-architecture").AsFmt().Echo("deb [arch=@{1} signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian @{2} stable").Output()
Writing #159 I thought that it could be good to have a way to use the stdout of a command executed with
Execas parameter of a followingExeccall.For being even more useful, it could be possible to support several
Execcalls.And to even go further (sorry, I'm blowing my mind), they could also be used as values to replace on a specific format string.
NOTE I'm not familiar with the
scriptimplementation, so I don't know if this is feasible, or if it's hard to implement or not.Let me write some example of an hypothetical API for each of the above wacky ideas.
Right now,
scriptallows to do thisThis translate to the shell script
I'm exposing an example with shell script that I think that I cannot translate using
scriptto a pipe execution as before; each numbered item relates, in the same order, to the three things that I exposed at the beginning of this issue.For keeping the examples concise, they are ilustrative examples rather than a specific use case that I'm having.
ls $(lsb_release -cs)In
scriptisn't currently possible without having to execute each of them speartelly. I'm going to show howscriptcould offer it with some unexisting methods without stating if their names are good nor if it's a good idea to have them.Execis passed as an argument on the followingExeccall.Execcalls.In this case I used
echoinside of anExec, but it could be extended to each source functions that receive a string as a parameter, hence it could be also done as