From 8c89e44ea59e8270d8dbfecfbf9a8512d8d61281 Mon Sep 17 00:00:00 2001 From: Roy Razon Date: Mon, 27 Nov 2023 17:23:08 +0200 Subject: [PATCH] fix: empty args --- packages/cli-common/src/commands/base-command.ts | 6 ++++++ packages/cli-common/src/hooks/init/load-plugins.ts | 2 +- packages/cli/src/commands/logs.ts | 2 +- packages/cli/src/commands/shell.ts | 2 +- packages/cli/src/commands/up.ts | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/cli-common/src/commands/base-command.ts b/packages/cli-common/src/commands/base-command.ts index 1e4a3951..d07b724d 100644 --- a/packages/cli-common/src/commands/base-command.ts +++ b/packages/cli-common/src/commands/base-command.ts @@ -3,6 +3,7 @@ import { LogLevel, Logger, logLevels, ComposeModel, ProcessError, telemetryEmitter, } from '@preevy/core' import { asyncReduce } from 'iter-tools-es' +import { ParsingToken } from '@oclif/core/lib/interfaces/parser' import { commandLogger } from '../lib/log' import { composeFlags, pluginFlags } from '../lib/common-flags' @@ -117,6 +118,11 @@ abstract class BaseCommand extends Comm // eslint-disable-next-line @typescript-eslint/return-await return await super.catch(error) } + + // eslint-disable-next-line class-methods-use-this + protected argsFromRaw(raw: ParsingToken[]): string[] { + return raw.filter(arg => arg.type === 'arg').map(arg => arg.input).filter(Boolean) + } } export default BaseCommand diff --git a/packages/cli-common/src/hooks/init/load-plugins.ts b/packages/cli-common/src/hooks/init/load-plugins.ts index 2b1c9769..7acb96e7 100644 --- a/packages/cli-common/src/hooks/init/load-plugins.ts +++ b/packages/cli-common/src/hooks/init/load-plugins.ts @@ -82,7 +82,7 @@ export const initHook: OclifHook<'init'> = async function hook(args) { }) if (id === 'help') { - const restArgs = raw.filter(arg => arg.type === 'arg').map(arg => arg.input) + const restArgs = raw.filter(arg => arg.type === 'arg').map(arg => arg.input).filter(Boolean) argv.splice(0, argv.length, ...restArgs) } } diff --git a/packages/cli/src/commands/logs.ts b/packages/cli/src/commands/logs.ts index c3f28cb9..8af0c88a 100644 --- a/packages/cli/src/commands/logs.ts +++ b/packages/cli/src/commands/logs.ts @@ -80,7 +80,7 @@ export default class Logs extends DriverCommand { async run(): Promise { const log = this.logger const { flags, raw } = await this.parse(Logs) - const restArgs = raw.filter(arg => arg.type === 'arg').map(arg => arg.input) + const restArgs = this.argsFromRaw(raw) let connection: MachineConnection let userModel: ComposeModel diff --git a/packages/cli/src/commands/shell.ts b/packages/cli/src/commands/shell.ts index a09e5833..3a2f5b89 100644 --- a/packages/cli/src/commands/shell.ts +++ b/packages/cli/src/commands/shell.ts @@ -23,7 +23,7 @@ export default class Shell extends DriverCommand { const { args, raw } = await this.parse(Shell) const driver = await this.driver() - const restArgs = raw.filter(arg => arg.type === 'arg').slice(1).map(arg => arg.input) + const restArgs = this.argsFromRaw(raw).slice(1) const result = await commands.shell({ envId: args.envId, diff --git a/packages/cli/src/commands/up.ts b/packages/cli/src/commands/up.ts index cae702a0..c1e6e949 100644 --- a/packages/cli/src/commands/up.ts +++ b/packages/cli/src/commands/up.ts @@ -52,7 +52,8 @@ export default class Up extends MachineCreationDriverCommand { async run(): Promise { const { flags, raw } = await this.parse(Up) - const restArgs = raw.filter(arg => arg.type === 'arg').map(arg => arg.input) + const restArgs = this.argsFromRaw(raw) + this.log('restArgs', restArgs) const driver = await this.driver() const machineCreationDriver = await this.machineCreationDriver()