1
我設置的指揮官設置defaultargs這樣的:指揮官不使用默認值
import * as validations from './validation'
import program from 'commander'
import path from 'path'
export default function initializeCommander (defaults) {
program
.version('0.0.1')
.usage('redbubble-demo')
.option('-u', '--url [url]', validations.isValidUrl, defaults.url)
.option('-o', '--output-dir [path]', validations.hasValidParentDirectory, path.resolve(defaults.path))
.option('-s', '--size [size]', validations.isValidSize, defaults.size)
.parse(process.argv)
return program
}
我在這裏設置的默認值,並將其傳遞到像這樣的功能:
const defaultValues = {
url: 'someuRL',
size: 'medium',
outputDir: './www'
}
const program = initializeCommander(defaultValues)
console.log(program) //no value in console
當我嘗試並從program
訪問選項,我沒有得到任何價值。
我使用調用我的應用程序不帶任何參數:
babel-node src/index.js
UPDATE:
我能夠運行的應用程序的二進制現在用npm link
,但我得到這個錯誤:
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.resolve (path.js:1146:7)
at initializeCommander (/home/vamsi/Do/redbubble-demo/build/index.js:9889:222)
at Object.<anonymous> (/home/vamsi/Do/redbubble-demo/build/index.js:87:34)
at __webpack_require__ (/home/vamsi/Do/redbubble-demo/build/index.js:22:30)
at /home/vamsi/Do/redbubble-demo/build/index.js:42:18
at Object.<anonymous> (/home/vamsi/Do/redbubble-demo/build/index.js:45:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
stack trace
中的行號已關閉,因爲我正在使用webpack
對其進行捆綁。
我正在使用webpack,因爲我有'import'語句遍佈我的代碼。另外,我閱讀http://jlongster.com/Backend-Apps-with-Webpack--Part-I。它不處理像'--output-dir'這樣的冗長參數,但可以正確使用'-o'。我怎樣才能處理冗長的參數呢? – vamsiampolu