From ca4f0190c97d677f990d5385c7cbff173f993174 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 21 Sep 2023 13:17:48 -0600 Subject: [PATCH] feat: add flags and args --- src/commands/esm2.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/commands/esm2.ts b/src/commands/esm2.ts index 1f7d15a..6351e66 100644 --- a/src/commands/esm2.ts +++ b/src/commands/esm2.ts @@ -1,7 +1,36 @@ -import {Command} from '@oclif/core' +import {Args, Command, Flags, Interfaces} from '@oclif/core' + +type Result = { + args: Interfaces.InferredArgs + flags: Interfaces.InferredFlags +} export default class ESM2 extends Command { - async run(): Promise { + static flags = { + optionalString: Flags.string(), + defaultString: Flags.string({ + default: 'simple string default', + }), + defaultFnString: Flags.string({ + default: async () => Promise.resolve('async fn default'), + }), + } + + static args = { + optionalArg: Args.string(), + defaultArg: Args.string({ + default: 'simple string default', + }), + defaultFnArg: Args.string({ + default: async () => Promise.resolve('async fn default'), + }), + } + + static enableJsonFlag = true + + async run(): Promise { + const {args, flags} = await this.parse(ESM2) this.log(`hello I am an ESM plugin from ${this.config.root}!`) + return {args, flags} } }