本文整理汇总了TypeScript中argparse.ArgumentParser.parseArgs方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ArgumentParser.parseArgs方法的具体用法?TypeScript ArgumentParser.parseArgs怎么用?TypeScript ArgumentParser.parseArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类argparse.ArgumentParser
的用法示例。
在下文中一共展示了ArgumentParser.parseArgs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: instrumentApp
function instrumentApp(args: Array<string>): void {
var parser = new argparse.ArgumentParser({
prog: "meminsight instrument",
addHelp: true,
description: "instrument a local application"
});
parser.addArgument(['--outputDir'], { help:"directory in which to place instrumented files and traces. " +
"We create a new sub-directory for our output.", defaultValue: "/tmp" });
parser.addArgument(['--only_include'], { help:"list of path prefixes specifying which sub-directories should be instrumented, separated by path.delimiter"});
parser.addArgument(['path'], { help:"directory of app to instrument" });
var parsed = parser.parseArgs(args);
var appPath = parsed.path;
var outputDir = parsed.outputDir;
console.log("instrumenting app " + appPath);
if (!fs.existsSync(appPath)) {
console.error("path " + appPath + " does not exist");
process.exit(1);
}
var cliArgs = [
path.join(__dirname, 'memTraceDriver.js'),
'--justGenerate',
'--verbose',
'--outputDir',
outputDir
];
if (parsed.only_include) {
cliArgs.push('--only_include', parsed.only_include);
}
cliArgs.push(appPath);
runNodeProg(cliArgs, "instrumentation");
}
示例2: inspectApp
function inspectApp(args: Array<string>): void {
var parser = new argparse.ArgumentParser({
prog: "meminsight inspect",
addHelp: true,
description: "inspect results of a previous profiling run"
});
parser.addArgument(['path'], { help:"directory of instrumented app" });
var parsed = parser.parseArgs(args);
var appPath = parsed.path;
console.log("inspecting previous run of app " + appPath);
if (!fs.existsSync(appPath)) {
console.error("path " + appPath + " does not exist");
process.exit(1);
}
// in order to inspect, we must have a staleness.json and
// enhanced-trace file present
var stalenessTrace = path.join(appPath, 'staleness-trace');
if (!fs.existsSync(stalenessTrace)) {
console.error("no staleness trace from previous run present; exiting");
process.exit(1);
}
// OK, we have the files. run the GUI server
var cliArgs = [
path.join(__dirname, '..', 'lib', 'gui', 'guiServer.js'),
appPath
];
runNodeProg(cliArgs, "inspect of app ");
}
示例3: parseArgs
export function parseArgs(args?: string[]):
{appDir: string, runtimeImage: string} {
const parsedArgs = PARSER.parseArgs(args);
return {
appDir: parsedArgs.app_dir[0],
runtimeImage: parsedArgs.runtime_image[0]
};
}
示例4: instAndRunNodeScript
/**
* run memory analysis on node script using on-the-fly instrumentation
* @param args
*/
function instAndRunNodeScript(args: Array<string>): void {
var parser = new argparse.ArgumentParser({
prog: "meminsight nodeinstrun",
addHelp: true,
description: "instrument a node.js script as it runs and collect profiling results"
});
parser.addArgument(['script'], { help: "path of script to run, relative to appPath"});
parser.addArgument(['scriptArgs'], {
help: "command-line arguments to pass to script",
nargs: argparse.Const.REMAINDER
});
var parsed = parser.parseArgs(args);
var script = path.resolve(parsed.script);
var scriptArgs = parsed.scriptArgs;
// dump traces in same directory as the instrumented script
// TODO make this configurable
var appPath = path.dirname(script);
var curDir = process.cwd();
process.chdir(appPath);
console.log("running node.js script " + script);
var loggingAnalysisArgs = [
onTheFlyDriver,
'--inlineIID',
'--analysis',
loggingAnalysis,
'--initParam',
'syncFS:true',
'--astHandlerModule',
path.join(__dirname, '..', 'lib', 'analysis', 'freeVarsAstHandler.js'),
script].concat(scriptArgs);
runNodeProg(loggingAnalysisArgs, "run of script ", (code: number) => {
if (code !== 0) {
console.log("run of script failed");
return;
}
console.log("run of script complete");
// run the lifetime analysis
var javaProc = lifetimeAnalysis.runLifetimeAnalysisOnTrace(path.join(appPath,'mem-trace'));
javaProc.stdout.on("data", (chunk : any) => {
console.log(chunk.toString());
});
javaProc.stderr.on("data", (chunk : any) => {
console.error(chunk.toString());
});
javaProc.on("exit", () => {
console.log("done with lifetime analysis");
});
});
}
示例5: runApp
function runApp(args: Array<string>): void {
var parser = new argparse.ArgumentParser({
prog: "meminsight run",
addHelp: true,
description: "run an instrumented web app and collect profiling results"
});
parser.addArgument(['path'], { help:"directory of instrumented app" });
var parsed = parser.parseArgs(args);
var appPath = parsed.path;
console.log("running app " + appPath);
if (!fs.existsSync(appPath)) {
console.error("path " + appPath + " does not exist");
process.exit(1);
}
var cliArgs = [
path.join(__dirname, '..', 'lib', 'server', 'server.js'),
appPath
];
runNodeProg(cliArgs, "run of app ");
}
示例6: ArgumentParser
}
const parser = new ArgumentParser({
description: 'CLI interface for the ehBasic hardware monitor',
addHelp: true
});
parser.addArgument('--cpu-type', {
help: `one of ${CpuTypes.stateMachine} (default), ${CpuTypes.batchedAccess}`,
choices: [CpuTypes.stateMachine, CpuTypes.batchedAccess],
defaultValue: CpuTypes.stateMachine
});
parser.addArgument(['--script', '-s'], { help: 'debugger script' });
parser.addArgument(['--file', '-f'], { help: 'input to feed into the monitor' });
const args = parser.parseArgs();
const fsProvider = new NodeFilesystemProvider(),
cli = new EhBasicCLI(fsProvider, cpuType(args['cpu_type'])),
runner = new NodeCLIRunner(cli);
runner.startup();
if (args['script']) {
cli.runDebuggerScript(args['script']);
}
if (args['file']) {
cli.readInputFile(args['file']);
}
示例7: require
import fs = require("fs")
import Q = require("q")
import cp = require('child_process');
import lastUseTree = require("./lastUseTree")
import issueFinder = require('./issueFinder');
var ejs = require("ejs");
var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
addHelp: true,
description: "GUI server for memory profiler"
});
parser.addArgument(['-P', '--port'], { help: "Port to serve on" });
parser.addArgument(['lifetimeDir'], { help: "directory containing lifetime analysis output for app" });
var args: { port: string; lifetimeDir: string } = parser.parseArgs();
var instOptions = {
iidMap : true,
serialize : true,
relative: true
};
var traceDirectory = path.resolve(args.lifetimeDir);
var stalenessTrace = path.join(traceDirectory, 'staleness-trace');
var lastUseTrace = path.join(traceDirectory, 'lastuse-trace');
var unreachableTrace = path.join(traceDirectory, 'unreachable-trace');
var memTrace = path.join(traceDirectory, 'mem-trace');
var port = args.port === null ? 9000 : parseInt(args.port);
示例8: originIsAllowed
* currently does nothing
*/
function originIsAllowed(origin: string) {
// put logic here to detect whether the specified origin is allowed.
return true;
}
var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
addHelp: true,
description: "Integrated server for memory profiler"
});
parser.addArgument(['--noHTTPServer'], { help: "don't start up a local HTTP server", action: 'storeTrue'});
parser.addArgument(['--outputFile'], { help: "name for output file for memory trace (default mem-trace in app directory)" });
parser.addArgument(['app'], { help: "the app to serve. if --noHTTPServer is passed, directory of the uninstrumented app, or where app code will be stored (if a proxy server is being used)", nargs: 1});
var args: { noHTTPServer: string; app: Array<string>; outputFile: string; } = parser.parseArgs();
var app = args.app[0];
var outputDir = app;
/**
* initializes the output target, both a Java process and a WriteStream for a file
*/
function initOutputTarget(): void {
if (!outputStream) {
var outputFileName = args.outputFile;
if (!outputFileName) {
outputFileName = path.join(outputDir, 'mem-trace');
}
outputStream = fs.createWriteStream(outputFileName);
示例9: mkdirSync
type: "string",
help: "output filename prefix",
defaultValue: "ts-"
}
);
parser.addArgument(
["-w", "--watch"],
{
defaultValue: args.watch,
dest: "watch",
action: "storeTrue",
help: "Watch source definitions"
}
);
var parsedArgs: IOptions = parser.parseArgs();
if (parsedArgs.inputs) {
args.inputs = parsedArgs.inputs;
}
if (parsedArgs.outdir) {
args.outdir = parsedArgs.outdir;
}
// create out dir
try {
mkdirSync(args.outdir);
}
catch (e) {
}
// inference rootdir
示例10: originIsAllowed
function originIsAllowed(origin: string) {
// put logic here to detect whether the specified origin is allowed.
return true;
}
var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
addHelp: true,
description: "Integrated server for memory profiler"
});
parser.addArgument(['--proxy'], { help: "run as a proxy server, instrumenting code on-the-fly", action:'storeTrue' });
parser.addArgument(['--proxyOutput'], { help: "in proxy server mode, directory under which to store instrumented code", defaultValue: '/tmp/proxyOut' });
parser.addArgument(['--noHTTPServer'], { help: "don't start up a local HTTP server", action: 'storeTrue'});
parser.addArgument(['--outputFile'], { help: "name for output file for memory trace (default mem-trace in app directory)" });
parser.addArgument(['app'], { help: "the app to serve. in proxy mode, the app should be uninstrumented.", nargs: 1});
var args: { proxy: string; proxyOutput: string; noHTTPServer: string; app: Array<string>; outputFile: string; } = parser.parseArgs();
var app = args.app[0];
// default to app directory; we'll change it in proxy server mode
var outputDir = app;
/**
* create a fresh directory in which to dump instrumented scripts
*/
function initProxyOutputDir(): void {
outputDir = args.proxyOutput;
var scriptDirToTry = "";
for (var i = 0; i < 100; i++) {
scriptDirToTry = path.join(outputDir, "/site" + i);
if (!fs.existsSync(scriptDirToTry)) {