@xuanqikai/one-click-upload
Version:
A CLI tool for one-click file upload to cloud storage services (OSS, TOS)
65 lines • 2.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const commander_1 = require("commander");
const ConfigCommand_1 = require("./commands/ConfigCommand");
const UploadCommand_1 = require("./commands/UploadCommand");
const program = new commander_1.Command();
// 设置程序信息
program
.name('one-upload')
.description('A CLI tool for one-click file upload to cloud storage services (OSS, TOS)')
.version('1.0.3');
// 添加配置管理命令
const configCommand = new ConfigCommand_1.ConfigCommand();
program.addCommand(configCommand.getCommand());
// 添加上传命令
const uploadCommand = new UploadCommand_1.UploadCommand();
program.addCommand(uploadCommand.getCommand());
// 添加快捷上传命令(主命令)
program
.argument('[local-path]', 'Local file or directory path to upload')
.argument('[remote-path]', 'Remote path in the storage service')
.option('-s, --service <name>', 'Service name to use for upload')
.option('-o, --overwrite', 'Overwrite existing files', false)
.option('-r, --resume', 'Enable resume upload for large files', true)
.option('--max-retries <number>', 'Maximum retry attempts', '3')
.option('--chunk-size <size>', 'Chunk size for multipart upload (in MB)', '1')
.option('--contents-only', 'Upload folder contents only (without folder name)')
.option('--cache-control <value>', 'Custom cache control header (e.g., "no-cache")')
.action(async (localPath, remotePath, options) => {
if (!localPath) {
// 如果没有提供参数,显示交互式上传界面
await uploadCommand.interactiveUpload();
}
else {
// 直接上传
await uploadCommand.directUpload(localPath, remotePath, options);
}
});
// 错误处理
program.exitOverride();
try {
program.parse();
}
catch (error) {
if (error.code === 'commander.help') {
process.exit(0);
}
else if (error.code === 'commander.version') {
process.exit(0);
}
else {
console.error(chalk_1.default.red('Error:'), error.message);
process.exit(1);
}
}
// 如果没有提供任何参数,显示帮助信息
if (process.argv.length === 2) {
program.help();
}
//# sourceMappingURL=cli.js.map