jfrog / jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
Apache License 2.0
530 stars 227 forks source link

jfrog rt download to stdout #1028

Open felipecrs opened 3 years ago

felipecrs commented 3 years ago

Problem

When I have to download a metadata file, such as JSON or XML with JFrog, I have to manipulate files because the jfrog rt download can't download to stdout.

Solution

jfrog rt download 'repo/project/latest/project-*.json' -

Notice the - used as target output. This often means stdout in other CLIs, would be good if it could be supported here as well. Example of another program which supports it:

wget https://file.json -O -

Important: any other text, such as progress, results summary, etc, must be redirected to the stderr instead of stdout to assure the stdout will only contain the contents of the file (as is with wget).

Alternatives

I have to do something like:

jfrog rt download --flat=true 'repo/project/latest/project-*.json' /tmp/file.json
cat /tmp/file.json | jq -er .version
rm -f /tmp/file.json

Instead of:

jfrog rt download --flat=true 'repo/project/latest/project-*.json' - | jq -er .version
eyalbe4 commented 3 years ago

Thanks for sharing this requirement @felipecrs. I think that the rt-fs jfrog-cli plugin can do what you're looking for. It includes a cat command which prints the content of file to the stdout. Please let us know if this helps.

felipecrs commented 3 years ago

Thank you so much for the suggestion. It indeed does what I propose, except that for my very own use case it does not:

❯ jfrog rt-fs cat 'repo/project/latest/project-*.json'
[Error] Wildcards are not supported in paths.
exit status 1
eyalbe4 commented 3 years ago

@felipecrs, I'm not sure if curl supports this, but if it does, you can use the jfrog rt curl command, which uses the connection details configured using the jfrog c add command.

felipecrs commented 3 years ago

The jfrog rt curl is very nice, thanks for letting me know. As with curl itself, it also supports outputting to stdout. However it does not seem to support wildcards as jfrog rt download does.

❯ jfrog rt curl 'repo/project/latest/project-*.json'
{
  "errors" : [ {
    "status" : 404,
    "message" : "File not found."
  } ]
}
felipecrs commented 3 years ago

Ok, I found a way to do it without having to handle files:

jfrog rt search --fail-no-op --limit 1 'repo/project/latest/project-*.json' | jq -er '.[0].path' | xargs jfrog rt curl

Caveats:

lanwatch commented 1 year ago

Wouldn't jfrog rt download --flat=true 'repo/project/latest/project-*.json' /dev/stdout | jq -er .version work? (at least on unix-like systems)