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

Autocompletion & Validation for Filepaths #124

Open
ktnlvr opened this issue Apr 15, 2023 · 2 comments
Open

Autocompletion & Validation for Filepaths #124

ktnlvr opened this issue Apr 15, 2023 · 2 comments

Comments

@ktnlvr
Copy link

ktnlvr commented Apr 15, 2023

Is your feature request related to a problem? Please describe.
Sometimes you need to specify a path to a file, so an autocomplete & a validator for that would be great.

Describe the solution you'd like
A new struct like PathAutocomplete, with options for picking only files, only directories or both. Symlinks can be ignored or replaced by their respective absolute paths, depending on the instance. Usage of back or forward slashes can be either always backslash, always forward slash or platform-dependent. Display of hidden folders can also be enabled or disabled with a flag. Options for displaying an absolute, relative or current-working-directory-relative path are also required. Read or write permissions can also be checked for. Most of the options mentioned above also apply to a possible PathValidator struct. All of this can be locked behind a feature-flag.

Describe alternatives you've considered
There aren't too many alternatives to consider, it either becomes a feature or it doesn't.

Additional context
I am building a CLI tool that suggests to enter the filepath if the filepath was not provided as a command line argument. I am happy to go ahead and implement this PR ahead, but I wonder if I am missing anything.

@mikaelmello
Copy link
Owner

You have my support. It isn't the first time someone asked for this but I was a little wary of pursuing because dealing with files, and paths, on a multi-platform lib is a minefield.

However, I do see now how it would be valuable to have at least something, as inquire is not like a stdlib. We can build something basic that works well enough, and iterate on top of that.

It will certainly need to be behind a feature flag though so any potential users know about the state of the solution before using, we'll certainly discover many edge cases in the future lol.

Currently I'm working on a architecture revamp to make way for future large-scale improvements, so if you'd like to get on it already I'd certainly appreciate it.

@ktnlvr
Copy link
Author

ktnlvr commented Apr 18, 2023

Wow is it more complex that I anticipated lol.

I looked into it and wondered whether it would even be appropriate for this library to implement. So far the library has not implemented any formatters and validators for users, is that part of the library's philosophy?

There is also an issue with UX, since when selecting a path from a list of paths can be confusing: displaying a full path looks cluttered, while a relative path does nothing to say what it is relative to.

One possibility for fixing all of the above is implementing a new prompt type, like pub struct Explorer (the name is up for debate) instead of a validator & autocomplete. The issue with that approach is that a path can be read through Text, Select, and MultiSelect. My solution so far is a new Prompt type. If we allow Dates to have a more useful prompt, why not a paths?

Just wanted to check that my approach aligns with the library's values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants