當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript nopt類代碼示例

本文整理匯總了TypeScript中nopt的典型用法代碼示例。如果您正苦於以下問題:TypeScript nopt類的具體用法?TypeScript nopt怎麽用?TypeScript nopt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了nopt類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parseArgs

function parseArgs() {
  return nopt(
    {
      "help": Boolean,
      "version": Boolean,
      "verbose": Boolean,
      "port": Number,
      "examples": Boolean,
      "example": String, // deprecated
      "config": String,

      "print-config": Boolean,
      "with-comments": Boolean,

      "file": String,
      "druid": String,
      "postgres": String,
      "mysql": String,

      "user": String,
      "password": String,
      "database": String
    },
    {
      "v": ["--verbose"],
      "p": ["--port"],
      "c": ["--config"],
      "f": ["--file"],
      "d": ["--druid"]
    },
    process.argv
  );
}
開發者ID:RaviNK,項目名稱:pivot,代碼行數:33,代碼來源:config.ts

示例2: if

    operations.push(async callback => {
        var module = remain[0]

        if (cooked[0] === '--version' || cooked[0] === '-v') {
            module = 'version'
        } else if (!remain.length || cooked.indexOf('-h') >= 0 || cooked.indexOf('--help') >= 0) {
            module = 'help'
        }

        try {
            Command = await loadCommand(module)
        } catch (err) {
            throw new Error(`Cannot find module ${module}\n${err}`)
        }

        options = nopt(Command.DETAILS.options, Command.DETAILS.shorthands, process.argv, 2)

        iterative = Command.DETAILS.iterative

        cooked = options.argv.cooked
        remain = options.argv.remain

        options.number = options.number || [remain[1]]
        options.remote = options.remote || config.default_remote

        if (module === 'help') {
            callback()
        } else {
            User.login(callback)
        }
    })
開發者ID:gamerson,項目名稱:gh,代碼行數:31,代碼來源:cmd.ts

示例3: parseArgs

function parseArgs() {
  return nopt(
    {
      "host": String,
      "druid": String,
      "data-source": String,
      "help": Boolean,
      "query": String,
      "interval": String,
      "version": Boolean,
      "verbose": Boolean,
      "timeout": Number,
      "retry": Number,
      "concurrent": Number,
      "output": String,
      "allow": [String, Array],
      "force-unique": [String, Array],
      "force-histogram": [String, Array],
      "skip-cache": Boolean,
      "introspection-strategy": String
    },
    {
      "h": ["--host"],
      "q": ["--query"],
      "v": ["--verbose"],
      "d": ["--data-source"],
      "i": ["--interval"],
      "a": ["--allow"],
      "r": ["--retry"],
      "c": ["--concurrent"],
      "o": ["--output"],
      "fu": ["--force-unique"],
      "fh": ["--force-histogram"]
    },
    process.argv
  );
}
開發者ID:dkarpman,項目名稱:plyql,代碼行數:37,代碼來源:cli.ts

示例4: Help

export default function Help() {
    this.options = nopt(Help.DETAILS.options, Help.DETAILS.shorthands, process.argv, 2)
}
開發者ID:gamerson,項目名稱:gh,代碼行數:3,代碼來源:help.ts

示例5: setUp

export function setUp() {
    let Command
    let iterative
    let options
    const operations = []
    const parsed = nopt(process.argv)
    let remain = parsed.argv.remain
    let cooked = parsed.argv.cooked

    operations.push(callback => {
        checkVersion()

        callback()
    })

    operations.push(async callback => {
        var module = remain[0]

        if (cooked[0] === '--version' || cooked[0] === '-v') {
            module = 'version'
        } else if (!remain.length || cooked.indexOf('-h') >= 0 || cooked.indexOf('--help') >= 0) {
            module = 'help'
        }

        try {
            Command = await loadCommand(module)
        } catch (err) {
            throw new Error(`Cannot find module ${module}\n${err}`)
        }

        options = nopt(Command.DETAILS.options, Command.DETAILS.shorthands, process.argv, 2)

        iterative = Command.DETAILS.iterative

        cooked = options.argv.cooked
        remain = options.argv.remain

        options.number = options.number || [remain[1]]
        options.remote = options.remote || config.default_remote

        if (module === 'help') {
            callback()
        } else {
            User.login(callback)
        }
    })

    async.series(operations, async () => {
        let iterativeValues
        const remoteUrl = git.getRemoteUrl(options.remote)

        options.isTTY = {}
        options.isTTY.in = Boolean(process.stdin.isTTY)
        options.isTTY.out = Boolean(process.stdout.isTTY)
        options.loggedUser = getUser()
        options.remoteUser = git.getUserFromRemoteUrl(remoteUrl)

        if (!options.user) {
            if (options.repo || options.all) {
                options.user = options.loggedUser
            } else {
                options.user = process.env.GH_USER || options.remoteUser || options.loggedUser
            }
        }

        options.repo = options.repo || git.getRepoFromRemoteURL(remoteUrl)
        options.currentBranch = options.currentBranch || git.getCurrentBranch()

        expandAliases(options)
        options.github_host = config.github_host
        options.github_gist_host = config.github_gist_host

        // Try to retrieve iterative values from iterative option key,
        // e.g. option['number'] === [1,2,3]. If iterative option key is not
        // present, assume [undefined] in order to initialize the loop.
        iterativeValues = options[iterative] || [undefined]

        iterativeValues.forEach(async value => {
            options = clone(options)

            // Value can be undefined when the command doesn't have a iterative
            // option.
            options[iterative] = value

            invokePayload(options, Command, cooked, remain)

            if (process.env.NODE_ENV === 'testing') {
                const { prepareTestFixtures } = await import('./utils')

                await new Command(options).run(prepareTestFixtures(Command.name, cooked))
            } else {
                await new Command(options).run()
            }
        })
    })
}
開發者ID:gamerson,項目名稱:gh,代碼行數:96,代碼來源:cmd.ts


注:本文中的nopt類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。