in packages/extensions/core/src/app.ts [111:192]
async function currentMain(
logger: AutorestLogger,
loggerSink: IAutorestLogger,
args: AutorestCliArgs,
): Promise<number> {
if (!args.options["message-format"] || args.options["message-format"] === "regular") {
logger.info(`> Loading AutoRest core '${__dirname}' (${VERSION})`);
}
verbose = verbose || (args.options["verbose"] ?? false);
debug = debug || (args.options["debug"] ?? false);
// Only show library logs if in verbose or debug mode.
if (verbose || debug) {
configureLibrariesLogger("verbose", (...x) => logger.debug(x.join(" ")));
}
// identify where we are starting from.
const currentDirUri = createFolderUri(currentDirectory());
if (args.options["help"]) {
// if they are asking for help, feed a false file to config so we don't load a user's configuration
args.configFileOrFolder = "invalid.filename.md";
}
const githubToken = args.options["github-auth-token"] ?? process.env.GITHUB_AUTH_TOKEN;
// get an instance of AutoRest and add the command line switches to the configuration.
const api = new AutoRest(
loggerSink,
new EnhancedFileSystem(githubToken),
resolveUri(currentDirUri, args.configFileOrFolder ?? "."),
);
api.AddConfiguration(args.options);
// listen for output messages and file writes
const artifacts: Array<Artifact> = [];
const clearFolders = new Set<string>();
const protectFiles = new Set<string>();
const context = await api.view;
const artifactWriter = new ArtifactWriter(context.config);
api.GeneratedFile.Subscribe((_, artifact) => {
if (context.config.help) {
artifacts.push(artifact);
return;
}
protectFiles.add(artifact.uri);
artifactWriter.writeArtifact(artifact);
});
api.ProtectFile.Subscribe((_, filename) => {
protectFiles.add(filename);
});
api.ClearFolder.Subscribe((_, folder) => clearFolders.add(folder));
// maybe a resource schema batch process
if (context.config["resource-schema-batch"]) {
return resourceSchemaBatch(api, logger);
}
if (context.config["batch"]) {
await batch(api, logger);
} else {
const result = await api.Process().finish;
if (result !== true) {
throw result;
}
}
if (context.config.help) {
printAutorestHelp(artifacts);
} else {
// perform file system operations.
await doClearFolders(protectFiles, clearFolders, logger);
logger.debug("Writing Outputs.");
await artifactWriter.wait();
}
printCompleteSummary(logger, artifactWriter);
// return the exit code to the caller.
return 0;
}