本文整理汇总了TypeScript中argparse.ArgumentParser类的典型用法代码示例。如果您正苦于以下问题:TypeScript ArgumentParser类的具体用法?TypeScript ArgumentParser怎么用?TypeScript ArgumentParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArgumentParser类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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 ");
}
示例2: 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");
}
示例3: 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");
});
});
}
示例4: 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 ");
}
示例5: originIsAllowed
var javaProc : cp.ChildProcess;
var outputStream: fs.WriteStream;
/**
* utility function used by the websocket server.
* 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(['--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
示例6: catch
});
}
// tslint:disable-next-line:no-empty
catch (ex) {}
if (ret !== undefined) {
return ret;
}
throw new Fatal(`cannot parse ${name}`);
}
const parser = new ArgumentParser({
addHelp: true,
description: "Generates a JSON file suitable for using as the " +
"``metadata`` option for a generic Meta object. The input file must " +
"be a JSON file in the format produced by TEI's odd2json.xsl " +
"transformation.",
});
parser.addArgument(["input"],
{ help: "Input file." });
parser.addArgument(["output"], {
help: "Output file. If absent, outputs to stdout.",
nargs: "?",
});
parser.addArgument(["--tei"], {
help: "Treat the input as a TEI JSON file produced by TEI's odd2json.xsl.",
action: "storeTrue",
示例7: ArgumentParser
// near copy of each of the tests from https://github.com/nodeca/argparse/tree/master/examples
import {ArgumentParser, RawDescriptionHelpFormatter} from 'argparse';
var args: any;
var simpleExample = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'Argparse example',
});
simpleExample.addArgument(
['-f', '--foo'],
{
help: 'foo bar',
}
);
simpleExample.addArgument(
['-b', '--bar'],
{
help: 'bar foo',
}
);
simpleExample.printHelp();
console.log('-----------');
args = simpleExample.parseArgs('-f 1 -b2'.split(' '));
console.dir(args);
console.log('-----------');
args = simpleExample.parseArgs('-f=3 --bar=4'.split(' '));
示例8: require
///<reference path='../lib/ts-declarations/jalangi.d.ts' />
///<reference path='../lib/ts-declarations/mkdirp.d.ts' />
///<reference path='../lib/ts-declarations/wrench.d.ts' />
/**
* Created by m.sridharan on 6/16/14.
*/
import mkdirp = require('mkdirp');
import path = require('path');
import fs = require('fs');
import memTracer = require('../lib/analysis/memTraceAPI');
import Q = require('q');
var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
addHelp: true,
description: "Command-line utility to generate memory trace"
});
parser.addArgument(['--debugFun'], { help: "function name for debug logging" });
parser.addArgument(['--only_include'], { help:"list of path prefixes specifying which sub-directories should be instrumented, separated by path.delimiter"});
parser.addArgument(['--syncAjax'], { help: "use synchronous AJAX calls for logging", action:'storeTrue' });
parser.addArgument(['--outputDir'], { help:"directory in which to place instrumented files and traces. " +
"We create a new sub-directory for our output.", required:true });
parser.addArgument(['--justGenerate'], { help: "just instrument and generate metadata, but don't produce mem-trace", action: 'storeTrue'});
parser.addArgument(['--verbose'], { help: "print verbose output", action:'storeTrue'});
parser.addArgument(['inputFile'], { help:"Either a JavaScript file or an HTML app directory with an index.html file" });
var args = parser.parseArgs();
var outputDir:string = args.outputDir;
var jsFile: boolean = !fs.statSync(args.inputFile).isDirectory();
var promise : Q.Promise<any>, trueOutputDir: string;
if (jsFile) {
示例9: function
module.exports.parseArgs = function() {
const parser = new ArgumentParser({
version: pjson.version,
addHelp: true,
description: 'BitGo-Express'
});
parser.addArgument(['-p', '--port'], {
defaultValue: 3080,
type: 'int',
help: 'Port to listen on'
});
parser.addArgument(['-b', '--bind'], {
defaultValue: 'localhost',
help: 'Bind to given address to listen for connections (default: localhost)'
});
parser.addArgument(['-e', '--env'], {
defaultValue: 'test',
help: 'BitGo environment to proxy against (prod, test)'
});
parser.addArgument(['-d', '--debug'], {
action: 'appendConst',
dest: 'debugnamespace',
constant: 'bitgo:express',
help: 'Enable basic debug logging for incoming requests'
});
parser.addArgument(['-D', '--debugnamespace'], {
action: 'append',
help: 'Enable a specific debugging namespace for more fine-grained debug output. May be given more than once.'
});
parser.addArgument(['-k', '--keypath'], {
help: 'Path to the SSL Key file (required if running production)'
});
parser.addArgument(['-c', '--crtpath'], {
help: 'Path to the SSL Crt file (required if running production)'
});
parser.addArgument( ['-u', '--customrooturi'], {
defaultValue: process.env.BITGO_CUSTOM_ROOT_URI,
help: 'Force custom root BitGo URI (e.g. https://test.bitgo.com)'
});
parser.addArgument(['-n', '--custombitcoinnetwork'], {
defaultValue: process.env.BITGO_CUSTOM_BITCOIN_NETWORK,
help: 'Force custom bitcoin network (e.g. testnet)'
});
parser.addArgument(['-l', '--logfile'], {
help: 'Filepath to write the access log'
});
parser.addArgument(['--disablessl'], {
action: 'storeTrue',
help: 'Allow running against production in non-SSL mode (at your own risk!)'
});
parser.addArgument(['--disableproxy'], {
action: 'storeTrue',
help: 'disable the proxy, not routing any non-express routes'
});
parser.addArgument(['--disableenvcheck'], {
action: 'storeTrue',
defaultValue: true, // BG-9584: temporarily disable env check while we give users time to react to change in runtime behavior
help: 'disable checking for proper NODE_ENV when running in prod environment'
});
parser.addArgument(['-t', '--timeout'], {
defaultValue: (process.env.BITGO_TIMEOUT as any) * 1000 || DEFAULT_TIMEOUT,
help: 'Proxy server timeout in milliseconds'
});
return parser.parseArgs();
};
示例10: 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]
};
}