本文整理汇总了TypeScript中cli.main函数的典型用法代码示例。如果您正苦于以下问题:TypeScript main函数的具体用法?TypeScript main怎么用?TypeScript main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了main函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
cli.main(function (args, options) {
var output = '', i: any, j: any, l: number, output_stream: NodeJS.WritableStream;
if (this.argc) {
if (options.escape) {
var replace: any = {'\\n':'\n','\\r':'\r','\\t':'\t','\\e':'\e','\\v':'\v','\\f':'\f','\\c':'\c','\\b':'\b','\\a':'\a','\\\\':'\\'};
var escape = function (str: string) {
str += '';
for (j in replace) {
str = str.replace(i, replace[i]);
}
return str;
}
for (i = 0, l = this.argc; i < l; i++) {
args[i] = escape(args[i]);
}
options.separator = escape(options.separator);
}
output += args.join(options.separator);
}
if (!options.newline) {
output += '\n';
}
try {
if (options.output) {
output_stream = this.native.fs.createWriteStream(options.output)
} else {
output_stream = process.stdout;
}
output_stream.write(output);
} catch (e) {
this.fatal('Could not write to output stream');
}
});
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:36,代码来源:cli-tests.ts
示例2: build
verbose: [null, 'Verbose logs'],
});
cli.main((args, options)=>{
if (options.quiet){
log.setLogLevel(log.LogLevel.error);
}
if (options.verbose){
log.setLogLevel(log.LogLevel.verbose);
}
build({
project: options.project,
outDir: options.outDir,
build: !options.nobuild,
watch: !!options.watch,
force: !!options.force,
target: args.length > 0 ? args : null,
server: !!options.server,
port: options.port,
}).catch(e=>{
if (e){
log.error(e);
if (e.stack){
console.error(e.stack);
}
}
process.exit(1);
});
});
开发者ID:uhyo,项目名称:my-static,代码行数:30,代码来源:bin.ts
示例3: require
cli.main(function(args, options) {
try {
if(cli.command) {
if(commands.indexOf(cli.command) < 0) throw Error('Invalid command: ' + cli.command);
// First try to run the `portable-js` package that is installed in folder where manifest file is located,
// if not found, run the command from the global package.
var manifest_dir = '';
if(options.file) {
manifest_dir = path.dirname(options.file);
} else {
manifest_dir = process.cwd();
}
var command_dir = manifest_dir + '/node_modules/portable-js/src/command';
if(!fs.existsSync(command_dir)) command_dir = __dirname + '/command';
if(options.verbose) log.level = 'verbose';
if(options.debug) log.level = 'silly';
var cmd = require(command_dir + '/' + cli.command + '.js');
cmd(args, options);
} else {
log.error('Command not found: ' + cli.command);
}
} catch(e) {
log.error(e);
if(options.debug) {
console.log(e.stack || e);
}
}
});
开发者ID:streamich,项目名称:portable,代码行数:32,代码来源:cli.ts
示例4: require
cli.main(function(args, options) {
//console.log(args, options);
var file_arg_pos = 0; // Position of a file to include in arguments list.
if(options['config-file']) {
var path = require('path');
var conffile = path.resolve(options['config-file']);
try {
var json = fs.readFileSync(conffile);
var config2 = JSON.parse(json.toString());
} catch(e) {
console.log(e.stack || e);
throw(Error('Error while loading config file.'))
}
for(var prop in config2) config[prop] = config2[prop];
}
var config_json = options.config;
if(config_json) {
try {
var config3 = JSON.parse(config_json);
} catch(e) {
console.log(e.stack || e);
throw(Error('Error while parsing --config JSON.'))
}
for(var prop in config3) config[prop] = config3[prop];
}
if(config.debug) {
console.log("Arguments:");
console.log(process.argv);
console.log("CLI options:");
console.log(args, options);
}
// Prompt
if(!config.prompt) config.prompt = prompt.Template.template;
var grammar = config.grammar;
if(grammar.indexOf("/") == -1) { // No slash "/", then load from "../grammar/" directory.
grammar = __dirname + "/../grammar/" + grammar;
} else {
grammar = require("path").resolve(grammar);
}
var apis = [];
config.api.forEach((tuple) => {
if(!(tuple instanceof Array) || (tuple.length != 2)) throw Error('Invalid "api" property in config.');
apis.push({namespace: tuple[0], name: tuple[1]});
});
var requires = [];
config.require.forEach((tuple) => {
if(!(tuple instanceof Array) || (tuple.length != 2)) throw Error('Invalid "require" property in config.');
requires.push({namespace: tuple[0], name: tuple[1]});
});
var opts: builder.IOpts = {
apis: apis,
require: requires,
prompt: config.prompt,
verbose: config.verbose,
printUndefined: config.undef,
language: config.lang,
grammar: grammar,
history: config.history,
entrypoint: config.entrypoint,
};
var file = '';
if(args.length > file_arg_pos) file = args[file_arg_pos];
// Start an SSH server.
if(options.ssh) {
if(!options.port) throw Error('Port --port not specified.');
opts.ssh = options.ssh;
opts.port = options.port;
var SshServerApp = require("./app/SshServer");
var app = new SshServerApp(opts);
app.run();
return;
}
// Start --port server.
if(options.port) {
var SocketApp = require("./app/Socket");
var app = new SocketApp(opts);
app.run(options.port);
return;
}
builder.Builder.buildShell(opts, (err, shell) => {
if(err) {
console.log("Error on startup.");
console.log(err);
return;
}
// Start --headless server.
//.........这里部分代码省略.........
开发者ID:streamich,项目名称:jssh,代码行数:101,代码来源:cli.ts
注:本文中的cli.main函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论