本文整理匯總了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)
}
}
示例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)
})
})
}
}
示例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",
},
示例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);
//.........這裏部分代碼省略.........
示例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")
}
示例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");
示例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: {
示例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();
示例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');
}
}