nodejs / nodejs/node

Add ability to suppress `.command`s in REPL

Ouverte
#57,989 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

feature request never-stale repl
Langage dominant
JavaScript
Étoiles
122k
Forks
37.3k
Merge moyen
4 j 2 h
PR mergées (30 j)
283

Description

What is the problem this feature will solve?

I'm building a custom shell-like REPL for an application that's written in Javascript. To achieve this, I'm using the REPL module because it's more feature-rich than the readline module (for example, using ctrl+r (and looking through the Node code, I couldn't actually find where this functionality is defined...)). It's also much easier to work with than the readline module.

However, I'm trying to secure the application as best as possible so my users don't fall into holes when trying to execute commands, and so I'm restricting access to the REPL dot commands of .editor, .help, etc. I would also like to take advantage of the .commands in my own eval function so I can also extend the functionality of my REPL too.

Specifically: the problem this feature will solve is to allow .commands through to the eval function. Some guard rails will probably need to be put in place (such as making sure the default eval isn't being used, or writing a warning in the docs).

What is the feature you are proposing to solve the problem?

Add an optional property to the ReplOptions called nativeDotCommands (or whatever fits), and adjust the if statement to account for this property (and likely adjustments to other parts of the codebase)

What alternatives have you considered?

Currently, I'm setting repl.commands = {} to remove all the commands, however of course this is throwing an error from my linter because that property is read-only. I can suppress the error, but that still doesn't allow me to use .commands within my application. So far, this is the best work around I've got (short of rewriting and using the readline module.)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’instruction if indiquée dans lib/repl.js et examinez la définition de ReplOptions ainsi que la manière dont repl.commands est exposé. Suivez le traitement actuel des commandes pointées, puis déterminez comment un paramètre facultatif nativeDotCommands pourrait leur permettre d’atteindre un eval personnalisé sans affaiblir le comportement par défaut. Le travail est terminé lorsque les REPL personnalisées peuvent recevoir des commandes pointées tout en conservant la protection du traitement par défaut existant.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
cli
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.