select-files-cli
v1.0.1
Published
Allows for the selection of files via the command line
Maintainers
Readme
select-files-cli
A library designed for selecting one or more files via the command line
Basic Usage
import { selectFiles, COMPLETED, CANCELLED } from 'select-files-cli';
const { selectedFiles, status } = await selectFiles();
if (status === COMPLETED) {
console.log(selectedFiles);
// ['/absolute/path/to/file.ts', ...]
} else if (status === CANCELLED) {
console.log('Selection cancelled');
}Advanced Usage
const { selectedFiles, status } = await selectFiles(options);Options
| Option | Type | Default | Description |
|---|---|---|---|
| pageSize | number | 10 | Number of items visible at once in the list |
| multi | boolean | true | Allow selecting multiple files. Set to false to return immediately after a single file is chosen |
| selectedFiles | string[] | [] | File paths that are pre-selected when the prompt opens |
| clearConsole | boolean | true | Clear the console between renders to keep the UI in place |
| startingPath | string | process.cwd() | Directory the prompt opens in |
| root | string | process.cwd() | Top-most directory the user can navigate to. The .. option is hidden once the user reaches this directory |
| directoryFilter | (path: string) => boolean | () => true | Return false to hide a directory from the list |
| fileFilter | (path: string) => boolean | () => true | Return false to hide a file from the list |
Examples
Hide node_modules and only show TypeScript files:
const { selectedFiles, status } = await selectFiles({
directoryFilter: (path) => !path.endsWith('node_modules'),
fileFilter: (path) => path.endsWith('.ts'),
});License
MIT
