Skip to content

Commit

Permalink
Improve stdin arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gburgett committed Oct 28, 2022
1 parent 8bfe545 commit 1228684
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/fetch_interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Limiter, Semaphore, timeout as timeoutWrapper } from 'async-toolbox'
import * as crossFetch from 'cross-fetch'
import { Interval } from 'limiter'
import { Logger } from './logger'

import { assign, Options } from './util'

Expand All @@ -13,6 +14,7 @@ interface FetchWrapperOptions {
headers: { [key: string]: string },
timeout: number
maxConcurrency: number | { tokens: number, interval: Interval }
logger?: Logger
}

export class FetchInterfaceWrapper implements FetchInterface {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Linkscanner extends Transform {
headers: headerObj,
maxConcurrency,
timeout,
logger: this._options.logger
})
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Logger } from './logger'

export function loadSource(args: { source: string | string[] }, logger: Logger) {
// specify '-' to read from stdin
if (args.source == '-' || args.source == ['-'] ||
if (isStdin(args.source) ||
// or if no URL is given on the command line
args.source.length == 0 && typeof process != 'undefined') {
logger.debug('reading URLs from STDIN')
Expand Down Expand Up @@ -49,3 +49,15 @@ class LineByLineTransform extends Transform {
cb()
}
}

function isStdin(source: any) {
if(source == '-'){
return true
}

if (Array.isArray(source)) {
return source.length == 1 && source[0] == '-'
}

return false
}

0 comments on commit 1228684

Please sign in to comment.