-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to enable verbose debug output and show saner error messag…
…es on failure
- Loading branch information
Showing
10 changed files
with
294 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
import { LogLevel } from '@debugr/core'; | ||
import { parseArgs } from 'util'; | ||
|
||
export class Argv { | ||
readonly configPath: string; | ||
readonly configFile?: string; | ||
readonly logLevel: LogLevel; | ||
|
||
constructor() { | ||
const args = parseArgs({ | ||
strict: true, | ||
allowPositionals: true, | ||
allowPositionals: false, | ||
options: { | ||
'config': { | ||
short: 'c', | ||
type: 'string', | ||
}, | ||
'verbose': { | ||
short: 'v', | ||
type: 'boolean', | ||
default: [], | ||
multiple: true, | ||
}, | ||
}, | ||
}); | ||
|
||
if (args.positionals.length > 1) { | ||
throw new Error('Invalid number of arguments, expected 0-1'); | ||
} | ||
this.configFile = args.values.config; | ||
|
||
const verbosity = args.values.verbose | ||
? args.values.verbose.reduce((n, v) => n + 2 * (Number(v) - 0.5), 0) | ||
: 0; | ||
|
||
this.configPath = args.positionals[0] ?? 'dicc.yaml'; | ||
if (verbosity >= 2) { | ||
this.logLevel = LogLevel.TRACE; | ||
} else if (verbosity > 0) { | ||
this.logLevel = LogLevel.DEBUG; | ||
} else if (verbosity < 0) { | ||
this.logLevel = LogLevel.WARNING; | ||
} else { | ||
this.logLevel = LogLevel.INFO; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.