Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display help before detect agent #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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