GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。 NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは 別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
84 lines
2.2 KiB
JavaScript
84 lines
2.2 KiB
JavaScript
const lightsailClient = require('../src/lightsailClient');
|
|
|
|
function parseArgs(argv) {
|
|
const SUBCOMMANDED = new Set(['snapshot']);
|
|
const [command, ...rest] = argv;
|
|
|
|
if (SUBCOMMANDED.has(command)) {
|
|
const [subcommand, ...subRest] = rest;
|
|
return { command, subcommand, args: subRest, options: {} };
|
|
}
|
|
|
|
const args = [];
|
|
const options = {};
|
|
for (let i = 0; i < rest.length; i += 1) {
|
|
const token = rest[i];
|
|
if (token.startsWith('--')) {
|
|
const key = token.slice(2);
|
|
options[key] = rest[i + 1];
|
|
i += 1;
|
|
} else {
|
|
args.push(token);
|
|
}
|
|
}
|
|
return { command, subcommand: null, args, options };
|
|
}
|
|
|
|
async function dispatch(parsed, clientModule) {
|
|
const { command, subcommand, args, options } = parsed;
|
|
|
|
if (command === 'list') {
|
|
return clientModule.listInstances();
|
|
}
|
|
if (command === 'status') {
|
|
return clientModule.getInstance(args[0]);
|
|
}
|
|
if (command === 'create') {
|
|
return clientModule.createInstance({
|
|
instanceName: args[0],
|
|
bundleId: options.bundle,
|
|
blueprintId: options.blueprint,
|
|
availabilityZone: options.az,
|
|
});
|
|
}
|
|
if (command === 'delete') {
|
|
return clientModule.deleteInstance(args[0]);
|
|
}
|
|
if (command === 'start') {
|
|
return clientModule.startInstance(args[0]);
|
|
}
|
|
if (command === 'stop') {
|
|
return clientModule.stopInstance(args[0]);
|
|
}
|
|
if (command === 'reboot') {
|
|
return clientModule.rebootInstance(args[0]);
|
|
}
|
|
if (command === 'snapshot' && subcommand === 'create') {
|
|
return clientModule.createSnapshot(args[0], args[1]);
|
|
}
|
|
if (command === 'snapshot' && subcommand === 'list') {
|
|
return clientModule.listSnapshots();
|
|
}
|
|
if (command === 'snapshot' && subcommand === 'delete') {
|
|
return clientModule.deleteSnapshot(args[0]);
|
|
}
|
|
|
|
throw new Error(`Unknown command: ${command}`);
|
|
}
|
|
|
|
async function main() {
|
|
console.error(`[lightsail-cli] region=${process.env.AWS_REGION || '(unset)'}`);
|
|
const parsed = parseArgs(process.argv.slice(2));
|
|
const result = await dispatch(parsed, lightsailClient);
|
|
console.log(JSON.stringify(result, null, 2));
|
|
}
|
|
|
|
if (require.main === module) {
|
|
main().catch((err) => {
|
|
console.error(`${err.name || 'Error'}: ${err.message}`);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
module.exports = { parseArgs, dispatch };
|