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 28, 2023
1 parent 67fa29e commit a1f20bd
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 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
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-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
3 changes: 3 additions & 0 deletions packages/cli-common/src/lib/flags.ts
Original file line number Diff line number Diff line change
@@ -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<T> =Pick<Flag<T>, 'type' | 'default'>
Expand Down Expand Up @@ -34,3 +35,5 @@ export const parseFlags = async <T extends {}>(def: T, argv: string[]) => (await
}).parse()).flags

export type ParsedFlags<T extends {}> = Omit<Awaited<ReturnType<typeof parseFlags<T>>>, 'json'>

export const argsFromRaw = (raw: ParsingToken[]) => raw.filter(arg => arg.type === 'arg').map(arg => arg.input).filter(Boolean)
3 changes: 2 additions & 1 deletion packages/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -80,7 +81,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 = argsFromRaw(raw)

let connection: MachineConnection
let userModel: ComposeModel
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +24,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 = argsFromRaw(raw).slice(1)

const result = await commands.shell({
envId: args.envId,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down 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 = argsFromRaw(raw)
this.log('restArgs', restArgs)

const driver = await this.driver()
const machineCreationDriver = await this.machineCreationDriver()
Expand Down

0 comments on commit a1f20bd

Please sign in to comment.