I would like to access the localStorage outside a Vorpal context to autocomplete a command by the array in my localStorage.
I add data in localStorage like this:
const cli = require('../../../cli'); // just an export: module.exports = require('vorpal')();
cli
.command('author add <name>', 'Add an author to the preferences.')
.action((args, cb) => {
let authors = JSON.parse(cli.localStorage.getItem('authors'));
if (authors === null) {
authors = [];
}
authors.push(args.name);
cli.localStorage.setItem('authors', JSON.stringify(authors));
cb();
});
The command who need to get access to the localStorage:
// Remove an author to the local storage
cli
.command('author remove <name>', 'Remove an author to the preferences.')
.autocomplete(cli.localStorage.getItem('authors')) // How to get the localStorage here?
.action((args, cb) => {
cli.log(args);
cb();
});
The error thrown is: cli.localStorage.getItem is not a function
Hi,
I would like to access the localStorage outside a Vorpal context to autocomplete a command by the array in my localStorage.
I add data in localStorage like this:
The command who need to get access to the localStorage:
The error thrown is:
cli.localStorage.getItem is not a function