UNPKG

2.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@anycli/command");
4const cli_ux_1 = require("cli-ux");
5class Hello extends command_1.Command {
6 constructor() {
7 super(...arguments);
8 // this makes the parser not fail when it receives invalid arguments
9 // set it to off if you need to accept variable arguments
10 // static strict = false
11 // runs the parser and stores the results in this.options
12 // you should run this even if you have no flags/args so it properly errors out
13 // (see strict above for variable argument commands)
14 //
15 // stores the parsed flags in options.flags[name]
16 //
17 // stores the parsed args in options.args[name] as an object
18 // but also in options.argv as an array
19 // you can get the raw args passed to the command with this.argv
20 // or from this.options.argv which will remove any args that were actually flags
21 this.options = command_1.parse(this.argv, Hello);
22 }
23 // entry point of command
24 async run() {
25 const name = this.options.flags.name || 'world';
26 cli_ux_1.default.log(`hello ${name} from hello!`);
27 // this.options.flags.force is a boolean
28 // this.options.args.file and this.options.argv[0] is a string or undefined
29 }
30}
31Hello.title = 'scaffolded command that says hello';
32// hide the command from help
33// can also set hidden on args and flags
34// static hidden = true
35// usage is set by default
36// add your own by setting this variable
37// can be a string or array
38// static usage = 'title of command'
39Hello.description = `
40Add a longer description here
41...
42...
43`;
44Hello.examples = [
45 `$ example-plugin-ts hello
46hello world from hello!
47`,
48 `$ example-plugin-ts hello --name myname
49hello myname from hello!
50`,
51 '$ example-plugin-ts hello file outputs "hello world!" to file',
52 '$ example-plugin-ts hello --force',
53 '$ example-plugin-ts hello --help',
54];
55// allow running this command by running `$ example-plugin-ts foobar`
56// static aliases = ['foobar']
57Hello.flags = {
58 // flag with a value (-n, --name=VALUE)
59 name: command_1.flags.string({
60 char: 'n',
61 description: 'name to print',
62 hidden: false,
63 required: false,
64 multiple: false,
65 }),
66 // flag with no value (-f, --force)
67 force: command_1.flags.boolean({
68 char: 'f',
69 }),
70};
71Hello.args = [
72 {
73 name: 'file',
74 required: false,
75 description: 'file to output',
76 },
77];
78exports.default = Hello;