Skip to content

Commit

Permalink
Fix showSystem default value
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 64f9ac0 commit 0853615
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bin/config/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Default: false`,
showSystem: {
group: REPORT,
describe: `Show hardware and software information.
Default: true when the "system" configuration property is set, false otherwise`,
Default: true when the result has a "system", false otherwise`,
},
showMetadata: {
group: REPORT,
Expand Down
6 changes: 0 additions & 6 deletions src/config/properties.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable max-lines */
import { cwd as getCwd } from 'process'

import isPlainObj from 'is-plain-obj'

import { normalizeLimit } from '../history/compare/normalize.js'
import { normalizeDelta } from '../history/delta/normalize.js'
import { getDefaultId, validateMerge } from '../history/merge/id.js'
Expand All @@ -22,7 +20,6 @@ import {
checkJson,
} from './check.js'
import { normalizeConfigPath, normalizeConfigGlob } from './path.js'
// eslint-disable-next-line import/max-dependencies
import { recurseConfigSelectors } from './select/normalize.js'

const METADATA_COMMANDS = new Set(['show', 'remove'])
Expand Down Expand Up @@ -207,9 +204,6 @@ export const CONFIG_PROPS = {
},
showSystem: {
commands: 'report',
default(name, { config: { system } }) {
return isPlainObj(system) && Object.keys(system).length !== 0
},
normalize(value, name) {
checkBoolean(value, name)
},
Expand Down
15 changes: 14 additions & 1 deletion src/top/omit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ export const omitMetadataFooterProps = function (result) {
// This only impacts the footer, not the properties of the target result nor
// history results.
export const omitFooterProps = function (footer, showMetadata, showSystem) {
const showSystemA = addShowSystemDefault(footer.systems, showSystem)
const footerA = maybeOmit(footer, showMetadata, METADATA_FOOTER_PROPS)
const systems = footerA.systems.map((system) =>
omitFooterSystemProps(system, showMetadata, showSystem),
omitFooterSystemProps(system, showMetadata, showSystemA),
)
return { ...footerA, systems }
}

// By default, we show systems only if the result was created with the `system`
// configuration property, i.e. there are some system dimensions
const addShowSystemDefault = function (systems, showSystem) {
return showSystem === undefined
? systems.some(hasSystemDimensions)
: showSystem
}

const hasSystemDimensions = function ({ dimensions }) {
return Object.keys(dimensions).length !== 0
}

const omitFooterSystemProps = function (system, showMetadata, showSystem) {
const systemA = maybeOmit(system, showMetadata, METADATA_SYSTEM_PROPS)
const systemB = maybeOmit(systemA, showSystem, MAIN_SYSTEM_PROPS)
Expand Down

0 comments on commit 0853615

Please sign in to comment.