index.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bun
  2. import { install } from './install';
  3. import type { BooleanArg, InstallArgs } from './types';
  4. function parseArgs(args: string[]): InstallArgs {
  5. const result: InstallArgs = {
  6. tui: true,
  7. skills: 'yes',
  8. };
  9. for (const arg of args) {
  10. if (arg === '--no-tui') {
  11. result.tui = false;
  12. } else if (arg.startsWith('--skills=')) {
  13. result.skills = arg.split('=')[1] as BooleanArg;
  14. } else if (arg === '--dry-run') {
  15. result.dryRun = true;
  16. } else if (arg === '--reset') {
  17. result.reset = true;
  18. } else if (arg === '-h' || arg === '--help') {
  19. printHelp();
  20. process.exit(0);
  21. }
  22. }
  23. return result;
  24. }
  25. function printHelp(): void {
  26. console.log(`
  27. oh-my-opencode-slim installer
  28. Usage: bunx oh-my-opencode-slim install [OPTIONS]
  29. Options:
  30. --skills=yes|no Install recommended and bundled skills (default: yes)
  31. --no-tui Non-interactive mode
  32. --dry-run Simulate install without writing files
  33. --reset Force overwrite of existing configuration
  34. -h, --help Show this help message
  35. The installer generates an OpenAI configuration by default.
  36. For the full config reference, see docs/configuration.md.
  37. Examples:
  38. bunx oh-my-opencode-slim install
  39. bunx oh-my-opencode-slim install --no-tui --skills=yes
  40. bunx oh-my-opencode-slim install --reset
  41. `);
  42. }
  43. async function main(): Promise<void> {
  44. const args = process.argv.slice(2);
  45. if (args.length === 0 || args[0] === 'install') {
  46. const hasSubcommand = args[0] === 'install';
  47. const installArgs = parseArgs(args.slice(hasSubcommand ? 1 : 0));
  48. const exitCode = await install(installArgs);
  49. process.exit(exitCode);
  50. } else if (args[0] === '-h' || args[0] === '--help') {
  51. printHelp();
  52. process.exit(0);
  53. } else {
  54. console.error(`Unknown command: ${args[0]}`);
  55. console.error('Run with --help for usage information');
  56. process.exit(1);
  57. }
  58. }
  59. main().catch((err) => {
  60. console.error('Fatal error:', err);
  61. process.exit(1);
  62. });