app.lsblk
app.lsblk is a thin command-construction wrapper around the util-linux
lsblk binary. It returns ward.process.cmd(...) objects.
lsblk supports JSON output (-J), and this wrapper models that flag.
This module constructs
ward.process.cmd(...)invocations; it does not parse output. consumers can usewardlib.tools.out(or their own parsing) on the:output()result.
Import
local Lsblk = require("wardlib.app.lsblk").Lsblk
Privilege escalation
Most lsblk listing operations are unprivileged, but some environments
restrict access to block-device metadata. If you need elevation, use
wardlib.tools.with.
local with = require("wardlib.tools.with")
local cmd = Lsblk.list(nil, { json = true })
local data = with.with(with.middleware.sudo(), cmd):output()
Options: LsblkOpts
json: boolean?—-J/--jsonoutput: string|string[]?—-o <cols>(string or array joined by commas)bytes: boolean?—-bpaths: boolean?—-pfs: boolean?—-fall: boolean?—-anodeps: boolean?—-dlist: boolean?—-lraw: boolean?—-rnoheadings: boolean?—-nsort: string?—--sort <col>tree: boolean?—--treeextra: string[]?— appended after modeled options
API
Lsblk.list(devices, opts)
Construct an lsblk command.
Builds: lsblk <opts...> [devices...]
Lsblk.list(devices: string|string[]|nil, opts: LsblkOpts|nil) -> ward.Cmd
Notes:
- If
devicesisnil,lsblkenumerates all block devices.
Examples
Parse JSON output
local out = require("wardlib.tools.out")
local data = out.cmd(Lsblk.list(nil, { json = true }))
:label("lsblk -J")
:json()
-- util-linux typically returns: { blockdevices = [...] }
local devs = data.blockdevices or {}
Select specific columns
-- lsblk -o NAME,SIZE,TYPE,MOUNTPOINT -J
local out = require("wardlib.tools.out")
local data = out.cmd(Lsblk.list(nil, {
json = true,
output = { "NAME", "SIZE", "TYPE", "MOUNTPOINT" },
}))
:label("lsblk -o ... -J")
:json()
Raw, no headings
-- lsblk -nrp -o NAME,SIZE
Lsblk.list(nil, { noheadings = true, raw = true, paths = true, output = { "NAME", "SIZE" } }):run()