import * as OptionParser from "." ; import * as OptionLib from "../lib/options" ; import { optionToObject } from "./optionToObject" ; export interface IOptions { debug : boolean ; showHeader : boolean ; showWarnings : boolean ; coins : string [ ] ; sleepTime : number ; unrecognized : string [ ] ; prices : OptionParser . PricesOption ; outputHandler : OptionParser . OutputHandlerOption ; includeFees : boolean ; listCoins : boolean ; watch : boolean ; watchDelay : number ; } export function parseOptions ( args ) { const parsedOptions = OptionLib . parse ( args , { arguments : { "no-color" : { type : "boolean" , default : false , } , "debug" : { type : "boolean" , default : false , aliases : [ "verbose" ] , } , "no-header" : { type : "boolean" , default : false , } , "no-warnings" : { type : "boolean" , default : false , } , "output" : { type : "string" , default : "pretty" , } , "prices" : { type : "string" , default : "average" , } , "sleep-time" : { type : "number" , default : 1000 , } , "experimental-fees" : { type : "boolean" , default : false , } , "list-coins" : { type : "boolean" , default : false , } , "watch" : { type : "boolean" , default : false , } , "watch-delay" : { type : "number" , default : 1000 , } , } , } ) ; const options = { unrecognized : parsedOptions . unrecognized , coins : parsedOptions . plain , debug : parsedOptions . arguments . debug as boolean , showHeader : ! parsedOptions . arguments [ "no-header" ] as boolean , showWarnings : ! parsedOptions . arguments [ "no-warnings" ] as boolean , sleepTime : parsedOptions . arguments [ "sleep-time" ] as number , prices : optionToObject ( parsedOptions , { name : "prices" , default : OptionParser . PricesOption . Average , args : { average : OptionParser . PricesOption . Average , minimum : OptionParser . PricesOption . MinimumWithMiners , "minimum-with-speed" : OptionParser . PricesOption . MinimumWithHashrate , } , } ) , outputHandler : optionToObject < OptionParser . OutputHandlerOption > ( parsedOptions , { name : "output" , default : OptionParser . OutputHandlerOption . Pretty , args : { pretty : OptionParser . OutputHandlerOption . Pretty , json : OptionParser . OutputHandlerOption . JSON , "delayed-json" : OptionParser . OutputHandlerOption . DelayedJSON , } , } ) , includeFees : parsedOptions . arguments [ "experimental-fees" ] as boolean , listCoins : parsedOptions . arguments [ "list-coins" ] as boolean , watch : parsedOptions . arguments [ "watch" ] as boolean , watchDelay : parsedOptions . arguments [ "watch-delay" ] as number , } ; return options ; }