// cell index — Build semantic index for a source file. // // Usage: // cell index Index one file, output JSON to stdout // cell index -o Index one file, write to file // cell index --help Show this help var fd = use('fd') var json = use('json') var tokenize_mod = use('tokenize') var parse_mod = use('parse') var fold_mod = use('fold') var index_mod = use('index') 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 [options]") log.console("") log.console("Build a semantic index for a source file.") log.console("") log.console("Options:") log.console(" -o 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 ') $stop() } if (!fd.is_file(filename)) { log.error('File not found: ' + filename) $stop() } var src = text(fd.slurp(filename)) var pipeline = {tokenize: tokenize_mod, parse: parse_mod, fold: fold_mod} var idx = index_mod.index_file(src, filename, pipeline) var out = json.encode(idx, true) if (output_path != null) { fd.slurpwrite(output_path, out) log.console('Wrote index to ' + output_path) } else { print(out) print("\n") } $stop()