Skip to content

Commit

Permalink
add pi bn swich mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TickHeart committed Oct 18, 2022
1 parent ec7d6f4 commit a51866b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/argv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import minimist from 'minimist'

const cmds = {
export const cmds = {
yarn: '-Y|--yarn',
pnpm: '-P|--pnpm',
npm: '-N|--npm',
Expand All @@ -15,7 +15,7 @@ export function selectorPackage(argv: string[]) {
return [cmd, argv]
}

function detectionInstruction(argv: string[]) {
export function detectionInstruction(argv: string[]) {
const param = getArguments(argv)
const pnpmAlias = cmds.pnpm.split('|')
const yarnAlias = cmds.yarn.split('|')
Expand Down
14 changes: 14 additions & 0 deletions src/branch/bn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AGENTS_KEYS } from '../agents'
import { detectionInstruction } from '../argv'
import { brain } from '../brain'

export async function bn(argvs: string[], config: {
skipVersionTesting: boolean
piBranchPath: string | null
}) {
const piBrain = await brain(config)
const cmd = detectionInstruction(argvs)
piBrain.addMemory(cmd as AGENTS_KEYS)

return true
}
2 changes: 2 additions & 0 deletions src/branch/branch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { log } from 'console'
import pkg from '../../package.json'
import { brainView } from '../brain/view'
import { bn } from './bn'
import { list } from './list'
import { sc } from './sc'
import setConfig, { getConfigFileBody } from './setConfig'
Expand All @@ -22,4 +23,5 @@ export const piBranch: Record<string, BranchFn> = {
'brain': brainView,
sc,
'-u': u,
'bn': bn,
}
9 changes: 6 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ const log = console.log
type Parser = (cmd: 'pnpm' | 'yarn' | 'npm', args?: string[]) => string

// parse list command
const parseLineFlag = async () => {
const parseLineFlag = async (config: {
skipVersionTesting: boolean
piBranchPath: string | null
}) => {
const args = process.argv.slice(2)
if (args[0] in piBranch) {
await piBranch[args[0] as keyof typeof piBranch](args)
await piBranch[args[0] as keyof typeof piBranch](args, config)
return true
}
return false
Expand All @@ -28,7 +31,7 @@ const parseLineFlag = async () => {
export async function run(parser: Parser) {
const config = await resolveConfig()
await localDetection(config)
if (await parseLineFlag())
if (await parseLineFlag(config))
return
const piBrain = await brain(config)
const [_cmd, args] = selectorPackage(process.argv.slice(2))
Expand Down

0 comments on commit a51866b

Please sign in to comment.