Skip to content

Commit

Permalink
fix: display help before detect agent (#111)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
smallnine9 and antfu committed Oct 26, 2022
1 parent f502149 commit a2f9577
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
22 changes: 0 additions & 22 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-console */
import c from 'kleur'
import { version } from '../package.json'
import type { Agent, Command } from './agents'
import { AGENTS } from './agents'
import { exclude } from './utils'
Expand All @@ -25,25 +22,6 @@ export function getCommand(
}

export const parseNi = <Runner>((agent, args, ctx) => {
if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) {
console.log(`@antfu/ni v${version}`)
process.exit(0)
}

if (args.length === 1 && (args[0] === '--help' || args[0] === '-h')) {
const dash = c.dim('-')
console.log(c.green(c.bold('ni')) + c.dim(' use the right package manager\n'))
console.log(`ni ${dash} install`)
console.log(`nr ${dash} run`)
console.log(`nx ${dash} execute`)
console.log(`nu ${dash} upgrade`)
console.log(`nun ${dash} uninstall`)
console.log(`nci ${dash} clean install`)
console.log(`na ${dash} agent alias`)
console.log(c.yellow('\ncheck https://github.com/antfu/ni for more documentation.'))
process.exit(0)
}

// bun use `-d` instead of `-D`, #90
if (agent === 'bun')
args = args.map(i => i === '-D' ? '-d' : i)
Expand Down
23 changes: 22 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable no-console */
import { resolve } from 'path'
import prompts from 'prompts'
import { execaCommand } from 'execa'
import c from 'kleur'
import { version } from '../package.json'
import type { Agent } from './agents'
import { agents } from './agents'
import { getDefaultAgent, getGlobalAgent } from './config'
Expand Down Expand Up @@ -35,6 +38,25 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
let cwd = process.cwd()
let command

if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) {
console.log(`@antfu/ni v${version}`)
return
}

if (args.length === 1 && ['-h', '--help'].includes(args[0])) {
const dash = c.dim('-')
console.log(c.green(c.bold('@antfu/ni')) + c.dim(` use the right package manager v${version}\n`))
console.log(`ni ${dash} install`)
console.log(`nr ${dash} run`)
console.log(`nx ${dash} execute`)
console.log(`nu ${dash} upgrade`)
console.log(`nun ${dash} uninstall`)
console.log(`nci ${dash} clean install`)
console.log(`na ${dash} agent alias`)
console.log(c.yellow('\ncheck https://github.com/antfu/ni for more documentation.'))
return
}

if (args[0] === '-C') {
cwd = resolve(cwd, args[1])
args.splice(0, 2)
Expand Down Expand Up @@ -70,7 +92,6 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
command = voltaPrefix.concat(' ').concat(command)

if (debug) {
// eslint-disable-next-line no-console
console.log(command)
return
}
Expand Down

0 comments on commit a2f9577

Please sign in to comment.