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

TypeScript optimist.usage函数代码示例

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

本文整理汇总了TypeScript中optimist.usage函数的典型用法代码示例。如果您正苦于以下问题:TypeScript usage函数的具体用法?TypeScript usage怎么用?TypeScript usage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了usage函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: run

export function run() {
    var argv = optimist
        .usage("Usage: \n  tpm install\n  tpm install package.json -o types/\n  tpm index types/**/*.d.ts -o types/all.d.ts")
        .demand([1])
        .check(function() {
            var command = optimist.argv._[0]
            if (command != "install" && command != "index") {
                throw new Error("Unknown Command: " + command)
            }
        })
        .argv

    var files = argv._
    var command = files.shift()
    var workingDir = process.cwd()
    files = files.map((f) => path.join(workingDir, f))

    var promise;

    if (command == "install") {
        var o = argv.o || "types/"
        var out = path.join(workingDir, o)
        if (argv.dev.length) warning("Please put --dev at the end of the command: tpm install package.json --dev")
        var useDev = !!argv.dev
        if (!files.length) files = [path.join(workingDir, "package.json")]
        promise = install(files[0], out, useDev)
    }

    else if (command == "index") {
        var o = argv.o || "types/all.d.ts"
        var out = path.join(workingDir, o)
        if (!files.length) warning("You must specify files to index")
        promise = index(files, out)
    }

    else {
        warning("Unknown Command: " + command)
    }

    if (promise) {
        promise.then(function() {
            console.log("[DONE]")
        }, error)
    }

}
开发者ID:davidparsson,项目名称:tpm,代码行数:46,代码来源:command.ts


示例2: main

export function main() {
  const argvparser = optimist
    .usage('Usage: npm-history -p 80')
    .describe({
      hostname: 'hostname to listen on',
      port: 'port to listen on',
      help: 'print this help message',
      verbose: 'print extra output',
      version: 'print version',
    })
    .alias({
      h: 'help',
      p: 'port',
      v: 'verbose',
    })
    .default({
      hostname: process.env.HOSTNAME || '127.0.0.1',
      port: parseInt(process.env.PORT, 10) || 8080,
    })
    .boolean(['help', 'verbose', 'version'])

  const argv = argvparser.argv
  logger.level = argv.verbose ? Level.debug : Level.info

  if (argv.help) {
    argvparser.showHelp()
  }
  else if (argv.version) {
    console.log(require('./package').version)
  }
  else {
    db.createDatabaseIfNotExists(error => {
      if (error) throw error

      executePatches(db, '_migrations', path.join(__dirname, 'migrations'), patchError => {
        if (patchError) throw patchError

        server.listen(argv.port, argv.hostname)
      })
    })
  }
}
开发者ID:chbrown,项目名称:npm-history,代码行数:42,代码来源:index.ts


示例3:

import * as fs from "fs";
import * as glob from "glob";
import * as optimist from "optimist";
import * as path from "path";
import * as ts from "typescript";

import {
    CONFIG_FILENAME,
    DEFAULT_CONFIG,
    findConfiguration,
} from "./configuration";
import {consoleTestResultHandler, runTest} from "./test";
import * as Linter from "./tslintMulti";

let processed = optimist
    .usage("Usage: $0 [options] file ...")
    .check((argv: any) => {
        // at least one of file, help, version, project or unqualified argument must be present
        if (!(argv.h || argv.i || argv.test || argv.v || argv.project || argv._.length > 0)) {
            throw "Missing files";
        }

        if (argv.f) {
            throw "-f option is no longer available. Supply files directly to the tslint command instead.";
        }
    })
    .options({
        c: {
            alias: "config",
            describe: "configuration file",
        },
开发者ID:chrismbarr,项目名称:tslint,代码行数:31,代码来源:tslint-cli.ts


示例4: main

export function main() {
  let argvparser = optimist
  .usage([
    'Consolidate any tabular format.',
    '',
    'Usage: <sprints.txt sv [options] > sprints.csv',
    '   or: sv [options] ~/Desktop/**/*.csv > ~/all.csv',
    '',
    'Parser options:',
    '  --in-delimiter    field separator (inferred if unspecified)',
    '  --in-quotechar "  ',
    '  --in-json         parse input as JSON (one object per row)',
    '',
    'Stringifier options:',
    '  --peek 10         infer columns from first ten objects of input',
    '  --out-delimiter , field separator',
    '  --out-quotechar " marks beginning and end of fields containing delimiter',
    '  --filter a,b      keep only fields a and b in the results',
    '  --omit c,d        leave out fields x and y from the results (processed before filter)',
    '  -j, --json        write one JSON object per row',
    '',
    'Other options:',
    '      --version       print version and quit',
    '  -v  --verbose       turn up the verbosity (still all on STDERR)',
    '',
    'STDIN, if supplied, will be coerced to utf8',
  ].join('\n'))
  .options({
    json: {
      alias: 'j',
      type: 'boolean',
    },
    'in-json': {
      type: 'boolean',
    },
    delimiter: {
      type: 'string',
    },
    quotechar: {
      type: 'string',
    },
    escapechar: {
      type: 'string',
    },
    help: {
      alias: 'h',
      describe: 'print this help message',
      type: 'boolean',
    },
    verbose: {
      alias: 'v',
      describe: 'print extra output',
      type: 'boolean',
    },
    version: {
      describe: 'print version',
      type: 'boolean',
    },
  });

  const argv = argvparser.argv;
  const parser_opts = {
    delimiter: argv['in-delimiter'],
    quotechar: argv['in-quotechar'],
    json: argv['in-json'],
  };
  const stringifier_opts = {
    delimiter: argv['out-delimiter'],
    quotechar: argv['out-quotechar'],
    peek: argv.peek,
    filter: argv.filter,
    omit: argv.omit,
    json: argv.json,
    width: argv.width,
  };

  function exit(err: NodeJS.ErrnoException) {
    if (err && err.code !== 'EPIPE') {
      throw err;
    }
    // if err.code == 'EPIPE' that just means that someone down
    // the line cut us short with a | head or something

    if (argv.verbose) {
      console.error('Done.');
    }
    // process.exit(); // wait for stdout to finish, actually.
  }

  if (argv.help) {
    argvparser.showHelp();
    console.log('ARGV: ' + process.argv.join(' '));
    if (argv.verbose) {
      console.log('  argv: ' + JSON.stringify(argv, null, '  ').replace(/\n/g, '\n  '));
    }
    console.log('  parser options: ' + JSON.stringify(parser_opts, null, '  ').replace(/\n/g, '\n  '));
    console.log('  stringifier options: ' + JSON.stringify(stringifier_opts, null, '  ').replace(/\n/g, '\n  '));
  }
  else if (argv.version) {
    console.log(require('../package').version);
//.........这里部分代码省略.........
开发者ID:chbrown,项目名称:sv,代码行数:101,代码来源:sv.ts


示例5: require

/// <reference path="../types/node.d.ts" />
/// <reference path="../types/optimist.d.ts" />

var optimist = require('optimist'); //something weird going on, can't import it properly
import compile = require('./compile');



var argv = optimist
  .usage('blaze <file>')
  .boolean('v')
  .describe('v', 'enable debug output')
  .argv;



var file = argv._[0];


if(file){
    console.log("transpiling", file);

    compile.compile(file, argv['v']);
}else{
    console.log("you must specify a YAML file containing the rules to compile")
}


开发者ID:tomlarkworthy,项目名称:linked_list,代码行数:26,代码来源:blaze.ts


示例6: require

import {IException, Exception} from "../exception";
import {IClient as IMemory, Client as Memory} from "../memory/client";
import IDaemon    = require("./daemon/IDaemon");
import Daemon     = require("./daemon/Daemon");
import {installMapping} from "../utils";
import {deferred} from "../utils/common";
import log4js     = require("../../logger");
import * as optimist from "optimist";

installMapping();

var memory:IMemory;
var daemon:IDaemon;
var logger:log4js.Logger = log4js.getLogger("less");
var argv:any = optimist
    .usage("Usage: less -l [daemon] -m [memory]")
    .demand("l").alias("l", "location").describe("l", "Daemon socket location")
    .demand("m").alias("m", "memory").describe("m", "Memory socket location")
    .argv;

function handler(errors:IException[]):void {
    var index:number,
        length:number;
    if (errors && errors.length) {
        if (!messageSent) {
            process.stderr.write(JSON.stringify({
                    started : false,
                    errors  : errors.map((error:IException):any => {
                        return error.toObject();
                    })
                }) + "\n");
开发者ID:rodzewich,项目名称:playground,代码行数:31,代码来源:daemon.ts


示例7:

#!/usr/bin/env node
import {createReadStream} from 'fs';
import {logger, Level} from 'loge';
import * as optimist from 'optimist';

import {Parser, XMLSerializer} from '../index';

let argvparser = optimist
  .usage('Usage: htmlfmt page.html')
  // .example('curl https://www.google.com/ | htmlfmt')
  .options({
    limit: {
      describe: 'maximum element length to inline',
      default: 60,
    },
    lower: {
      describe: 'convert tag names to lowercase',
      type: 'boolean',
    },
    // script meta commands
    help: {
      describe: 'print this help message',
      alias: 'h',
      type: 'boolean',
    },
    verbose: {
      describe: 'print debugging information',
      alias: 'v',
      type: 'boolean',
    },
    version: {
开发者ID:chbrown,项目名称:domlike,代码行数:31,代码来源:htmlfmt.ts


示例8: test

/// <reference path="./typings/index.d.ts"/>

import * as translator from './thingTranslator';
import * as q from 'q';
import * as optimist from 'optimist';

var argv = optimist
    .usage('Usage: $0 -a [ip address of hue bridge] -u [hue user id] -i [hue light unique id]')
    .demand(['a'])
    .demand(['u'])
    .demand(['i'])
    .argv;

test({
    name: "Hue Light (Test)",
    props: JSON.stringify({ ipAddress: argv.a, userId: argv.u, uniqueId: argv.i })
});

async function test(device: translator.Device): Promise<void> {
    console.log("Testing lamp: " + device.props);

    // initialize the translator for testing purposes (this is normally called by the runtime)
    translator.initDevice(device);

    // Go through a sequence of test operations for the translator.

    await q.delay(1000);
    await translator.turnOn();
    await q.delay(5000);
    await translator.turnOff();
开发者ID:ejarvi,项目名称:translators,代码行数:30,代码来源:test.ts


示例9: main

export function main() {
  let argvparser = optimist
    .usage([
      'Usage: academia <command> <file>',
      '',
      'Commands:',
      '  highlight: highlight references in paper, e.g.:',
      '    academia highlight P14-1148.pdf.json -- Print the Paper specified in P14-1148.pdf.json as plaintext with the references highlighted',
      '  link: detect references, citations, and link citations to references as possible, e.g.:',
      '    academia link P14-1148.pdf.json -- Detect cites and references, link them, and print the full enhanced Paper object',
    ].join('\n'))
    .describe({
      output: 'output file (- for STDOUT)',
      help: 'print this help message',
      verbose: 'print debug messages',
      version: 'print version',
    })
    .alias({
      o: 'output',
      h: 'help',
      v: 'verbose',
    })
    .boolean([
      'help',
      'verbose',
    ])
    .default({
      output: '-',
    });

  let argv = argvparser.argv;

  if (argv.help) {
    argvparser.showHelp();
  }
  else if (argv.version) {
    console.log(require('../package').version);
  }
  else {
    argv = argvparser.demand(2).argv;
    // pull off positional arguments
    const command: string = argv._[0];
    const input_filename: string = argv._[1];
    // apply command to input
    let output: string;
    if (command === 'highlight') {
      output = highlight(input_filename);
    }
    else if (command === 'link') {
      const paper = link(input_filename);
      output = JSON.stringify(paper);
    }
    else {
      stderr(`Unrecognized command: "${command}"`);
      process.exit(1);
    }

    const outputStream = (argv.output == '-') ? process.stdout : createWriteStream(argv.output, {encoding: 'utf8'});
    outputStream.write(output + '\n');
  }
}
开发者ID:chbrown,项目名称:academia,代码行数:61,代码来源:index.ts



注:本文中的optimist.usage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript option-t.Option类代码示例发布时间:2022-05-25
下一篇:
TypeScript optimal.string函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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