-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Pass scripts arguments #20
Conversation
and install yaargs-parser to parse arguments easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a question to readme file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
While I think that this is a good effort in solving the problem of passing custom arguments to the Cake script, I do have a few concerns about using a general-purpose library to parse the arguments defined in the workflow.
The Cake executable has a well-defined syntax to pass arguments to a script:
dotnet cake --foo=bar --baz
A library like yargs, on the other hand, is very flexible and will try to parse almost anything you throw at it into a list of options. Consider these examples:
const parse = require('yargs-parser');
parse('-foo=bar');
parse('-foo bar');
Both these strings will result in an object that looks like this:
{
_: [],
f: true,
o: [ true, 'bar' ]
}
Which is not what we expected.
Is there a way to configure yargs
so that it follows a well-defined syntax when parsing a string of arguments?
with suggestion from PR
added when(fakeGetInput).calledWith('script-arguments').mockReturnValue(''); to test, because we consule the data always
We can change the behavior of yargs-parser. a canple you cen see here: console.log(parse('-foo=bar')); // { _: [], f: true, o: [ true, 'bar' ] } var conf = {configuration: {'short-option-groups': false}}; Will it be fine? |
Hi. |
I gave this some serious thought and I've arrived to the conclusion that this implementation is not the right way to go. There are a couple of reasons for this:
Until it's possible to parse action inputs as lists, I'd like to offer a syntax that's as close as possible to that ideal. Having said that, I didn't want to close this PR without providing an alternative solution. After a few attempts, I settled on doing what most actions that accept a list argument do: parse it as a multi-line string: with:
arguments: |
name: value
foo: bar I've implemented this in 49c1c65 and it seems to work well. I haven't released a new version yet, but if you want to try out the new steps:
- name: Run the Cake script
uses: cake-build/cake-action@master
with:
arguments: |
name: value
foo: bar Let me know how it works for you. I'd like to thank you again for your contribution. Even if the code itself ultimately didn't make it into the project, it served me as inspiration for finally tackling this problem. 🙏 |
I need to pass scripts args into cake script.
it allow for the feature from issue 10