11#!/usr/bin/env node
22
3+ import path from 'path' ;
4+ import fs from 'fs' ;
35import { intro , checkExistingSetup , detectProject , promptAgents , promptSkills , promptModels , promptMcp , promptMcpSearch , promptCostControl , generateFiles , promptAgentsMd , outro , launchOpenCode } from './setup.js' ;
46
5- const args = process . argv . slice ( 2 ) ;
7+ // ── Parse flags ─────────────────────────────────────────────────────────────
8+
9+ const rawArgs = process . argv . slice ( 2 ) ;
10+ const flags = { } ;
11+ const positional = [ ] ;
12+
13+ for ( let i = 0 ; i < rawArgs . length ; i ++ ) {
14+ const arg = rawArgs [ i ] ;
15+ if ( arg === '--skipSSL' || arg === '--skip-ssl' ) {
16+ flags . skipSSL = true ;
17+ } else if ( arg === '--config' && rawArgs [ i + 1 ] ) {
18+ flags . configPath = path . resolve ( rawArgs [ ++ i ] ) ;
19+ } else if ( arg === '--crt' && rawArgs [ i + 1 ] ) {
20+ flags . crtPath = path . resolve ( rawArgs [ ++ i ] ) ;
21+ } else if ( arg === '--help' || arg === '-h' ) {
22+ flags . help = true ;
23+ } else {
24+ positional . push ( arg ) ;
25+ }
26+ }
27+
28+ const command = positional [ 0 ] || '' ;
29+ const subcommand = positional [ 1 ] || '' ;
30+
31+ // ── Apply flags ─────────────────────────────────────────────────────────────
632
7- // ── Handle --skipSSL flag (can appear anywhere in args) ───────────────────
8- if ( args . includes ( '--skipSSL' ) || args . includes ( '--skip-ssl' ) ) {
33+ if ( flags . skipSSL ) {
934 process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
1035}
1136
12- const filteredArgs = args . filter ( a => a !== '--skipSSL' && a !== '--skip-ssl' ) ;
13- const command = filteredArgs [ 0 ] || '' ;
14- const subcommand = filteredArgs [ 1 ] || '' ;
37+ if ( flags . crtPath ) {
38+ if ( ! fs . existsSync ( flags . crtPath ) ) {
39+ console . error ( `Error: Certificate file not found: ${ flags . crtPath } ` ) ;
40+ process . exit ( 1 ) ;
41+ }
42+ process . env . NODE_EXTRA_CA_CERTS = flags . crtPath ;
43+ }
44+
45+ if ( flags . configPath ) {
46+ if ( ! fs . existsSync ( flags . configPath ) ) {
47+ console . error ( `Error: Config file not found: ${ flags . configPath } ` ) ;
48+ process . exit ( 1 ) ;
49+ }
50+ }
51+
52+ // ── Main ────────────────────────────────────────────────────────────────────
1553
1654async function main ( ) {
1755 try {
18- // ── Handle --help / -h ────────────────────────────────────────────────
19- if ( command === '--help' || command === '-h' ) {
56+ if ( flags . help ) {
2057 showHelp ( ) ;
2158 return ;
2259 }
2360
24- // ── Handle subcommands ────────────────────────────────────────────────
2561 if ( command === 'configure' ) {
2662 intro ( ) ;
2763 await handleConfigure ( subcommand ) ;
2864 return ;
2965 }
3066
31- // ── Default: full setup or re-run ─────────────────────────────────────
3267 intro ( ) ;
3368
3469 const existing = checkExistingSetup ( ) ;
@@ -59,17 +94,22 @@ function showHelp() {
5994 awesome-opencode configure skills Add/remove skills
6095 awesome-opencode configure models Change model strategy
6196 awesome-opencode configure mcp Add/remove MCP servers
62- awesome-opencode --help Show this help
6397
6498 Flags:
65- --skipSSL Set NODE_TLS_REJECT_UNAUTHORIZED=0
66- (useful behind corporate proxies)
99+ --help, -h Show this help
100+ --config <path> Path to external opencode.json
101+ (default: ./opencode.json)
102+ --crt <path> Path to custom CA certificate (.crt/.pem)
103+ Sets NODE_EXTRA_CA_CERTS for TLS
104+ --skipSSL Disable TLS certificate verification
105+ Sets NODE_TLS_REJECT_UNAUTHORIZED=0
67106
68107 Examples:
69108 npx @weisser-dev/awesome-opencode
70- awesome-opencode configure mcp
71- awesome-opencode --skipSSL
109+ awesome-opencode --config ~/shared/opencode.json
110+ awesome-opencode --crt /etc/ssl/corporate-ca.crt
72111 awesome-opencode --skipSSL configure models
112+ awesome-opencode --config /mnt/config/opencode.json --crt /mnt/certs/ca.pem
73113
74114 Docs: https://github.com/weisser-dev/awesome-opencode
75115` ) ;
@@ -93,6 +133,15 @@ async function handleExistingSetup(existing) {
93133 if ( existing . modelStrategy ) {
94134 console . log ( chalk . gray ( ` Models: ${ existing . modelStrategy } ` ) ) ;
95135 }
136+ if ( flags . configPath ) {
137+ console . log ( chalk . gray ( ` Config: ${ flags . configPath } ` ) ) ;
138+ }
139+ if ( flags . crtPath ) {
140+ console . log ( chalk . gray ( ` CA cert: ${ flags . crtPath } ` ) ) ;
141+ }
142+ if ( flags . skipSSL ) {
143+ console . log ( chalk . yellow ( ' SSL: verification disabled (--skipSSL)' ) ) ;
144+ }
96145 console . log ( '' ) ;
97146
98147 // Check if Docker is available for sandboxed option
@@ -124,10 +173,10 @@ async function handleExistingSetup(existing) {
124173
125174 switch ( action ) {
126175 case 'start' :
127- await launchOpenCode ( { forceSandbox : false } ) ;
176+ await launchOpenCode ( { forceSandbox : false , flags } ) ;
128177 break ;
129178 case 'sandbox' :
130- await launchOpenCode ( { forceSandbox : true } ) ;
179+ await launchOpenCode ( { forceSandbox : true , flags } ) ;
131180 break ;
132181 case 'reconfigure' :
133182 await runFullSetup ( ) ;
@@ -149,7 +198,7 @@ async function handleExistingSetup(existing) {
149198}
150199
151200async function handleConfigure ( what ) {
152- const project = await detectProject ( ) ;
201+ const project = await detectProject ( { configPath : flags . configPath } ) ;
153202
154203 switch ( what ) {
155204 case 'agents' : {
@@ -175,7 +224,6 @@ async function handleConfigure(what) {
175224 break ;
176225 }
177226 default : {
178- // No subcommand: full reconfigure
179227 await runFullSetup ( ) ;
180228 }
181229 }
@@ -184,22 +232,20 @@ async function handleConfigure(what) {
184232}
185233
186234async function runFullSetup ( ) {
187- const project = await detectProject ( ) ;
235+ const project = await detectProject ( { configPath : flags . configPath } ) ;
188236 const agents = await promptAgents ( project ) ;
189237 const skills = await promptSkills ( project ) ;
190238 const modelConfig = await promptModels ( project ) ;
191239
192- // MCP: curated list + optional mcp.so search
193240 const mcpConfig = await promptMcp ( project ) ;
194241 const mcpSearchResults = await promptMcpSearch ( mcpConfig ) ;
195242
196- // Cost & context control: step limits per agent
197243 const costControl = await promptCostControl ( agents ) ;
198244
199245 await generateFiles ( { project, agents, skills, modelConfig, mcpConfig, mcpSearchResults, costControl } ) ;
200246 await promptAgentsMd ( { project, agents, skills, modelConfig } ) ;
201247 outro ( ) ;
202- await launchOpenCode ( ) ;
248+ await launchOpenCode ( { flags } ) ;
203249}
204250
205251main ( ) ;
0 commit comments