jakubriegel / kotlin-shell

Tool for performing shell-like programing in Kotlin
Apache License 2.0
143 stars 8 forks source link

Interpolation of Kotlin variables not working? #26

Closed helpermethod closed 2 years ago

helpermethod commented 2 years ago

Hi!

First of all, great project, exactly what I was looking for!

I'm currently writing a script which delegates to git to create a commit / branch and corresponding merge request. This seems to work fine, except for the commit itself

shell {
    "git checkout -b silencer/exclude-${packageName.replace(':', '_')}"()
    "git add renovate.json"()
    "git -c user.name=silencer -c user.email= commit -m 'chore(dependency-updates): Exclude $packageName from $groupName'"()
    "git push -o merge_request.create"()
}

Somehow the interpolation in the commit message is not working, the string 'chore(dependency-updates): Exclude $packageName from $groupName' is split into multiple words it seems. Is this a bug or an error on my side?

Thanks in advance!

helpermethod commented 2 years ago

Okay, it seems the interpolation is not the problem. This call also seems to be problematic:

"git commit -m 'chore(dependency-updates): Exclude packageName from groupName'"()

For some reason is split into multiple tokens

 -m 'chore(dependency-updates):
 Exclude
 packageName
 from
 groupName'

So the single quotes in 'chore(dependency-updates): Exclude packageName from groupName' seem to be the problem.

helpermethod commented 2 years ago

Answering my own question: You need to use systemProcess

 systemProcess {
    cmd { "git" withArgs listOf("commit", "-m", "chore(dependency-updates): Exclude $groupName from $packageName") }
 }()
jakubriegel commented 2 years ago

Thanks for engagement!