Coder Social home page Coder Social logo

inquirer-directory's Introduction

inquirer-directory

Relative Directory prompt for inquirer

Build Status

Installation

npm install --save inquirer-directory

Features

  • Support for symlinked files
  • Vim style navigation
  • Search for file with "/" key

Key Maps

  • Press "/" key to enter search mode.
  • Press "-" key to go up (back) a directory.

Usage

This prompt is anonymous, meaning you can register this prompt with the type name you please:

inquirer.registerPrompt('directory', require('inquirer-directory'));
inquirer.prompt({
  type: 'directory',
  ...
})

Change directory to whatever you might prefer.

Options

Takes type, name, message, basePath properties.

See inquirer readme for meaning of all except basePath.

basePath is the relative path from your current working directory

Example

inquirer.registerPrompt('directory', require('inquirer-directory'));
inquirer.prompt([{
  type: 'directory',
  name: 'from',
  message: 'Where you like to put this component?',
  basePath: './src'
}]).then(function(answers) {
  // (answers.from is the path chosen)
});

asciicast

See also example.js for a working example

License

MIT

inquirer-directory's People

Contributors

amwmedia avatar nicksrandall avatar oresoftware avatar taco avatar teamop 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

Watchers

 avatar  avatar

inquirer-directory's Issues

...!

Really looking forward to using this lib..!

If I run this code:

var inquirer = require('inquirer');
var inqDir = require('inquirer-directory');

inquirer.registerPrompt('directory', inqDir);

inquirer.prompt([{
    type: 'directory',
    name: 'from',
    message: 'Where would you like to put this component?',
    basePath: '.'
}], function (answers) {
    console.log('answers =>', answers);
});

and I select "choose this directory", the final callback does not fire.
In other words, "answers =>" never gets printed.

What am I doing wrong?

 $ npm list inquirer inquirer-directory
.........
inquirer version is 1.2.2
inquirer-directory version is 2.1.0

Error with yeoman

Hello,

I've tried using it in a yeoman generator project. But I've got this error :

TypeError: Cannot read property 'then' of undefined
    at C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\yeoman-environment\node_modules\inquirer\lib\ui\prompt.js:79:50
    at tryCatcher (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:63:31)
    at Defer.subscribeCore (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:2536:37)
    at Defer.tryCatcher (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:63:31)
    at setDisposable (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:2082:46)
    at Defer.Rx.ObservableBase.ObservableBase._subscribe (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:2097:9)
    at Defer.Rx.Observable.observableProto.subscribe.observableProto.forEach (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:2034:19)
    at MergeObserver.handleSubscribe (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:3525:28)
    at MergeObserver.next (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:3531:14)
    at MergeObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (C:\Users\KillertO\AppData\Roaming\npm\node_modules\yo\node_modules\rx\dist\rx.js:1762:31)
events.js:154
      throw er; // Unhandled 'error' event

Here's my code :

'use strict';
var yeoman = require('yeoman-generator'),
    chalk = require('chalk'),
    yosay = require('yosay'),
    slug = require('slug');

module.exports = yeoman.Base.extend({
    initializing: function() {
        this.env.adapter.promptModule.registerPrompt('directory', require('inquirer-directory'));
        this.props = {};
    },
    prompting: function() {
        // Have Yeoman greet the user.
        this.log(yosay(
            'Welcome to the cool ' + chalk.red('generator-yo-web') + ' generator!'
        ));

        var prompts = [{
            type: 'input',
            name: 'appname',
            message: 'Project name ',
            default: 'web-app'
        }, {
            type: 'directory',
            name: 'destinationFolder',
            message: 'Destination folder',
            basePath: process.cwd()
        }];

        return this.prompt(prompts).then(function(answer) {
            this.props.appname = slug(answer.appname);
            this.props.destinationRoot = answer.destinationFolder.concat('/' + this.props.appname);
        }.bind(this));
    },

    default: function() {},
    writing: function() {},
    install: function() {}
});

validate fn does not seem to be invoked

no idea why, stepped through the code multiple times, and the validate opt function doesn't seem to get invoked

var inquirer = require('inquirer');
var inqDir = require('inquirer-directory');

inquirer.registerPrompt('directory', inqDir);

inquirer.prompt([ {
  type: 'directory',
  name: 'from',
  message: 'Where would you like to put this component?',
  basePath: '.',
  validate: function () {
    console.log('in validate');   // put a break point here
    return true;
  }
} ]).then(function (answers) {
  console.log('answers =>', answers);
});

it's quite easy to debug this with the new --inspect flag

try node --inspect this-file.js

Choose multiple directories in one session

we have the promise callback:

.then(function(answers){

});

this seems to suggest that we could select multiple directories during one round of selection.
However, my brief experience with this lib seems to dictate that you can only select one directory with each go-around.

Please help me out - can we select multiple directories without invoking inquirer.prompt() twice?

If not, please change the semantics to singular "answer" instead of "answers"

.then(function(answer){

});

option to select file path

Is there an option we can pass to this library such that we can select file paths as well as directory paths?

Would be very useful for my use case, thanks!

promises

Does this library work with promises?

If so, maybe put that in the readme? I am hoping it does, because inquirer works with promises.

thanks

Vim Style completion

I saw in issue #1, that vim style completion was removed in favor of being able to type the first letter of a file to jump to it. Is there any way that we can bring back vim style completion and still make people happy that want auto completion?

Vim style navigation (using j/k to move up/down) is something that I have come to expect in the command line. I'm not sure what the convention is for auto completion though.

@kentcdodds, let me know if you have any thoughts on this.

Should a filter option be allowed?

I have a structure on the likes of SOME_PATH/components.
I want to remove the components part in the case the user selected it without knowing so I don't generate SOME_PATH/components/components.

Should be a inquirer-directory option to validate?
I can make a PR if that would be a good idea,

For large directories, use right / left arrow keys

Imagine a directory with 100 folders, or 1000 folders.... it gets awkward to "choose this directory" -

e.g. if you you want to choose a directory, you would have to navigate (using enter) to the right dir, and then once the current directory is the one you want, then you have to scroll to get to "choose this directory" which means you might have to scroll through 999 items.

Instead, I recommend having an option of right and left arrow keys to navigate through dirs =>

Left arrow key is to "go up" a directory. Right arrow key is to drill into a directory.

And then enter becomes selecting / choosing the highlighted dir.

Is this an existing setup or is this lib not configured for this?

Make 'choose this directory' default

I'm using inquirer-directory with plop to generate components. Sometimes I want to generate nested components, but 90% of the time I want to generate in the components root folder.

With the current default of inquirer-directory I cannot just enter my way through the menu, because I need to navigate to 'choose this directory'. Not a big deal but it still requires some extra brain cycles :)

It would be nice if one of the following could be done:

  1. Display 'choose this directory' as the first list item, rather than the last
  2. Start with the cursor at 'choose this directory'
  3. Make the position of 'choose this directory' configurable (top, bottom, some other way?)
  4. Any other way to make the base directory the default

How do you feel, would that make sense?

Feature Request: File selector

It would be useful to have the option of selecting files in addition to directories. How hard would that be to add? Not sure if it would be easier to integrate here or built a separate repo. I'm guessing the former but wanted to check.

error using library - cb is not a function

got this just now


SFOC02Q106HG8WM:suman t_millal$ node lib/interactive/index2.js 
? Where you like to put this component? (Use arrow keys)
? Where you like to put this component? default-conf-files
(Use "/" key to search this directory)


readline.js:982
            throw err;
            ^

TypeError: cb is not a function
    at module.exports (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/node_modules/run-async/index.js:23:5)
    at Prompt.filter (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/node_modules/inquirer/lib/prompts/base.js:128:3)
    at Prompt.<anonymous> (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/node_modules/inquirer/lib/prompts/base.js:56:10)
    at Prompt.onSubmit (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/index.js:234:8)
    at AnonymousObserver.Rx.AnonymousObserver.AnonymousObserver.next (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/node_modules/inquirer/node_modules/rx-lite/rx.lite.js:1535:12)
    at AnonymousObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/t_millal/WebstormProjects/oresoftware/suman/node_modules/inquirer-directory/node_modules/inquirer/node_modules/rx-lite/rx.lite.js:1469:31)

Allow default and/or basePath depending on previous answers

Here's my case: depending on previous answers I'd like to start in different directories.

I found that inquirer-directory purposefully removes the default.
Why is that?

The best case scenario for me would be to allow defining paths relative to the base path like this:

{
  type: 'directory',
  name: 'path',
  message: 'Where to put the component?',
  basePath: `./app`,
  default: ({isStateful}) => isStateful ?
    './statefulComponents' :
    './statelessComponents',
},

(it should be possible to go back to the base path)

or like this:

{
  type: 'directory',
  name: 'path',
  message: 'Where to put the component?',
  basePath: ({isStateful}) => isStateful ?
    './app/statefulComponents' :
    './app/statelessComponents',
},

(in this case navigation to the upper directory would be impossible)

IMO both those options are worth considering.
I'm not sure which one is easier to implement but I guess the latter.

Two Issues -- Not getting Path back in answers Object and How to move outside of basedir

Trying to use this in my project. First is that when I used this i don't get the path of the selected directory back and second is that users can't move outside of the baseDir

I have a default location for data files to be saved to but I want to give users the option to change the directory. I start them out in the default location but want to allow them to move to another location if they wish. This would mean going up and outside of the default location.

The default directory is an empty directory so does the baseDir get selected if you only have the choose this directory option?

Error with latest inquirer.js

Hi ,
When using inquirer 1.0.2 and inquirer-directory 2.0.0 the code is broken ,
this is the error i got :

readline.js:925
            throw err;
            ^

TypeError: cb is not a function
    at module.exports (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/run-async/index.js:23:5)
    at Prompt.filter (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inquirer/lib/prompts/base.js:128:3)
    at Prompt.<anonymous> (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inquirer/lib/prompts/base.js:56:10)

    at Prompt.onSubmit (/Users/idan/readytodeploy/node_modules/inquirer-directory/index.js:234:8)
    at AnonymousObserver.Rx.AnonymousObserver.AnonymousObserver.next (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inqu
irer/node_modules/rx-lite/rx.lite.js:1535:12)
    at AnonymousObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_mo
dules/inquirer/node_modules/rx-lite/rx.lite.js:1469:31)
    at AnonymousObserver.tryCatcher (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inquirer/node_modules/rx-lite/rx.lite
.js:63:31)
    at AutoDetachObserverPrototype.next (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inquirer/node_modules/rx-lite/rx.
lite.js:5782:51)
    at AutoDetachObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_m
odules/inquirer/node_modules/rx-lite/rx.lite.js:1469:31)
    at AnonymousObserver._onNext (/Users/idan/readytodeploy/node_modules/inquirer-directory/node_modules/inquirer/node_modules/rx-lite/rx.lite.js
:4234:13)

basePath should allow an absolute path

hey man, I was just trying this out and ran into a little snag. I wanted to make basePath the path of the plopfile (available via plop.getPlopfilePath()) and the plugin errored. I'm guessing that your plugin expects a relative path, but I might be wrong. Didn't have the time to dig in further.

ENOENT error
plopfile code

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.