(args)
| 730 | * @param {string[]} args - Command-line arguments (process.argv.slice(2)) |
| 731 | */ |
| 732 | export function run(args) { |
| 733 | // --version / -v |
| 734 | if (args.includes('--version') || args.includes('-v')) { |
| 735 | printVersion(); |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | // --help / -h |
| 740 | if (args.includes('--help') || args.includes('-h')) { |
| 741 | printHelp(); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | // --dev guard: this only works from a cloned repository |
| 746 | if (args.includes('--dev')) { |
| 747 | die( |
| 748 | 'Dev mode requires a cloned repository.\n' + |
| 749 | ' Clone from https://github.com/paperlinguist/autocoder and run start_ui.sh' |
| 750 | ); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | // "config" subcommand |
| 755 | if (args[0] === 'config') { |
| 756 | handleConfig(args.slice(1)); |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | // Parse flags for server start |
| 761 | const host = getFlagValue(args, '--host') || '127.0.0.1'; |
| 762 | const portStr = getFlagValue(args, '--port'); |
| 763 | const port = portStr ? Number(portStr) : null; |
| 764 | const noBrowser = args.includes('--no-browser'); |
| 765 | const repair = args.includes('--repair'); |
| 766 | |
| 767 | if (port !== null && (!Number.isFinite(port) || port < 1 || port > 65535)) { |
| 768 | die('Invalid port number. Must be between 1 and 65535.'); |
| 769 | } |
| 770 | |
| 771 | // Print banner |
| 772 | console.log(''); |
| 773 | log(`AutoForge v${VERSION}`); |
| 774 | console.log(''); |
| 775 | |
| 776 | startServer({ port, host, noBrowser, repair }); |
| 777 | } |
| 778 | |
| 779 | // --------------------------------------------------------------------------- |
| 780 | // Argument parsing helpers |
no test coverage detected