Skip to content

Commit

Permalink
move those comments to get some whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Nov 4, 2022
1 parent 6b9c70e commit 5f57475
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/cli/parse-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,30 @@ const normalizeFlagName = (flagName: string): string => {
const setCLIArg = (flags: ConfigFlags, rawArg: string, normalizedArg: string, value: CLIValueResult) => {
normalizedArg = dereferenceAlias(normalizedArg);

// We're setting a boolean!
if (readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizedArg)) {
// We're setting a boolean!
flags[normalizedArg] =
typeof value === 'string'
? Boolean(value)
: // no value was supplied, default to true
true;
flags.knownArgs.push(rawArg);
} else if (readOnlyArrayHasStringMember(STRING_CLI_FLAGS, normalizedArg)) {
// We're setting a string!
}

// We're setting a string!
else if (readOnlyArrayHasStringMember(STRING_CLI_FLAGS, normalizedArg)) {
if (typeof value === 'string') {
flags[normalizedArg] = value;
flags.knownArgs.push(rawArg);
flags.knownArgs.push(value);
} else {
throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
}
} else if (readOnlyArrayHasStringMember(STRING_ARRAY_CLI_FLAGS, normalizedArg)) {
// We're setting a string, but it's one where the user can pass multiple values,
// like `--reporters="default" --reporters="jest-junit"`
}

// We're setting a string, but it's one where the user can pass multiple values,
// like `--reporters="default" --reporters="jest-junit"`
else if (readOnlyArrayHasStringMember(STRING_ARRAY_CLI_FLAGS, normalizedArg)) {
if (typeof value === 'string') {
if (!Array.isArray(flags[normalizedArg])) {
flags[normalizedArg] = [];
Expand All @@ -261,8 +265,10 @@ const setCLIArg = (flags: ConfigFlags, rawArg: string, normalizedArg: string, va
} else {
throwCLIParsingError(rawArg, 'expected a string argument but received nothing');
}
} else if (readOnlyArrayHasStringMember(NUMBER_CLI_FLAGS, normalizedArg)) {
// We're setting a number!
}

// We're setting a number!
else if (readOnlyArrayHasStringMember(NUMBER_CLI_FLAGS, normalizedArg)) {
if (typeof value === 'string') {
const parsed = parseInt(value, 10);

Expand All @@ -278,8 +284,10 @@ const setCLIArg = (flags: ConfigFlags, rawArg: string, normalizedArg: string, va
} else {
throwCLIParsingError(rawArg, 'expected a number argument but received nothing');
}
} else if (readOnlyArrayHasStringMember(STRING_NUMBER_CLI_FLAGS, normalizedArg)) {
// We're setting a value which could be either a string _or_ a number
}

// We're setting a value which could be either a string _or_ a number
else if (readOnlyArrayHasStringMember(STRING_NUMBER_CLI_FLAGS, normalizedArg)) {
if (typeof value === 'string') {
if (CLI_ARG_STRING_REGEX.test(value)) {
// if it matches the regex we treat it like a string
Expand All @@ -302,8 +310,10 @@ const setCLIArg = (flags: ConfigFlags, rawArg: string, normalizedArg: string, va
} else {
throwCLIParsingError(rawArg, 'expected a string or a number but received nothing');
}
} else if (readOnlyArrayHasStringMember(LOG_LEVEL_CLI_FLAGS, normalizedArg)) {
// We're setting the log level, which can only be a set of specific string values
}

// We're setting the log level, which can only be a set of specific string values
else if (readOnlyArrayHasStringMember(LOG_LEVEL_CLI_FLAGS, normalizedArg)) {
if (typeof value === 'string') {
if (isLogLevel(value)) {
flags[normalizedArg] = value;
Expand Down

0 comments on commit 5f57475

Please sign in to comment.