import { Preconditions } from 'polar-shared/src/Preconditions' ; import { FilePaths } from 'polar-shared/src/util/FilePaths' ; export class Cmdline { static getDocArg ( args ) { return Cmdline . getArg ( args , Cmdline . isDoc ) ; } static getURLArg ( args ) { return Cmdline . getArg ( args , Cmdline . isURL ) ; } static getArg ( args , filter ) { Preconditions . assertNotNull ( filter , "filter" ) ; if ( ! ( args instanceof Array ) ) { throw new Error ( "Args not an array" ) ; } const arg = args . filter ( ( arg ) => arg != null && filter ( arg ) ) . reduce ( ( accumulator , currentValue ) => accumulator = currentValue != null ? currentValue : null , null ) ; return arg ; } public static isDoc ( arg ) { return FilePaths . hasExtension ( arg , "pdf" ) || FilePaths . hasExtension ( arg , "chtml" ) || FilePaths . hasExtension ( arg , "phz" ) ; } public static isURL ( arg ) { return arg . startsWith ( "http:" ) || arg . startsWith ( "https:" ) || arg . startsWith ( "file:" ) ; } }