dzhv.io
dzhv.io11mo ago

Is there a feature allowing custom "Allow?" CLI inputs?

For example, if you deno run some program that reads from the file system, you're prompted Deno requests read access to... Allow? and you specify whether or not you want Deno to proceed. Is there any built-in or native feature that would let me cause the same kind of CLI "Allow?" prompt to appear with a custom message?
3 Replies
dzhv.io
dzhv.ioOP11mo ago
I found alert() and prompt() from https://examples.deno.land/prompts to be sufficient.
Input Prompts - Deno by Example
Prompts are used to ask the user for input or feedback on actions. -- Deno by example is a collection of annotated examples for how to use Deno, and the various features it provides.
Deno AI Helper
Deno AI Helper11mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your description, it seems like you're asking about creating custom permission prompts within a Deno program. Deno's permission prompts are a built-in feature of the runtime for security-sensitive operations, such as file system access, network access, etc. These prompts are not designed to be customizable by users or to be used for arbitrary confirmation messages within scripts. If you're looking to implement a custom "Allow?" prompt for your own logic within a Deno script, you would typically handle this by writing your own function to prompt the user and process their input. This isn't a feature provided by Deno's permissions API, but you can use Deno's standard input (stdin) to achieve something similar. Here's a simple example of how you might implement a custom prompt:
async function customPrompt(message) {
const buf = new Uint8Array(1024);

// Ask the user the custom question
console.log(message);

// Wait for the user's response
const n = await Deno.stdin.read(buf);
const answer = new TextDecoder().decode(buf.subarray(0, n)).trim();

// Process the user's response
return answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y';
}

// Usage
const userConsent = await customPrompt('Do you want to proceed? Allow? (y/n)');
console.log(userConsent ? 'User allowed the action.' : 'User did not allow the action.');
async function customPrompt(message) {
const buf = new Uint8Array(1024);

// Ask the user the custom question
console.log(message);

// Wait for the user's response
const n = await Deno.stdin.read(buf);
const answer = new TextDecoder().decode(buf.subarray(0, n)).trim();

// Process the user's response
return answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y';
}

// Usage
const userConsent = await customPrompt('Do you want to proceed? Allow? (y/n)');
console.log(userConsent ? 'User allowed the action.' : 'User did not allow the action.');
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you're looking for more advanced CLI interaction, you might want to look into third-party libraries that provide more sophisticated command-line interface tools.
bartlomieju
bartlomieju11mo ago
Deno.pernissions.request is probably what you're looking for