update
This commit is contained in:
@@ -7,7 +7,7 @@ import os from 'node:os'
|
||||
import fs from 'node:fs';
|
||||
import { select } from '@inquirer/prompts';
|
||||
|
||||
const MODELS = ['minimax', 'glm'] as const;
|
||||
const MODELS = ['minimax', 'glm', 'volcengine'] as const;
|
||||
type Model = typeof MODELS[number];
|
||||
|
||||
const changeMinimax = (token?: string) => {
|
||||
@@ -39,6 +39,21 @@ const changeGLM = (token?: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const changeVolcengine = (token?: string) => {
|
||||
const auth_token = token || useKey('VOLCENGINE_API_KEY')
|
||||
return {
|
||||
"env": {
|
||||
"ANTHROPIC_AUTH_TOKEN": auth_token,
|
||||
"ANTHROPIC_BASE_URL": "https://ark.cn-beijing.volces.com/api/coding",
|
||||
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "ark-code-latest",
|
||||
"ANTHROPIC_DEFAULT_OPUS_MODEL": "ark-code-latest",
|
||||
"ANTHROPIC_DEFAULT_SONNET_MODEL": "ark-code-latest",
|
||||
"ANTHROPIC_MODEL": "ark-code-latest",
|
||||
"API_TIMEOUT_MS": "3000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳过登录检查,在~/.claude.json的配置中添加字段 "hasCompletedOnboarding": true
|
||||
*/
|
||||
@@ -67,6 +82,7 @@ const changeNoCheck = () => {
|
||||
const modelConfig: Record<Model, (token?: string) => object> = {
|
||||
minimax: changeMinimax,
|
||||
glm: changeGLM,
|
||||
volcengine: changeVolcengine,
|
||||
};
|
||||
|
||||
const readOrCreateConfig = (configPath: string): Record<string, unknown> => {
|
||||
@@ -86,7 +102,7 @@ const saveConfig = (configPath: string, config: Record<string, unknown>) => {
|
||||
};
|
||||
|
||||
export const command = new Command('cc')
|
||||
.description('切换claude code模型,支持GLM4.7和Minimax')
|
||||
.description('切换claude code模型,支持GLM4.7、Minimax和豆包')
|
||||
.option('-m, --models <model:string>', `选择模型: ${MODELS.join(' | ')}`)
|
||||
.action(async (options) => {
|
||||
const configPath = path.join(os.homedir(), '.claude/settings.json');
|
||||
|
||||
104
src/command/docker.ts
Normal file
104
src/command/docker.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { program, Command } from '@/program.ts';
|
||||
import { chalk } from '../module/chalk.ts';
|
||||
import path from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { useKey } from '@kevisual/use-config';
|
||||
import os from 'node:os'
|
||||
import fs from 'node:fs';
|
||||
import { select } from '@inquirer/prompts';
|
||||
|
||||
// 执行 docker指令
|
||||
// docker login --username=${DOCKER_USERNAME} ${DOCKER_REGISTRY} --password ${DOCKER_PASSWORD}
|
||||
// docker login -u cnb docker.cnb.cool --password ${CNB_TOKEN}
|
||||
// helm registry login -u cnb helm.cnb.cool --password ${CNB_TOKEN}
|
||||
|
||||
const dockerCommand = new Command('docker')
|
||||
.description('Docker 相关指令')
|
||||
.action(async () => {
|
||||
console.log(chalk.green('Docker command executed'));
|
||||
});
|
||||
|
||||
const login = new Command('login')
|
||||
.description('登录 Docker 镜像仓库')
|
||||
.option('-r , --registry <registry>', 'Docker 镜像仓库地址', 'default')
|
||||
.action(async (options) => {
|
||||
const { registry = 'default' } = options;
|
||||
let DOCKER_USERNAME = useKey('DOCKER_USERNAME') as string;
|
||||
let DOCKER_PASSWORD = useKey('DOCKER_PASSWORD') as string;
|
||||
let DOCKER_REGISTRY = useKey('DOCKER_REGISTRY') as string;
|
||||
if (registry !== 'default') {
|
||||
DOCKER_USERNAME = 'cnb';
|
||||
DOCKER_PASSWORD = useKey('CNB_TOKEN') as string;
|
||||
DOCKER_REGISTRY = 'docker.cnb.cool';
|
||||
}
|
||||
if (!DOCKER_USERNAME || !DOCKER_PASSWORD) {
|
||||
console.log(chalk.red('请先配置 DOCKER_USERNAME 和 DOCKER_PASSWORD'));
|
||||
return;
|
||||
}
|
||||
const loginProcess = spawn('docker', [
|
||||
'login',
|
||||
'--username',
|
||||
DOCKER_USERNAME,
|
||||
DOCKER_REGISTRY,
|
||||
'--password-stdin'
|
||||
], {
|
||||
stdio: ['pipe', 'inherit', 'inherit']
|
||||
});
|
||||
|
||||
loginProcess.stdin.write(DOCKER_PASSWORD + '\n');
|
||||
loginProcess.stdin.end();
|
||||
|
||||
loginProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(chalk.green('登录成功'));
|
||||
} else {
|
||||
console.log(chalk.red(`登录失败,退出码:${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
dockerCommand.addCommand(login);
|
||||
|
||||
const helmLogin = new Command('helm')
|
||||
.description('Helm 登录镜像仓库')
|
||||
.action(async () => {
|
||||
});
|
||||
|
||||
const helmLoginCommand = new Command('login')
|
||||
.description('登录 Helm 镜像仓库')
|
||||
.action(async () => {
|
||||
let DOCKER_USERNAME = 'cnb';
|
||||
let DOCKER_PASSWORD = useKey('CNB_TOKEN') as string;
|
||||
|
||||
if (!DOCKER_PASSWORD) {
|
||||
console.log(chalk.red('请先配置 CNB_TOKEN'));
|
||||
return;
|
||||
}
|
||||
|
||||
const helmLoginProcess = spawn('helm', [
|
||||
'registry',
|
||||
'login',
|
||||
'--username',
|
||||
DOCKER_USERNAME,
|
||||
'--password-stdin',
|
||||
'helm.cnb.cool'
|
||||
], {
|
||||
stdio: ['pipe', 'inherit', 'inherit']
|
||||
});
|
||||
|
||||
helmLoginProcess.stdin.write(DOCKER_PASSWORD + '\n');
|
||||
helmLoginProcess.stdin.end();
|
||||
|
||||
helmLoginProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(chalk.green('Helm 登录成功'));
|
||||
} else {
|
||||
console.log(chalk.red(`Helm 登录失败,退出码:${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
helmLogin.addCommand(helmLoginCommand);
|
||||
|
||||
program.addCommand(dockerCommand);
|
||||
program.addCommand(helmLogin);
|
||||
@@ -18,6 +18,7 @@ import './command/config-remote.ts';
|
||||
import './command/config-secret-remote.ts';
|
||||
import './command/ai.ts';
|
||||
import './command/cc.ts'
|
||||
import './command/docker.ts';
|
||||
// program.parse(process.argv);
|
||||
|
||||
export const runParser = async (argv: string[]) => {
|
||||
|
||||
Reference in New Issue
Block a user