feat(vhd-cli info): human format some fields
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
"cli-progress": "^3.1.0",
|
||||
"exec-promise": "^0.7.0",
|
||||
"getopts": "^2.2.3",
|
||||
"human-format": "^0.11.0",
|
||||
"vhd-lib": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,34 @@
|
||||
import { VhdFile } from 'vhd-lib'
|
||||
import { Constants, VhdFile } from 'vhd-lib'
|
||||
import { getHandler } from '@xen-orchestra/fs'
|
||||
import { resolve } from 'path'
|
||||
import humanFormat from 'human-format'
|
||||
import invert from 'lodash/invert.js'
|
||||
|
||||
const { PLATFORMS } = Constants
|
||||
|
||||
const DISK_TYPES_MAP = invert(Constants.DISK_TYPES)
|
||||
const PLATFORMS_MAP = invert(PLATFORMS)
|
||||
|
||||
const MAPPERS = {
|
||||
bytes: humanFormat.bytes,
|
||||
date: _ => (_ !== 0 ? new Date(_) : 0),
|
||||
diskType: _ => DISK_TYPES_MAP[_],
|
||||
platform: _ => PLATFORMS_MAP[_],
|
||||
}
|
||||
function mapProperties(object, mapping) {
|
||||
const result = { ...object }
|
||||
for (const prop of Object.keys(mapping)) {
|
||||
const value = object[prop]
|
||||
if (value !== undefined) {
|
||||
let mapper = mapping[prop]
|
||||
if (typeof mapper === 'string') {
|
||||
mapper = MAPPERS[mapper]
|
||||
}
|
||||
result[prop] = mapper(value)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default async args => {
|
||||
const vhd = new VhdFile(getHandler({ url: 'file:///' }), resolve(args[0]))
|
||||
@@ -12,6 +40,26 @@ export default async args => {
|
||||
await vhd.readHeaderAndFooter(false)
|
||||
}
|
||||
|
||||
console.log(vhd.header)
|
||||
console.log(vhd.footer)
|
||||
console.log(
|
||||
mapProperties(vhd.footer, {
|
||||
currentSize: 'bytes',
|
||||
diskType: 'diskType',
|
||||
originalSize: 'bytes',
|
||||
timestamp: 'date',
|
||||
})
|
||||
)
|
||||
|
||||
console.log(
|
||||
mapProperties(vhd.header, {
|
||||
blockSize: 'bytes',
|
||||
parentTimestamp: 'date',
|
||||
parentLocatorEntry: _ =>
|
||||
_.filter(_ => _.platformCode !== PLATFORMS.NONE) // hide empty
|
||||
.map(_ =>
|
||||
mapProperties(_, {
|
||||
platformCode: 'platform',
|
||||
})
|
||||
),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12496,7 +12496,7 @@ ms@2.1.2:
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
ms@^2.1.1, ms@^2.1.2:
|
||||
ms@^2.1.1, ms@^2.1.2, ms@^2.1.3:
|
||||
version "2.1.3"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
|
||||
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
|
||||
|
||||
Reference in New Issue
Block a user