Coder Social home page Coder Social logo

inquirer-fuzzy-path's Introduction

inquirer-fuzzy-path

npm npm

Fuzzy file/directory search and select prompt for Inquirer.js

inquirer-fuzzy-path demo

Usage

Register the prompt with inquirer:

inquirer.registerPrompt('fuzzypath', require('inquirer-fuzzy-path'))

Call the prompt:

  return inquirer.prompt([
    {
      type: 'fuzzypath',
      name: 'path',
      excludePath: nodePath => nodePath.startsWith('node_modules'),
        // excludePath :: (String) -> Bool
        // excludePath to exclude some paths from the file-system scan
      excludeFilter: nodePath => nodePath == '.',
        // excludeFilter :: (String) -> Bool
        // excludeFilter to exclude some paths from the final list, e.g. '.'
      itemType: 'any',
        // itemType :: 'any' | 'directory' | 'file'
        // specify the type of nodes to display
        // default value: 'any'
        // example: itemType: 'file' - hides directories from the item list
      rootPath: 'app',
        // rootPath :: String
        // Root search directory
      message: 'Select a target directory for your component:',
      default: 'components/',
      suggestOnly: false,
        // suggestOnly :: Bool
        // Restrict prompt answer to available choices or use them as suggestions
      depthLimit: 5,
        // depthLimit :: integer >= 0
        // Limit the depth of sub-folders to scan
        // Defaults to infinite depth if undefined
    }
  ]);

Change log

  • In version 2.2.0 new option excludeFilter was added.
  • In version 2.1.0 new option depthLimit was added.
  • In version 2.0.0 option filterPath was deprecated. Please use excludePath and itemType instead.

Related

  • inquirer - A collection of common interactive command line user interfaces

License

MIT © adelsz

inquirer-fuzzy-path's People

Contributors

adelsz avatar cuginoale avatar dependabot[bot] avatar haykokoryun avatar msftenhanceprovenance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

inquirer-fuzzy-path's Issues

TypeError: sink._addParentTeardownLogic is not a function

Hi all,

a few days ago a CLI tool I wrote threw this error on a colleague's machine. I cannot reproduce this on my environment, so I can currently not provide you with a reproducible scenario sadly.

I can provide you with a more detailed stacktrace etc on Thursday if required.

The error itself gets throws within inquirer -> rxjs. I found this old issue in the angular CLI which also had rxjs as the origin of the error angular/angular-cli#12072

The problem may be the dependency to the old inquirer version 5.2.0 as this one still uses [email protected] which maybe already had this bug.

Do you think updating the package.json to require a newer version of inquirer with a newer rxjs dependency is possible? Or adding inquirer as peerDependency maybe?

I will try this workaround on Thursday to check whether it is actually the problem on his machine.

Question object ignores "prefix" and "suffix"

Hi,

I am testing the plugin and I noticed a discrepancy to the question object.

The question object ignores the keys:

  • prefix
  • suffix

See the question object from Inquirer.js.


Example:

return inquirer.prompt([
    {
      type: 'fuzzypath',
      name: 'path',
      excludePath: nodePath => nodePath.startsWith('node_modules'),
      itemType: 'any',
      rootPath: 'app',
      message: 'Select a target directory for your component:',
      default: 'components/',
      suggestOnly: false,
      depthLimit: 5,
      prefix: '-->'
    }
]);

The arrow --> should be displayed before the question Select a target ... instead of the question mark ...

Default value ignored

It's not clear to me how one would invoke the "default" behavior from the prompt since pressing enter immediately is going to select rootPath. Looking at the code, it looks like the default is just passed on to inquirer. is there some method for using the default value from the prompt that I'm missing?

The question i'm using is:

{
        type: "path",
        name: "path",
        message: "Directory",
        itemType: "directory",
        rootPath: "src/app",
        default: "src/app/shared/components"
}

I've also tried default: 'shared/component' (relative to rootPath).

I'm not exactly sure what expected behavior would be. Perhaps it could list the default value as the first option with the root as the second, and so on e.g.

> src/app/shared/components
  src/app
  src/app/foo
  src/app/bar
  src/app/baz

adding hard coded values to the list

A great feature will be to add a hardcoded values to the list results.
For example, I want the default path to be ./components but this path doesn't exist yet (my app will create it in such case).
Or maybe I want to add some popular paths which of course doesn't exist yet.

Tab complete throws TypeError exception

Seeing an exception thrown when trying to do a tab complete on a path that in not in the rootPath.

const choice = Choices.prototype.getChoice.call(this.currentChoices, choiceIndex);

TypeError: Cannot read property 'value' of undefined at module.exports.currentChoices.getChoice (/Users/jranz/amplify/amplify-cli/packages/amplify-category-xr/node_modules/inquirer-fuzzy-path/index.js:89:35) at InquirerFuzzyPath.Prompt.onKeypress (/Users/jranz/amplify/amplify-cli/packages/amplify-category-xr/node_modules/inquirer-autocomplete-prompt/index.js:217:29) ...

I tried adding a check for 'choice' returning:
if (!choice) { return { value: null, name: null, short: null } }

and I see a line in the autocomplete-prompt package also throws an exception:
https://github.com/mokkabonna/inquirer-autocomplete-prompt/blob/master/index.js#L215

TypeError: Cannot read property 'length' of null at InquirerFuzzyPath.Prompt.onKeypress (/Users/jranz/amplify/amplify-cli/packages/amplify-category-xr/node_modules/inquirer-autocomplete-prompt/index.js:221:61) ...

I am able to workaround this by checking if 'autoCompleted' is null and setting it to empty string.

I'll open a similar issue in the autocomplete package.

I really like this plugin, so let me know if I am either doing something incorrect or if I can help make the fix to improve this use case!

Error UnhandledPromiseRejectionWarning

When I use this plugin in windows 10 show me this error:

(node:8392) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, scandir 'c:\Documents and Settings'(node:8392) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8392) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

add excludeFilter option to filter final result

There is an edge case where the excludePath option is not sufficient to achieve the desired result.

For example say you were trying to list all of the directories in the current directory to carry out some process inside the selected one, naturally you would want to exclude .. If you do that however you exclude the current directory and thus all of the sub directories.

A proposal is to offer an excludeFilter option that expects a function to run for each item in the final result to decide if it should be filtered out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.