//!wrt $BSPEC:{"icn":null,"cpr":"Copyright (C) Windows 96 Team 2021.","dsc":"","frn":"<Unknown>","ver":1,"ssy":"cli"}

const{WRT:WRT}=w96,term=this.boxedEnv.term,cwd=this.cwd;if(!term)return 1;class WJSApplication extends WApplication{constructor(){super()}async main(args){if(super.main(args),args.includes("--help"))return term.println("usage: wjs <path> [--no-term] [--no-wrt]\nRuns a JS file in WRT (the Windows 96 JavaScript runtime).\n\nIf --no-wrt is specified, the file will be evaluated in normal JS instead.\nIf --no-term is specified, the WRT application will not know that it is running in a terminal."),0;let pathArg=args[1];if(""==pathArg||null==pathArg)return term.printError("wjs: 'wjs' requires a file path argument (none specified)."),1;if(/^([a-zA-Z]:)/.test(pathArg)||(pathArg=FSUtil.resolvePath(cwd,pathArg)),!await FS.exists(pathArg))return term.printError(`wjs: unable to access '${pathArg}': No such file or directory.`),1;if(!await FS.isFile(pathArg))return term.printError("wjs: invalid argument."),1;try{args.includes("--no-wrt")?eval(await FS.readstr(pathArg)):await WRT.runFile(pathArg,{boxedEnv:args.includes("--no-term")?null:{term:term,cwd:cwd},envType:"terminal"})}catch(r){term.printError(r)}}}

return await WApplication.execAsync(new WJSApplication(), this.boxedEnv.args, this);