Skip to content

Commit

Permalink
--list-root-hubs option to include root hubs in list
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Aug 26, 2024
1 parent e074f2c commit 000a0d6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Changed

- Standard cyme list now excludes root_hubs (`--tree` shows them at root). `--lsusb` list mode will still show them.
- Standard cyme list now excludes root_hubs (`--tree` shows them as buses as before). `--lsusb` list mode will still show them. Use `--list-root-hubs` (or in config) to include them in the cyme list on Linux as before.

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion doc/_cyme
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ replace\:"Mask by replacing length with random chars"))' \
'-m[Print more blocks by default at each verbosity]' \
'--more[Print more blocks by default at each verbosity]' \
'--sort-buses[Sort devices by bus number]' \
'--hide-buses[Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs]' \
'--hide-buses[Hide empty buses when printing tree; those with no devices]' \
'--hide-hubs[Hide empty hubs when printing tree; those with no devices. When listing will hide hubs regardless of whether empty of not]' \
'--list-root-hubs[Show root hubs when listing; Linux only]' \
'--decimal[Show base16 values as base10 decimal instead]' \
'--no-padding[Disable padding to align blocks - will cause --headings to become maligned]' \
'--no-color[Disable coloured output, can also use NO_COLOR environment variable]' \
Expand Down
3 changes: 2 additions & 1 deletion doc/_cyme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ Register-ArgumentCompleter -Native -CommandName 'cyme' -ScriptBlock {
[CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Print more blocks by default at each verbosity')
[CompletionResult]::new('--more', 'more', [CompletionResultType]::ParameterName, 'Print more blocks by default at each verbosity')
[CompletionResult]::new('--sort-buses', 'sort-buses', [CompletionResultType]::ParameterName, 'Sort devices by bus number')
[CompletionResult]::new('--hide-buses', 'hide-buses', [CompletionResultType]::ParameterName, 'Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs')
[CompletionResult]::new('--hide-buses', 'hide-buses', [CompletionResultType]::ParameterName, 'Hide empty buses when printing tree; those with no devices')
[CompletionResult]::new('--hide-hubs', 'hide-hubs', [CompletionResultType]::ParameterName, 'Hide empty hubs when printing tree; those with no devices. When listing will hide hubs regardless of whether empty of not')
[CompletionResult]::new('--list-root-hubs', 'list-root-hubs', [CompletionResultType]::ParameterName, 'Show root hubs when listing; Linux only')
[CompletionResult]::new('--decimal', 'decimal', [CompletionResultType]::ParameterName, 'Show base16 values as base10 decimal instead')
[CompletionResult]::new('--no-padding', 'no-padding', [CompletionResultType]::ParameterName, 'Disable padding to align blocks - will cause --headings to become maligned')
[CompletionResult]::new('--no-color', 'no-color', [CompletionResultType]::ParameterName, 'Disable coloured output, can also use NO_COLOR environment variable')
Expand Down
7 changes: 5 additions & 2 deletions doc/cyme.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH NAME
cyme \- List system USB buses and devices; a modern cross\-platform `lsusb`
.SH SYNOPSIS
\fBcyme\fR [\fB\-l\fR|\fB\-\-lsusb\fR] [\fB\-t\fR|\fB\-\-tree\fR] [\fB\-d\fR|\fB\-\-vidpid\fR] [\fB\-s\fR|\fB\-\-show\fR] [\fB\-D\fR|\fB\-\-device\fR] [\fB\-\-filter\-name\fR] [\fB\-\-filter\-serial\fR] [\fB\-\-filter\-class\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-b\fR|\fB\-\-blocks\fR] [\fB\-\-bus\-blocks\fR] [\fB\-\-config\-blocks\fR] [\fB\-\-interface\-blocks\fR] [\fB\-\-endpoint\-blocks\fR] [\fB\-m\fR|\fB\-\-more\fR] [\fB\-\-sort\-devices\fR] [\fB\-\-sort\-buses\fR] [\fB\-\-group\-devices\fR] [\fB\-\-hide\-buses\fR] [\fB\-\-hide\-hubs\fR] [\fB\-\-decimal\fR] [\fB\-\-no\-padding\fR] [\fB\-\-color\fR] [\fB\-\-encoding\fR] [\fB\-\-icon\fR] [\fB\-\-headings\fR] [\fB\-\-json\fR] [\fB\-\-from\-json\fR] [\fB\-F\fR|\fB\-\-force\-libusb\fR] [\fB\-c\fR|\fB\-\-config\fR] [\fB\-z\fR|\fB\-\-debug\fR]... [\fB\-\-mask\-serials\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR]
\fBcyme\fR [\fB\-l\fR|\fB\-\-lsusb\fR] [\fB\-t\fR|\fB\-\-tree\fR] [\fB\-d\fR|\fB\-\-vidpid\fR] [\fB\-s\fR|\fB\-\-show\fR] [\fB\-D\fR|\fB\-\-device\fR] [\fB\-\-filter\-name\fR] [\fB\-\-filter\-serial\fR] [\fB\-\-filter\-class\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-b\fR|\fB\-\-blocks\fR] [\fB\-\-bus\-blocks\fR] [\fB\-\-config\-blocks\fR] [\fB\-\-interface\-blocks\fR] [\fB\-\-endpoint\-blocks\fR] [\fB\-m\fR|\fB\-\-more\fR] [\fB\-\-sort\-devices\fR] [\fB\-\-sort\-buses\fR] [\fB\-\-group\-devices\fR] [\fB\-\-hide\-buses\fR] [\fB\-\-hide\-hubs\fR] [\fB\-\-list\-root\-hubs\fR] [\fB\-\-decimal\fR] [\fB\-\-no\-padding\fR] [\fB\-\-color\fR] [\fB\-\-encoding\fR] [\fB\-\-icon\fR] [\fB\-\-headings\fR] [\fB\-\-json\fR] [\fB\-\-from\-json\fR] [\fB\-F\fR|\fB\-\-force\-libusb\fR] [\fB\-c\fR|\fB\-\-config\fR] [\fB\-z\fR|\fB\-\-debug\fR]... [\fB\-\-mask\-serials\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR]
.SH DESCRIPTION
List system USB buses and devices; a modern cross\-platform `lsusb`
.SH OPTIONS
Expand Down Expand Up @@ -304,11 +304,14 @@ bus: Group into buses with bus info as heading \- like a flat tree
.RE
.TP
\fB\-\-hide\-buses\fR
Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs
Hide empty buses when printing tree; those with no devices
.TP
\fB\-\-hide\-hubs\fR
Hide empty hubs when printing tree; those with no devices. When listing will hide hubs regardless of whether empty of not
.TP
\fB\-\-list\-root\-hubs\fR
Show root hubs when listing; Linux only
.TP
\fB\-\-decimal\fR
Show base16 values as base10 decimal instead
.TP
Expand Down
2 changes: 1 addition & 1 deletion doc/cyme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _cyme() {

case "${cmd}" in
cyme)
opts="-l -t -d -s -D -v -b -m -F -c -z -h -V --lsusb --tree --vidpid --show --device --filter-name --filter-serial --filter-class --verbose --blocks --bus-blocks --config-blocks --interface-blocks --endpoint-blocks --more --sort-devices --sort-buses --group-devices --hide-buses --hide-hubs --decimal --no-padding --color --no-color --encoding --ascii --no-icons --icon --headings --json --from-json --force-libusb --config --debug --mask-serials --gen --help --version"
opts="-l -t -d -s -D -v -b -m -F -c -z -h -V --lsusb --tree --vidpid --show --device --filter-name --filter-serial --filter-class --verbose --blocks --bus-blocks --config-blocks --interface-blocks --endpoint-blocks --more --sort-devices --sort-buses --group-devices --hide-buses --hide-hubs --list-root-hubs --decimal --no-padding --color --no-color --encoding --ascii --no-icons --icon --headings --json --from-json --force-libusb --config --debug --mask-serials --gen --help --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
3 changes: 2 additions & 1 deletion doc/cyme.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ complete -c cyme -s t -l tree -d 'Dump USB device hierarchy as a tree'
complete -c cyme -s v -l verbose -d 'Verbosity level: 1 prints device configurations; 2 prints interfaces; 3 prints interface endpoints; 4 prints everything and all blocks'
complete -c cyme -s m -l more -d 'Print more blocks by default at each verbosity'
complete -c cyme -l sort-buses -d 'Sort devices by bus number'
complete -c cyme -l hide-buses -d 'Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs'
complete -c cyme -l hide-buses -d 'Hide empty buses when printing tree; those with no devices'
complete -c cyme -l hide-hubs -d 'Hide empty hubs when printing tree; those with no devices. When listing will hide hubs regardless of whether empty of not'
complete -c cyme -l list-root-hubs -d 'Show root hubs when listing; Linux only'
complete -c cyme -l decimal -d 'Show base16 values as base10 decimal instead'
complete -c cyme -l no-padding -d 'Disable padding to align blocks - will cause --headings to become maligned'
complete -c cyme -l no-color -d 'Disable coloured output, can also use NO_COLOR environment variable'
Expand Down
1 change: 1 addition & 0 deletions doc/cyme_example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"more": false,
"hide-buses": false,
"hide-hubs": false,
"list-root-hubs": false,
"decimal": false,
"no-padding": false,
"ascii": false,
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ pub struct Config {
pub verbose: u8,
/// Print more blocks by default at each verbosity
pub more: bool,
/// Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs
/// Hide empty buses when printing tree; those with no devices.
pub hide_buses: bool,
/// Hide empty hubs when printing tree; those with no devices. When listing will hide hubs regardless of whether empty of not
pub hide_hubs: bool,
/// Show root hubs when listing; Linux only
pub list_root_hubs: bool,
/// Show base16 values as base10 decimal instead
pub decimal: bool,
/// Disable padding to align blocks
Expand Down
24 changes: 11 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct Args {
#[arg(long, value_enum, default_value_t = Default::default())]
group_devices: display::Group,

/// Hide empty buses when printing tree; those with no devices. When listing will hide Linux root_hubs
/// Hide empty buses when printing tree; those with no devices.
// these are a bit confusing, could make value enum with hide_empty, hide...
#[arg(long, default_value_t = false)]
hide_buses: bool,
Expand All @@ -99,6 +99,10 @@ struct Args {
#[arg(long, default_value_t = false)]
hide_hubs: bool,

/// Show root hubs when listing; Linux only
#[arg(long, default_value_t = false)]
list_root_hubs: bool,

/// Show base16 values as base10 decimal instead
#[arg(long, default_value_t = false)]
decimal: bool,
Expand Down Expand Up @@ -195,6 +199,7 @@ fn merge_config(c: &Config, a: &mut Args) {
a.more |= c.more;
a.hide_buses |= c.hide_buses;
a.hide_hubs |= c.hide_hubs;
a.list_root_hubs |= c.list_root_hubs;
a.decimal |= c.decimal;
a.no_padding |= c.no_padding;
a.ascii |= c.ascii;
Expand Down Expand Up @@ -583,25 +588,18 @@ fn cyme() -> Result<()> {
// exclude root hubs unless:
// * lsusb compat (shows root_hubs)
// * json - for --from-json support
// * group by bus - wouldn't make sense to exclude root hubs
// * not hide_buses - user wants to hide all buses including root_hubs
f.no_exclude_root_hub =
(args.lsusb || args.json || matches!(args.group_devices, display::Group::Bus))
&& !args.hide_buses;
// * list_root_hubs - user wants to see root hubs in list
f.no_exclude_root_hub = args.lsusb || args.json || args.list_root_hubs;

Some(f)
} else {
// ensure exclude root hubs on Linux unless:
// exclude root hubs (on Linux) unless:
// * lsusb compat (shows root_hubs)
// * json - for --from-json support
// * group by bus - wouldn't make sense to exclude root hubs
// * not hide_buses - user wants to hide all buses including root_hubs
// * list_root_hubs - user wants to see root hubs in list
if cfg!(target_os = "linux") {
Some(system_profiler::USBFilter {
no_exclude_root_hub: (args.lsusb
|| args.json
|| matches!(args.group_devices, display::Group::Bus))
&& !args.hide_buses,
no_exclude_root_hub: (args.lsusb || args.json || args.list_root_hubs),
..Default::default()
})
} else {
Expand Down

0 comments on commit 000a0d6

Please sign in to comment.