1.0.4 • Published 4 years ago

@interactive-cli-helper/file-suggestor v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

interactive-cli-helper / file suggestor

Allow to auto-suggest one file name as a command suggestion for interactive-cli-helper package.

Getting started

npm i @interactive-cli-helper/file-suggestor

Usage

Give the default export of package as onSuggest value in command options.

With functional API

import CliHelper from 'interactive-cli-helper';
import cliFileSuggestor from '@interactive-cli-helper/file-suggestor';
import fs from 'fs';

// Assuming cli is a CliHelper/CliListener instance

// Declare it
cli.command('read', filename => {
  console.log(fs.readFileSync(filename, 'utf-8'));
}, {
  onSuggest: cliFileSuggestor,
});

cli.listen();

With decorators API

import { CliMain, CliBase, Command, CliCommand, CliCommandInstance, CliExecutor } from 'interactive-cli-helper';
  
@CliCommand()
class ReadCommand {
  onSuggest = cliFileSuggestor;
  
  executor: CliExecutor = filename => {
    console.log(fs.readFileSync(filename, 'utf-8'));
  };
}
 
@CliMain({ suggestions: true })
class Main extends CliBase {
  onNoMatch: CliExecutor = 'No command matched your search.';
 
  // Assign ReadCommand for 'read' command
  @Command('read', ReadCommand)
  read_command!: CliCommandInstance<ReadCommand>;
}
 
const cli = new Main();
cli.listen();
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago