cli 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env node
  2. const { spawnSync } = require('child_process');
  3. const commands = {
  4. migrate: {
  5. description: 'Run migrations to update to the latest major SDK version',
  6. fn: () => {
  7. const result = spawnSync(
  8. 'npx',
  9. [
  10. '-y',
  11. 'https://github.com/stainless-api/migrate-ts/releases/download/0.0.3/stainless-api-migrate-0.0.3.tgz',
  12. '--migrationConfig',
  13. require.resolve('./migration-config.json'),
  14. ...process.argv.slice(3),
  15. ],
  16. { stdio: 'inherit' },
  17. );
  18. if (result.status !== 0) {
  19. process.exit(result.status);
  20. }
  21. },
  22. },
  23. };
  24. function exitWithHelp() {
  25. console.log(`Usage: openai <subcommand>`);
  26. console.log();
  27. console.log('Subcommands:');
  28. for (const [name, info] of Object.entries(commands)) {
  29. console.log(` ${name} ${info.description}`);
  30. }
  31. console.log();
  32. process.exit(1);
  33. }
  34. if (process.argv.length < 3) {
  35. exitWithHelp();
  36. }
  37. const commandName = process.argv[2];
  38. const command = commands[commandName];
  39. if (!command) {
  40. console.log(`Unknown subcommand ${commandName}.`);
  41. exitWithHelp();
  42. }
  43. command.fn();