npm.io
1.0.19 • Published 5 months ago

@ynpx/ynpx-argv

Licence
ISC
Version
1.0.19
Deps
2
Size
46 kB
Vulns
0
Weekly
0
Stars
32

@ynpx/ynpx-argv

YNPX 命令列參數解析器,用於解析 ynpx 工具的命令列選項和參數。 Command line argument parser for YNPX tool, used to parse command line options and arguments.

安裝 (Installation)

# 使用 yarn / Using yarn
yarn add @ynpx/ynpx-argv

# 使用 yarn-tool / Using yarn-tool
yarn-tool add @ynpx/ynpx-argv

# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
yt add @ynpx/ynpx-argv

# 使用 pnpm / Using pnpm
pnpm add @ynpx/ynpx-argv

# 使用 npm / Using npm
npm install @ynpx/ynpx-argv

功能 (Features)

  • 解析 ynpx 命令列參數 / Parse YNPX command line arguments
  • 支援 -p/--package 多套件指定 / Support -p/--package multiple package specification
  • 自動處理 -- 分隔的額外參數 / Auto-handle -- separated extra arguments
  • 提供完整的 TypeScript 型別支援 / Full TypeScript type support

使用範例 (Usage Examples)

import parseArgv from '@ynpx/ynpx-argv';

// 基本使用 / Basic usage
const argv = parseArgv(['-p', 'lodash', 'mocha', '--', '-R', 'spec']);
console.log(argv.package); // ['lodash']
console.log(argv._);       // ['mocha']
console.log(argv['--']);   // ['-R', 'spec']

// 多套件指定 / Multiple packages
const argv2 = parseArgv(['-p', 'esm', '-p', 'ts-node', 'mocha']);
console.log(argv2.package); // ['esm', 'ts-node']

// 指定套件管理器 / Specify package manager
const argv3 = parseArgv(['--pm', 'pnpm', 'eslint']);
console.log(argv3.npmClient); // ['pnpm']

// 多個套件管理器 / Multiple package managers
const argv4 = parseArgv(['--npmClient', 'yarn', '--pm', 'pnpm', 'node']);
console.log(argv4.npmClient); // ['yarn', 'pnpm']

介面 (Interfaces)

IYPXArgumentsCore

核心參數介面,定義支援的所有選項: Core arguments interface defining all supported options:

選項 (Option) 類型 (Type) 說明 (Description)
package string[] 要安裝的套件列表 / List of packages to install
quiet boolean? 靜默模式 / Quiet mode
preferOffline boolean? 優先使用離線快取 / Prefer offline cache
cwd string? 工作目錄 / Working directory
ignoreExisting boolean? 忽略已存在檢查 / Skip existence check
noInstall boolean? 跳過安裝 / Skip installation
userconfig string? Yarn 設定檔路徑 / Yarn config file path
debugBin boolean? 除錯二進制模式 / Debug binary mode
debugMode boolean? 除錯模式 / Debug mode
npmClient string[]? 套件管理器列表(例如:npm、yarn、pnpm)/ Package manager list (e.g., npm, yarn, pnpm)

API

parseArgv(inputArgv: string[]): IYPXArguments

解析命令列參數並返回解析結果。 Parse command line arguments and return the parsed result.

parseArgvCore(inputArgv: string[]): Argv

建立並配置 yargs 實例,返回未解析的 yargs 物件。 Create and configure yargs instance, return the unparsed yargs object.

  • ynpx - 基於 Yarn 的 npx 替代工具 / Yarn-based npx alternative

Keywords