Skip to content

Commit

Permalink
Fix CLI flags parsing of config selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 1a8a552 commit b90ac2b
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 37 deletions.
2 changes: 0 additions & 2 deletions src/bin/config/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const ALL_CONFIG = {
config: {
group: CONFIG,
alias: 'c',
string: true,
describe: `Configuration file location.
This can be:
Expand Down Expand Up @@ -34,7 +33,6 @@ The configuration property must then be an object where:
},
cwd: {
group: CONFIG,
string: true,
requiresArg: true,
describe: `Customize the current directory used:
- In task files
Expand Down
2 changes: 0 additions & 2 deletions src/bin/config/combinations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const COMBINATIONS_CONFIG = {
tasks: {
group: TASKS,
alias: 't',
string: true,
requiresArg: true,
describe: `Path to the tasks files.
This should only specify their main files.
Expand All @@ -20,7 +19,6 @@ Can be a globbing pattern.`,
},
runner: {
group: TASKS,
string: true,
describe: `Tasks' programming language or platform.
Can be specified several times.
Expand Down
1 change: 0 additions & 1 deletion src/bin/config/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const REMOVE_CONFIG = {
force: {
group: REPORT,
alias: 'f',
boolean: true,
describe: `Do not report the result nor ask for confirmation.
Default: true unless the terminal is interactive.`,
},
Expand Down
11 changes: 0 additions & 11 deletions src/bin/config/report.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable max-lines */
import { REPORT, HISTORY } from './groups.js'

// Configuration shared by commands that report results: `run`, `show`, `remove`
export const REPORT_CONFIG = {
reporter: {
group: REPORT,
alias: 'r',
string: true,
describe: `Modules to report the result.
Can be empty, if no reporters should be used.
Expand All @@ -33,7 +31,6 @@ reporter.`,
output: {
group: REPORT,
alias: 'o',
string: true,
requiresArg: true,
describe: `Output the result to "stdout" or to a file path.
Expand All @@ -46,7 +43,6 @@ The default value depends on the reporter`,
},
colors: {
group: REPORT,
boolean: true,
describe: `Use colors in output.
Default: true if the output is an interactive terminal.`,
},
Expand All @@ -59,35 +55,29 @@ The id can be any identifier: task, runner, system, variation.`,
},
showTitles: {
group: REPORT,
boolean: true,
describe: `Show titles instead of identifiers.
Default: false`,
},
showSystem: {
group: REPORT,
boolean: true,
describe: `Show hardware and software information.
Default: true when the "system" configuration property is set, false otherwise`,
},
showMetadata: {
group: REPORT,
boolean: true,
describe: `Show metadata such as id, timestamp, commit/branch or CI build.
Default: true for command "show" and "remove", false otherwise`,
},
showPrecision: {
group: REPORT,
boolean: true,
describe: `Show the results confidence interval.
Default: false.`,
},
showDiff: {
group: HISTORY,
boolean: true,
describe: `Show the difference with previous results.
Default: true if the output is an interactive terminal.`,
},
// We do not use `number: true` to avoid parsing invalid numbers as NaN
limit: {
group: HISTORY,
alias: 'l',
Expand All @@ -102,4 +92,3 @@ Negative numbers like "-50" can be used for decreases instead.
Default: none`,
},
}
/* eslint-enable max-lines */
5 changes: 0 additions & 5 deletions src/bin/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TASKS, REPORT, HISTORY } from './groups.js'

// Configuration specific to `run`
export const RUN_CONFIG = {
// We do not use `number: true` to avoid parsing invalid numbers as NaN
precision: {
group: TASKS,
alias: 'p',
Expand All @@ -14,20 +13,17 @@ A higher level increases precision but makes the benchmark last longer.`,
quiet: {
group: REPORT,
alias: 'q',
boolean: true,
describe: `Preview the results and display a progress bar.
Reporters are still used.
Default: false if the output is an interactive terminal.`,
},
save: {
group: HISTORY,
boolean: true,
describe: `Save the results.
Default: false`,
},
merge: {
group: HISTORY,
string: true,
requiresArg: true,
describe: `Merge this result with a previous one.
The value is the previous result's identifier.
Expand All @@ -38,7 +34,6 @@ Default: none`,
},
outliers: {
group: TASKS,
boolean: true,
describe: `Some measures can be extremely slower than others.
Most of the times, those outliers are due to concurrent logic unrelated to
your tasks such as garbage collection or OS background processes.
Expand Down
1 change: 0 additions & 1 deletion src/bin/config/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const SELECT_CONFIG = {
select: {
group: SELECT,
alias: 's',
string: true,
describe: `Select only specific combinations.
The value is a space-separated list of identifiers to select.
Those can be the identifiers of any task, runner, system or variation.
Expand Down
7 changes: 7 additions & 0 deletions src/bin/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import filterObj from 'filter-obj'
import mapObj from 'map-obj'

// We do not use yargs types as it conflicts with our own validation and
// normalization logic, e.g.:
// - `number` parses invalid numbers as NaN
// - `boolean` parses strings as boolean
// - many configuration properties are objects or are polymorphic
// One downside is that typing then relies on yargs' guess, which is fine:
// - string configuration properties cannot be "true", "false" or "1"
export const parseCliFlags = function (yargs) {
const {
_: [command = DEFAULT_COMMAND],
Expand Down
21 changes: 6 additions & 15 deletions src/config/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ const normalizePropValue = function (value, propName, name) {
return newValue === undefined ? value : newValue
}

const validateInputs = function (value, name) {
checkJsonObject(value, name)
}

const validateOutliers = function (value, name) {
checkBoolean(value, name)
}

const normalizeReporter = function (value, name) {
const valueA = normalizeOptionalArray(value)
checkDefinedStringArray(valueA, name)
Expand All @@ -64,10 +56,6 @@ const normalizeSelect = function (value, name) {
return valueA
}

const validateSystem = function (system) {
checkStringsObject(system, 'system')
}

const normalizeTasks = function (value, name) {
const valueA = normalizeOptionalArray(value)
checkDefinedStringArray(valueA, name)
Expand All @@ -81,15 +69,18 @@ const validateTitles = function (value, name) {
}

const NORMALIZERS = {
inputs: validateInputs,
inputs: checkJsonObject,
limit: normalizeLimit,
merge: validateMerge,
outliers: validateOutliers,
outliers: checkBoolean,
precision: normalizePrecision,
reporter: normalizeReporter,
runner: normalizeRunner,
select: normalizeSelect,
system: validateSystem,
showDiff: checkBoolean,
showPrecision: checkBoolean,
showTitles: checkBoolean,
system: checkStringsObject,
tasks: normalizeTasks,
titles: validateTitles,
}

0 comments on commit b90ac2b

Please sign in to comment.