You can define commands (like functions) like this (in the shell if you want for easy trial and error):
# Returns indices that would sort the input list
def argsort [--reverse (-r)]: list<number> -> list<int> {
enumerate | sort-by item --reverse=$reverse | get index
}Then you get nice help like this "for free":
