This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refact] move functions from index.ts to other places
- Loading branch information
Showing
3 changed files
with
43 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const EXIT_TASK_FAILED = 1 | ||
export const EXIT_LOGIN_FAILED = 69 | ||
export const EXIT_CODE_INVALID_ARGUMENT = 87 | ||
export const EXIT_CODE_UNKNOWN_ERROR = 255 |
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,3 +1,33 @@ | ||
import log from 'loglevel' // cspell: ignore loglevel | ||
import { OptionValues } from 'commander' | ||
import { EXIT_CODE_INVALID_ARGUMENT } from './exit_code' | ||
|
||
export function sleep() { | ||
return new Promise((res) => setTimeout(res, 500)) | ||
} | ||
|
||
export function setupLogging(args: OptionValues) { | ||
if (process.env['DEBUG']) { | ||
log.setDefaultLevel('debug') | ||
if (args.quiet) { | ||
log.warn('Option `--quiet` is ignored in debug mode.') | ||
} | ||
} else if (args.quiet) { | ||
log.setDefaultLevel('warn') | ||
} else { | ||
log.setDefaultLevel('info') | ||
} | ||
} | ||
|
||
function requireCheckinOrSolveWeeklyMission(args: OptionValues) { | ||
if (args.checkin === args.solveWeeklyMission) { | ||
log.error( | ||
'You should run exactly one of --checkin or --solve-weekly-mission.' | ||
) | ||
process.exit(EXIT_CODE_INVALID_ARGUMENT) | ||
} | ||
} | ||
|
||
export function validateArgs(args: OptionValues) { | ||
requireCheckinOrSolveWeeklyMission(args) | ||
} |