From e0877e20346bd7f7f29dbf7e0cabd2c45342747e Mon Sep 17 00:00:00 2001 From: zetaloop Date: Wed, 8 May 2024 23:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E5=B7=A5=E5=85=B7gi?= =?UTF-8?q?thub...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit windows中文时自动切换utf8编码,防止乱码 --- app/src/cli/commands/clone.ts | 13 +++++++------ app/src/cli/commands/help.ts | 36 +++++++++++++++++++++++------------ app/src/cli/commands/open.ts | 16 ++++++++-------- app/src/cli/main.ts | 6 ++++++ 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/app/src/cli/commands/clone.ts b/app/src/cli/commands/clone.ts index 012c0531b7..1c025c0b51 100644 --- a/app/src/cli/commands/clone.ts +++ b/app/src/cli/commands/clone.ts @@ -10,13 +10,14 @@ interface ICloneArgs extends mriArgv { } export const command: ICommandModule = { - command: 'clone ', - description: 'Clone a repository', + command: 'clone <网址|标识符>', + description: '克隆一个储存库', args: [ { - name: 'url|slug', + name: '网址|标识符', required: true, - description: 'The URL or the GitHub owner/name alias to clone', + description: + '储存库的 URL 地址,或者 GitHub "用户/储存库名" 格式的标识符', type: 'string', }, ], @@ -24,12 +25,12 @@ export const command: ICommandModule = { branch: { type: 'string', aliases: ['b'], - description: 'The branch to checkout after cloning', + description: '克隆完成后要检出的分支', }, }, handler({ _: [cloneUrl], branch }: ICloneArgs) { if (!cloneUrl) { - throw new CommandError('Clone URL must be specified') + throw new CommandError('必须指定克隆地址') } try { const _ = new URL(cloneUrl) diff --git a/app/src/cli/commands/help.ts b/app/src/cli/commands/help.ts index 5396000901..e295e7df54 100644 --- a/app/src/cli/commands/help.ts +++ b/app/src/cli/commands/help.ts @@ -5,8 +5,8 @@ import { commands, ICommandModule, IOption } from '../load-commands' import { dasherizeOption, printTable } from '../util' export const command: ICommandModule = { - command: 'help [command]', - description: 'Show the help page for a command', + command: 'help [命令]', + description: '显示命令的帮助页面', handler({ _: [command] }) { if (command) { printCommandHelp(command, commands[command]) @@ -17,7 +17,7 @@ export const command: ICommandModule = { } function printHelp() { - console.log(chalk.underline('Commands:')) + console.log(chalk.underline('命令:')) const table: string[][] = [] for (const commandName of Object.keys(commands)) { const command = commands[commandName] @@ -25,15 +25,27 @@ function printHelp() { } printTable(table) console.log( - `\nRun ${chalk.bold( - `github help ${chalk.gray('')}` - )} for details about each command` + `\n运行 ${chalk.bold( + `github help ${chalk.gray('<命令>')}` + )} 查看各个命令的详细帮助信息` + // )} for details about each command` ) } +function typeTranslator(type: string) { + switch (type) { + case 'string': + return '字符串' + case 'boolean': + return '布尔值' + default: + return type + } +} + function printCommandHelp(name: string, command: ICommandModule) { if (!command) { - console.log(`Unrecognized command: ${chalk.bold.red.underline(name)}`) + console.log(`未知命令: ${chalk.bold.red.underline(name)}`) printHelp() return } @@ -51,7 +63,7 @@ function printCommandHelp(name: string, command: ICommandModule) { } const { options, args } = command if (options) { - console.log(chalk.underline('\nOptions:')) + console.log(chalk.underline('\n选项:')) printTable( Object.keys(options) .map(k => [k, options[k]] as [string, IOption]) @@ -61,18 +73,18 @@ function printCommandHelp(name: string, command: ICommandModule) { .map(x => chalk.bold.blue(x)) .join(chalk.gray(', ')), option.description, - chalk.gray(`[${chalk.underline(option.type)}]`), + chalk.gray(`[${chalk.underline(typeTranslator(option.type))}]`), ]) ) } if (args && args.length) { - console.log(chalk.underline('\nArguments:')) + console.log(chalk.underline('\n参数:')) printTable( args.map(arg => [ (arg.required ? chalk.bold : chalk).blue(arg.name), - arg.required ? chalk.gray('(required)') : '', + arg.required ? chalk.gray('(必填)') : '', arg.description, - chalk.gray(`[${chalk.underline(arg.type)}]`), + chalk.gray(`[${chalk.underline(typeTranslator(arg.type))}]`), ]) ) } diff --git a/app/src/cli/commands/open.ts b/app/src/cli/commands/open.ts index b5c58d19f6..0c9e77d3eb 100644 --- a/app/src/cli/commands/open.ts +++ b/app/src/cli/commands/open.ts @@ -6,13 +6,13 @@ import { openDesktop } from '../open-desktop' import { parseRemote } from '../../lib/remote-parsing' export const command: ICommandModule = { - command: 'open ', - aliases: [''], - description: 'Open a git repository in GitHub Desktop', + command: 'open <路径>', + aliases: ['<路径>'], + description: '用 GitHub Desktop 打开一个 git 储存库', args: [ { - name: 'path', - description: 'The path to the repository to open', + name: '路径', + description: '储存库文件夹路径', type: 'string', required: false, }, @@ -26,9 +26,9 @@ export const command: ICommandModule = { //Check if the pathArg is a remote url if (parseRemote(pathArg) != null) { console.log( - `\nYou cannot open a remote URL in GitHub Desktop\n` + - `Use \`${chalk.bold(`git clone ` + pathArg)}\`` + - ` instead to initiate the clone` + `\n无法直接打开远程地址\n` + + `请先使用 \`${chalk.bold(`git clone ` + pathArg)}\`` + + ` 来克隆它` ) } else { const repositoryPath = Path.resolve(process.cwd(), pathArg) diff --git a/app/src/cli/main.ts b/app/src/cli/main.ts index c9525da9b0..fae8d3f32b 100644 --- a/app/src/cli/main.ts +++ b/app/src/cli/main.ts @@ -20,6 +20,12 @@ const supportsCommand = (name: string) => Object.hasOwn(commands, name) ;(function attemptRun(name: string) { try { + if (__WIN32__) { + // Solve Chinese garbled problem on Windows + const { execSync } = require('child_process') + execSync('chcp 65001') + } + if (supportsCommand(name)) { runCommand(name) } else if (name.startsWith('--')) {