You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cliffy allows to map option values, but doesn't wait for any promises returned from the value function. One could make the argument that this is by design and the action code should deal with that, but it bars one from use cases like allowing users to pass a value or a file path, and read the content from those before calling the action. Sample code for posterity:
.option("-j, --jwk","JWK to use for verifying JWTs",{asyncvalue(value){if(value==="-"){// If it's stupid, but it works, it ain't stupid.returnawaitnewResponse(Deno.stdin.readable).text();}// Apply some heuristics to check whether this might be a file// path, and if so, try to read the file. If this fails for// whatever reason, treat the value as a literal JWK and// continue; the error will be caught during validation later.if(value&&!value.startsWith("{")&&(value.startsWith("/")||value.startsWith(".")||/^[a-zA-Z]:[\\/]/.test(value))){try{awaitDeno.stat(value);returnawaitDeno.readTextFile(value,{signal});}catch{returnvalue;}}returnvalue;},})
This allows users to call the command with either of these:
# Pipe to stdin
cat jwk.json | cmd --jwk -
# Pass a file path
cmd --jwk ./jwk.json
# Pass the literal value on the command line
cmd --jwk "$(cat ./jwk.json)"
However, now my action needs to be aware of the fact that jwk may be a promise or a string. Yes, this is easily handled, but I'd prefer Cliffy to await any promises returned by value(), to stay consistent with non-mapped values.
The text was updated successfully, but these errors were encountered:
Cliffy allows to map option values, but doesn't wait for any promises returned from the value function. One could make the argument that this is by design and the action code should deal with that, but it bars one from use cases like allowing users to pass a value or a file path, and read the content from those before calling the action. Sample code for posterity:
This allows users to call the command with either of these:
However, now my action needs to be aware of the fact that
jwk
may be a promise or a string. Yes, this is easily handled, but I'd prefer Cliffy to await any promises returned byvalue()
, to stay consistent with non-mapped values.The text was updated successfully, but these errors were encountered: