Public
HTTP (deprecated)
version 30
Readme

Cli Vals

Cli vals are a new type of val (same as http, email, cron and script vals). A cli val must use a function without args as it's default export.

The function body will run on the user device using deno. An error message will be shown if deno is not installed.

export default function() { if (Deno.args.length == 0) { console.error("<name> arg is required!"); Deno.exit(1); } console.log(`Hey ${Deno.args[0]}!`); }

Fork @pomdtr/example_cli to get started.

Of course, you can use a cli framework to parse arguments (ex: cliffy).

Running a cli val

Go to https://pomdtr-cli.web.val.run/v/<author>/<name>[?v=<version>] to get a runnable script for your val.

You can pipe the script to a shell to test it

curl 'https://pomdtr-cli.web.val.run/v/pomdtr/cli_example' | sh -s Steve Hello Steve!

Or save it to your $PATH.

# save the script to the ~/.local/bin folder curl 'https://pomdtr-cli.web.val.run/v/pomdtr/cli_example' > ~/.local/bin/cli_example # make the script executable chmod +x ~/.local/bin/cli_example # run the installed val cli_example Steve

Allowing cli vals to access private resources

Cli vals run on your device, so by default they can only access public/unlisted vals.

You can set the DENO_AUTH_TOKENS env var in your shell config to allow deno to import private vals.

export DENO_AUTH_TOKENS=<your-token>@esm.town

Cli vals don't have access to val town tokens. Instead of trying to replicate your valtown secrets locally, you can configure your cli vals to call your http endpoints using fetch.

Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
pomdtr-cliold.web.val.run
December 29, 2023