"use strict"; const Promise = require("bluebird"); const graphql = require("graphql"); const util = require("util"); const chalk = require("chalk"); const gql = require("./graphql/tag"); const api = require("./api/index"); function debugDisplay(results) { if (results.errors != null && results.errors.length > 0) { results.errors.forEach((graphqlError) => { let errorHeader; if (graphqlError.path != null) { errorHeader = `Error occurred for path: ${graphqlError.path.join(" -> ")}`; } else if (graphqlError.locations != null && graphqlError.locations.length > 0) { errorHeader = `Error occurred at line ${graphqlError.locations[0].line}, column ${graphqlError.locations[0].column}`; } else { errorHeader = "Error occurred in GraphQL"; } console.log(chalk.bgBlue.white(errorHeader)); let error = graphqlError.originalError; if (error != null) { if (error.showChain != null) { console.log(error.showChain()); } else { console.log(error.stack); } } else { console.log(graphqlError.stack); } console.log("-----------------------------"); }); } console.log(util.inspect(results.data, {colors: true, depth: null})); } // ############################################### let makeQuery = api(); // FIXME: If we intend to target macOS, a lot of whitespace-based output splitting won't work: https://www.mail-archive.com/austin-group-l@opengroup.org/msg01678.html // findmnt --json -o +SIZE,AVAIL // -> map back to mountPoint stuff? // blkid // to discover the filesystem that a given path exists on: stat -c %m // partx // (rest of util-linux) // memory usage: /proc/meminfo return Promise.try(() => { let query = gql` # query SomeDrives($drivePaths: [String]) { query SomeDrives { hardware { drives { path interface model modelFamily smartAvailable smartEnabled serialNumber wwn firmwareVersion size rpm logicalSectorSize physicalSectorSize formFactor ataVersion sataVersion smartHealth # smartAttributes { # name # type # value # failingNow # flags { # affectsPerformance # indicatesFailure # } # } # blockDevice { # removable # children { # name # mountpoint # size # } # } } } # resources { # blockDevices { # name # mountpoint # size # deviceNumber # removable # readOnly # parent { name } # children { # name # mountpoint # size # deviceNumber # removable # readOnly # parent { name } # } # } # lvm { # physicalVolumes { # path # blockDevice { # name # deviceNumber # } # volumeGroup { # name # } # format # size # freeSpace # duplicate # allocatable # used # exported # missing # } # } # } } `; return makeQuery(query, { // drivePaths: ["/dev/sda", "/dev/sdb"] }); }).then((results) => { debugDisplay(results); });