Skip to content

Commit

Permalink
fix: empty args
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Nov 27, 2023
1 parent 67fa29e commit 8c89e44
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/cli-common/src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -117,6 +118,11 @@ abstract class BaseCommand<T extends typeof Command=typeof Command> 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
2 changes: 1 addition & 1 deletion packages/cli-common/src/hooks/init/load-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class Logs extends DriverCommand<typeof Logs> {
async run(): Promise<void> {
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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Shell extends DriverCommand<typeof Shell> {
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,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default class Up extends MachineCreationDriverCommand<typeof Up> {

async run(): Promise<unknown> {
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()
Expand Down

0 comments on commit 8c89e44

Please sign in to comment.