gh-cp icon indicating copy to clipboard operation
gh-cp copied to clipboard

Add support for cleaning up after itself in case of a failure

Open swichers opened this issue 1 year ago • 0 comments

If you do something like

gh cp mislav/gh-cp some-missing-file .

The command will error out (expected), but you will also still have a file present with the 404 response from gh:

{"message":"Not Found","documentation_url":"https://docs.github.com/rest/reference/repos#get-repository-content"}

It would be great if this command would check the exit status of the api call and remove the file on its own in that situation. I was hoping to use this command to clean up my own implementation of copying files, but still having to manage these error files reduces its usefulness by quite a bit.

To illustrate:

None gh-cp implementation

gh api "repos/${{ github.repository_owner }}/${{ matrix.repository }}/contents/${F}" \
              -H 'Accept: application/vnd.github.v3.raw' > "${{ runner.temp }}/${F}" \
  || { rm "${{ runner.temp }}/${F}"
}

vs using gh-cp

gh extension install mislav/gh-cp
gh cp "${{ github.repository_owner }}/${{ matrix.repository }}" "${F}" "${{ runner.temp }}" \
  || { rm "${{ runner.temp }}/${F}" }

vs the ideal gh-cp

gh extension install mislav/gh-cp
gh cp "${{ github.repository_owner }}/${{ matrix.repository }}" "${F}" "${{ runner.temp }}"

swichers avatar May 16 '23 23:05 swichers