openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 226 forks source link

Specify a local file on disk for the function store #984

Open alexellis opened 11 months ago

alexellis commented 11 months ago

Expected Behaviour

I'd like to be able to specify a local file on disk for the function store to test out definitions before publishing them on GitHub.

Current Behaviour

I can test any HTTP url via --url, but not a local file via a flag.

Why do you need this?

Better testing experience and contributing experience.

Which Solution Do You Recommend?

A new flag perhaps, or a url like file://. I think a flag fits better with the intuitive developer experience of a UNIX CLI.

Steps to Reproduce (for bugs)

  1. git clone https://github.com/openfaas/store-functions && cd store-functions
  2. faas-cli store deploy --file ./functions.json
  3. See an error
LucasRoesler commented 11 months ago

I think the cleanest solution is to support the file:// scheme or to treat scheme-less urls as local paths.

alexellis commented 11 months ago

file:// is the easiest solution, but not the cleanest.

It's confusing vs. faas-cli deploy -f / --yaml local-file, and many other tools people are used to like "kubectl" work with "kubectl apply -f https://andkuebctl apply -f ./some-local-file.yaml`

A mix of the two might work. --url with a local path, with or without a file:// scheme could be accepted and resolve to a local file if it looks like one.

LucasRoesler commented 11 months ago

Maybe move from --url to a more generic --store which supports local files or a url, like kubectl and others.

Then add a flag alias from --store to --url for backwards compat and then convert all docs to only reference --store. It is also possible to make --url hidden so that it is supported but doesn't show in the cli --help

alexellis commented 11 months ago

I think that could work :+1:

Are you interested in contributing it?

rgee0 commented 11 months ago

Lucas' approach but treading carefully with the word in the new flag.

faas-cli store deploy figlet --store ./functions.json

jars slightly because the same word is a command and a flag. Ultimately, however the file is retrieved its a file:

faas-cli store deploy figlet --file ./functions.json

and

faas-cli store deploy figlet --file https://raw.githubusercontent.com/openfaas/store/master/functions.json

Side note: From a UX / PO perspective I'd suggest that faas-cli template store mirrors whatever behaviour is settled on here

LucasRoesler commented 11 months ago

Sure I can do this.

Good point by @rgee0, I originally thought file or url was a bit like showing the details of how it works, but it probably isn't an issue here. It is not likely to be the most popular flag in the CLI :) I will stick with --file