diff --git a/packages/cli-common/src/commands/base-command.ts b/packages/cli-common/src/commands/base-command.ts index 1e4a3951..7b31c5c0 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' 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-common/src/index.ts b/packages/cli-common/src/index.ts index 0539015f..b34a45e4 100644 --- a/packages/cli-common/src/index.ts +++ b/packages/cli-common/src/index.ts @@ -3,6 +3,6 @@ export * as text from './lib/text' export { HookName, HookFunc, HooksListeners, Hooks } from './lib/hooks' export { PluginContext, PluginInitContext } from './lib/plugins/context' export { composeFlags, pluginFlags, envIdFlags, tunnelServerFlags, urlFlags } from './lib/common-flags' -export { formatFlagsToArgs, parseFlags, ParsedFlags } from './lib/flags' +export { formatFlagsToArgs, parseFlags, ParsedFlags, argsFromRaw } from './lib/flags' export { initHook } from './hooks/init/load-plugins' export { default as BaseCommand } from './commands/base-command' diff --git a/packages/cli-common/src/lib/flags.ts b/packages/cli-common/src/lib/flags.ts index 10c1f6a9..3e22f43a 100644 --- a/packages/cli-common/src/lib/flags.ts +++ b/packages/cli-common/src/lib/flags.ts @@ -1,4 +1,5 @@ import { Flag } from '@oclif/core/lib/interfaces' +import { ParsingToken } from '@oclif/core/lib/interfaces/parser' import { Parser } from '@oclif/core/lib/parser/parse' type FlagSpec =Pick, 'type' | 'default'> @@ -34,3 +35,5 @@ export const parseFlags = async (def: T, argv: string[]) => (await }).parse()).flags export type ParsedFlags = Omit>>, 'json'> + +export const argsFromRaw = (raw: ParsingToken[]) => raw.filter(arg => arg.type === 'arg').map(arg => arg.input).filter(Boolean) diff --git a/packages/cli/src/commands/logs.ts b/packages/cli/src/commands/logs.ts index c3f28cb9..cf815bb6 100644 --- a/packages/cli/src/commands/logs.ts +++ b/packages/cli/src/commands/logs.ts @@ -5,6 +5,7 @@ import { localComposeClient, wrapWithDockerSocket, findEnvId, MachineConnection, ComposeModel, remoteUserModel, } from '@preevy/core' import { COMPOSE_TUNNEL_AGENT_SERVICE_NAME } from '@preevy/common' +import { argsFromRaw } from '@preevy/cli-common' import DriverCommand from '../driver-command' import { envIdFlags } from '../common-flags' @@ -80,7 +81,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 = 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..a22ec0d2 100644 --- a/packages/cli/src/commands/shell.ts +++ b/packages/cli/src/commands/shell.ts @@ -1,5 +1,6 @@ import { Args } from '@oclif/core' import { commands } from '@preevy/core' +import { argsFromRaw } from '@preevy/cli-common' import DriverCommand from '../driver-command' // eslint-disable-next-line no-use-before-define @@ -23,7 +24,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 = 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..932d22a5 100644 --- a/packages/cli/src/commands/up.ts +++ b/packages/cli/src/commands/up.ts @@ -7,7 +7,7 @@ import { telemetryEmitter, withSpinner, } from '@preevy/core' -import { tunnelServerFlags } from '@preevy/cli-common' +import { argsFromRaw, tunnelServerFlags } from '@preevy/cli-common' import { inspect } from 'util' import { editUrl, tunnelNameResolver } from '@preevy/common' import MachineCreationDriverCommand from '../machine-creation-driver-command' @@ -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 = argsFromRaw(raw) + this.log('restArgs', restArgs) const driver = await this.driver() const machineCreationDriver = await this.machineCreationDriver()