foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat: directory creation in scripts

Open pegahcarter opened this issue 2 years ago • 4 comments

Component

Other (please describe)

Describe the feature you would like

I found an issue when writing to a file using vm.writeFile() where the script breaks if the file is being written into a directory that does not yet exist. vm.writeFile() is only able to write to existing directories, and I have not seen functionality to create a directory directly from a script. This would be helpful, for example, if I want to write some of the output from script/Deploy.s.sol into my own script/output/{chainName}/Deploy.json file after broadcasting instead of needing to work with the whole Broadcast.json.

Since I'm working with the script on multiple chains, I don't always have the {chainName} directory created, and this feature would be much appreciated.

Additional context

No response

pegahcarter avatar Apr 09 '23 16:04 pegahcarter

Is the feature request here to have vm.writeFile automatically create the directory if it doesn't exist, or to add a vm.mkdir cheat to create directories? Both seem reasonable to me, though just updating writeLine seems sufficient and would be my preference—it keeps the cheat interface smaller/simpler and accomplishes the same goal

mds1 avatar Apr 10 '23 13:04 mds1

The request would be the former - that vm.writeFile would automatically create the directory. vm.mkdir would be a nice to have but in terms of development process vm.writeFile should do all the lifting IMO

pegahcarter avatar Apr 10 '23 16:04 pegahcarter

anybody working on this? would be a killer feature to have.

ArshanKhanifar avatar Nov 29 '23 21:11 ArshanKhanifar

Update: Since #4803 vm.createDir(string,bool) now exists with bool indicating whether the missing directories should be created recursively.

Is this still proposed feature still desired? I think the existing vm.createDir should suffice in most cases.

zerosnacks avatar Feb 09 '24 21:02 zerosnacks

Thanks for the ping @zerosnacks. This issue is now resolved.

pegahcarter avatar Feb 19 '24 18:02 pegahcarter