• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript cli.main函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript cli.parse函数代码示例发布时间:2022-05-24
下一篇:
TypeScript cli.enable函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap