Compare commits
No commits in common. "7d14ef173bf7f2bce3fe639ac020c747725d4d64" and "84001bf67f5da057ae0c81fc9d488e34fb889312" have entirely different histories.
7d14ef173b
...
84001bf67f
54
bin/shrimp
54
bin/shrimp
|
|
@ -12,21 +12,16 @@ import { join } from 'path'
|
||||||
function showHelp() {
|
function showHelp() {
|
||||||
console.log(`${colors.bright}${colors.magenta}🦐 Shrimp${colors.reset} is a scripting language in a shell.
|
console.log(`${colors.bright}${colors.magenta}🦐 Shrimp${colors.reset} is a scripting language in a shell.
|
||||||
|
|
||||||
${colors.bright}Usage:${colors.reset} shrimp <command> [options] [...args]
|
${colors.bright}Usage:${colors.reset} shrimp <command> [...args]
|
||||||
|
|
||||||
${colors.bright}Commands:${colors.reset}
|
${colors.bright}Commands:${colors.reset}
|
||||||
${colors.cyan}run ${colors.yellow}./my-file.sh${colors.reset} Execute a file with Shrimp
|
${colors.cyan}run ${colors.yellow}./my-file.sh${colors.reset} Execute a file with Shrimp
|
||||||
${colors.cyan}parse ${colors.yellow}./my-file.sh${colors.reset} Print parse tree for Shrimp file
|
${colors.cyan}parse ${colors.yellow}./my-file.sh${colors.reset} Print parse tree for Shrimp file
|
||||||
${colors.cyan}bytecode ${colors.yellow}./my-file.sh${colors.reset} Print bytecode for Shrimp file
|
${colors.cyan}bytecode ${colors.yellow}./my-file.sh${colors.reset} Print bytecode for Shrimp file
|
||||||
${colors.cyan}eval ${colors.yellow}'some code'${colors.reset} Evaluate a line of Shrimp code
|
${colors.cyan}eval ${colors.yellow}'some code'${colors.reset} Evaluate a line of Shrimp code
|
||||||
${colors.cyan}repl${colors.reset} Start REPL
|
${colors.cyan}repl${colors.reset} Start REPL
|
||||||
${colors.cyan}help${colors.reset} Print this help message
|
${colors.cyan}help${colors.reset} Print this help message
|
||||||
${colors.cyan}version${colors.reset} Print version
|
${colors.cyan}version${colors.reset} Print version`)
|
||||||
|
|
||||||
${colors.bright}Options:${colors.reset}
|
|
||||||
${colors.cyan}eval -I${colors.reset} ${colors.yellow}<module>${colors.reset} Import module (can be repeated)
|
|
||||||
Example: shrimp -I math -e 'random | echo'
|
|
||||||
Example: shrimp -Imath -Istr -e 'random | echo'`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVersion() {
|
function showVersion() {
|
||||||
|
|
@ -34,40 +29,7 @@ function showVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
let args = process.argv.slice(2)
|
const args = process.argv.slice(2)
|
||||||
|
|
||||||
if (args.length === 0) {
|
|
||||||
showHelp()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse -I flags for imports (supports both "-I math" and "-Imath")
|
|
||||||
const imports: string[] = []
|
|
||||||
|
|
||||||
while (args.length > 0) {
|
|
||||||
const arg = args[0]
|
|
||||||
|
|
||||||
if (arg === '-I') {
|
|
||||||
// "-I math" format
|
|
||||||
if (args.length < 2) {
|
|
||||||
console.log(`${colors.bright}error: -I requires a module name${colors.reset}`)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
imports.push(args[1])
|
|
||||||
args = args.slice(2)
|
|
||||||
} else if (arg.startsWith('-I')) {
|
|
||||||
// "-Imath" format
|
|
||||||
const moduleName = arg.slice(2)
|
|
||||||
if (!moduleName) {
|
|
||||||
console.log(`${colors.bright}error: -I requires a module name${colors.reset}`)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
imports.push(moduleName)
|
|
||||||
args = args.slice(1)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
showHelp()
|
showHelp()
|
||||||
|
|
@ -101,14 +63,10 @@ async function main() {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepend import statement if -I flags were provided
|
|
||||||
const importStatement = imports.length > 0 ? `import ${imports.join(' ')}` : ''
|
|
||||||
const fullCode = importStatement ? `${importStatement}; ${code}` : code
|
|
||||||
|
|
||||||
try { mkdirSync('/tmp/shrimp') } catch { }
|
try { mkdirSync('/tmp/shrimp') } catch { }
|
||||||
const path = `/tmp/shrimp/${randomUUID()}.sh`
|
const path = `/tmp/shrimp/${randomUUID()}.sh`
|
||||||
writeFileSync(path, fullCode)
|
writeFileSync(path, code)
|
||||||
await runFile(path)
|
console.log(await runFile(path))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user