From 45cd7756b907dedcb9cbf40c4c29eda786f9be30 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 21 Sep 2023 13:20:43 -0600 Subject: [PATCH] feat: add flags and args --- src/commands/core-v2.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/commands/core-v2.ts b/src/commands/core-v2.ts index 50181c4..124d7e3 100644 --- a/src/commands/core-v2.ts +++ b/src/commands/core-v2.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 CoreV2 extends Command { - public async run(): Promise { - this.log(`hello I am an @oclif/core@v2 plugin from ${this.config.root}!`) + 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(CoreV2) + this.log(`hello I am a CJS plugin from ${this.config.root}!`) + return {args, flags} } }