Set version from command line?

Is it possible to do something like snapcraft snap --set-version foo that sets SNAPCRAFT_PROJECT_VERSION? I use SNAPCRAFT_PROJECT_VERSION to construct the source URL to a pre-packaged tarball. It would be nice if I could command builds of different versions without having to change the hardcoded field in snapcraft.yaml every time.

The version key isn’t really hardcoded and can be set in build time, refer Using external metadata for more info.

You can make the source pulling non static by using the override-pull Scriptlets.

I’m aware of version-script and snapcraftctl set-version, but I don’t understand how they will help me in this scenario. I don’t want Snapcraft to discover the version with a script, I want to to tell Snapcraft the version as an argument.

You probably could determine the version and URL to pull via scripting, for example, make the script to parse the download webpage and grab the latest tarball release to build the snap.

In this case, it’s not necessary to specify the version via the version key or the command-line.