Files
cell/index.ce
2026-02-20 15:33:46 -06:00

59 lines
1.4 KiB
Plaintext

// cell index <file> — Build semantic index for a source file.
//
// Usage:
// cell index <file.ce|file.cm> Index one file, output JSON to stdout
// cell index <file> -o <output.json> Index one file, write to file
// cell index --help Show this help
var fd = use('fd')
var json = use('json')
var shop = use('internal/shop')
var filename = null
var output_path = null
var i = 0
for (i = 0; i < length(args); i++) {
if (args[i] == '-o' || args[i] == '--output') {
if (i + 1 < length(args)) {
output_path = args[i + 1]
i = i + 1
} else {
log.error('-o requires a file path')
$stop()
}
} else if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell index <file.ce|file.cm> [options]")
log.console("")
log.console("Build a semantic index for a source file.")
log.console("")
log.console("Options:")
log.console(" -o <path> Write output to file instead of stdout")
$stop()
} else if (!starts_with(args[i], '-')) {
filename = args[i]
}
}
if (filename == null) {
log.error('No file specified. Usage: cell index <file>')
$stop()
}
if (!fd.is_file(filename)) {
log.error('File not found: ' + filename)
$stop()
}
var idx = shop.index_file(filename)
var out = json.encode(idx, true)
if (output_path != null) {
fd.slurpwrite(output_path, out)
log.console('Wrote index to ' + output_path)
} else {
log.compile(out)
}
$stop()