Cargo has a custom subcommands feature which lets you run an appropriately named executable found on the path when you invoke cargo and it doesn't recognize the subcommand you provide. It's a super useful feature and there are a lot of 3rd party commands implemented based on it. One I particularly love is cargo-lambda. It makes it incredibly easy to build, deploy and invoke AWS lambda functions written in Rust and was a real step change in productivity when I started using it.
I am exploring building and deploying Lambda functions using nim instead of rust and find myself missing cargo-lambda greatly. Nimble has custom tasks which can be used to achieve similar functionality, but the downside of this approach is that you need to define all the tasks yourself and duplicate them for each package as there is no way to import tasks into a nimble file AFAIK. By encapsulating all this build logic into reusable executable(s) it becomes trivially easy to depend on them and use wherever you need.
What are the maintainer/community thoughts on introducing a similar mechanism to cargo subcommands into nimble? It would work essentially the same - if you invoke nimble lambda build and you don't have a custom lambda task already, it would call out to nimble-lambda build if it finds it on the path. I've implemented a basic prototype locally and it's quite a simple code change, but it is a significant design decision to make. Before I go making PRs or writing RFCs I want to get a temperature check.
Thanks
maybe i'm missing something, i've never really used nimble, but can't you
# Package
version = "0.1.0"
author = "brendo-m"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["tmp"]
# Dependencies
requires "nim >= 1.7.3"
import std/os
task lambda, "build on aws lambda":
case commandLineParams()[^1]
of "build":
echo "building on aws lambda..."
of "install":
echo "installing..."
else:
echo "usage: nim lambda {build/install}, got ",commandLineParams()
❯ nimble lambda build
Executing task lambda in /tmp/tmp.nimble
building on aws lambda...
❯ nimble lambda install
Executing task lambda in /tmp/tmp.nimble
installing...
@Araq - a concrete benefit is that if nimble calls nimble-lambda, it can pass along the command line args and parsed PackageInfo for it to use. nimble-lambda needs to cross compile and needs to know dependencies and which files to compile and package.
@shirleyquirk - this is possible, but a) the task logic is going to be very complicated because of the above cross compiling and b) this nim.lambda file would need to be duplicated in every package that wants to build lambdas wouldn't it?