tiny-bin
Version:
A library for building tiny and beautiful command line apps.
56 lines (55 loc) • 1.66 kB
JavaScript
/* IMPORT */
import Addon from './addon.js';
import Argument from './argument.js';
import ChainableCommand from './chainable_command.js';
import Command from './command.js';
import Option from './option.js';
/* MAIN */
class ChainableBin extends Addon {
/* API */
colors(colors) {
this.bin.metadata.colors = colors;
return this;
}
package(name, version) {
this.bin.metadata.package = name;
this.bin.metadata.version = version;
return this;
}
autoExit(exiter) {
this.bin.metadata.exiter = exiter;
return this;
}
autoUpdateNotifier(updater) {
this.bin.metadata.updater = updater;
return this;
}
usage(usage) {
this.bin.command.usage.register(usage);
return this;
}
option(name, description, options = {}) {
const option = new Option(this.bin, { name, description, ...options });
this.bin.command.options.register(option, !!options.override);
return this;
}
argument(name, description, options = {}) {
const argument = new Argument(this.bin, { name, description, ...options });
this.bin.command.arguments.register(argument);
return this;
}
action(handler) {
this.bin.command.handler = handler;
return this;
}
command(name, description, options = {}) {
const command = new Command(this.bin, { name, description, ...options });
this.bin.commands.register(command);
return new ChainableCommand(this.bin, command);
}
run(argv) {
return this.bin.run(argv);
}
}
/* EXPORT */
export default ChainableBin;