// 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 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 [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 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()