Skip to content

Commit c6aedfa

Browse files
committed
Add debug logging via CLI flag
1 parent b8a8734 commit c6aedfa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

ts/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ function getInputForDay(day: number, year: number, test: boolean = false, fileNa
99
type DayInput = string;
1010
type DaySolver = (input: DayInput) => void;
1111

12+
let debugMode: boolean = false;
13+
function debugLog(message: string): void {
14+
if (debugMode) {
15+
console.debug(message);
16+
}
17+
}
18+
1219
const daySolvers: { [key: string]: DaySolver } = {
1320
'01': (input: DayInput) => {
1421
let zeroCount1: number = 0;
@@ -115,6 +122,7 @@ program
115122
new Date().getFullYear()
116123
)
117124
.option('-t, --test', 'Use test input instead of real input')
125+
.option('-d, --debug', 'Enable debug mode')
118126
.description('Solve the challenge for the specified day')
119127
.action((day, year, options) => {
120128
console.debug(`Solving challenge for year ${year} day ${day}...`);
@@ -123,6 +131,8 @@ program
123131
throw new Error(`No solver implemented for day ${day}`);
124132
}
125133

134+
debugMode = options.debug || false;
135+
126136
const input = getInputForDay(day, year, options.test);
127137
daySolvers[day](input);
128138
});

0 commit comments

Comments
 (0)