Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt.file filter does not provide enough context to filter files #3393

Open
danielo515 opened this issue Jul 31, 2024 · 0 comments
Open

Prompt.file filter does not provide enough context to filter files #3393

danielo515 opened this issue Jul 31, 2024 · 0 comments
Labels
cli enhancement New feature or request

Comments

@danielo515
Copy link
Contributor

What is the problem this feature would solve?

Hello. I'm facing some problems using the Prompt.file utility.
The first surprising thing is that using a filter to check the file extension can also remove the ability to travel to upper directories, so instead of just checking for the extension I also have to account for .., not very annoying, but worth mentioning IMO.

Second is that the provided path is not absolute, neither relative to the starting directory where the execution started, so if you want to check if the file is a directory (for example) and the user has navigated to a subfolder or to a parent folder, you have no way to know where is the actual file your filer has to check.

Here is an example of what I'm trying:

  const xmlPath = yield* Prompt.file({
    filter: (p) =>
      Effect.gen(function* (_) {
        console.log(p);
        const stat = yield* fs.stat(path.resolve(p)).pipe(Effect.orDie);
        return stat.type === "Directory" || p.endsWith(".xml");
      }),
    message: "Please select one XML file",
  });

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

The filter should receive a full path, or a relative path, or a file handle

What alternatives have you considered?

The only one I can think about is to implement my own custom input

@danielo515 danielo515 added the enhancement New feature or request label Jul 31, 2024
@IMax153 IMax153 added the cli label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants