mirror of https://github.com/ipxe/ipxe.git
[util] Support reversed sort ordering when generating NIC list
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/71/head
parent
bc85368cdd
commit
eda9f4db61
|
@ -19,7 +19,7 @@ use Getopt::Long qw(GetOptions);
|
||||||
GetOptions(
|
GetOptions(
|
||||||
'help' => \( my $help = 0 ),
|
'help' => \( my $help = 0 ),
|
||||||
'format=s' => \( my $format = 'text' ),
|
'format=s' => \( my $format = 'text' ),
|
||||||
'sort=s' => \( my $sort = 'bus,ipxe_driver,ipxe_name' ),
|
'sort=s' => \( my $sort = 'bus-,ipxe_driver,ipxe_name' ),
|
||||||
'columns=s' => \( my $columns = 'bus,vendor_id,device_id,'
|
'columns=s' => \( my $columns = 'bus,vendor_id,device_id,'
|
||||||
. 'vendor_name,device_name,ipxe_driver,'
|
. 'vendor_name,device_name,ipxe_driver,'
|
||||||
. 'ipxe_name,ipxe_description,file,legacy_api'
|
. 'ipxe_name,ipxe_description,file,legacy_api'
|
||||||
|
@ -47,26 +47,26 @@ Output formats:
|
||||||
Column names (default order):
|
Column names (default order):
|
||||||
bus, vendor_id, device_id, vendor_name, device_name,
|
bus, vendor_id, device_id, vendor_name, device_name,
|
||||||
ipxe_driver, ipxe_name, ipxe_description, file, legacy_api
|
ipxe_driver, ipxe_name, ipxe_description, file, legacy_api
|
||||||
|
|
||||||
|
Default sort order (minus at the end means reverse sort):
|
||||||
|
bus-, ipxe_driver, ipxe_name
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
# Only load runtime requirements if actually in use
|
# Only load runtime requirements if actually in use
|
||||||
given($format) {
|
if ( $format =~ /csv/ ) {
|
||||||
when( /csv/ ) {
|
|
||||||
eval { require Text::CSV; };
|
eval { require Text::CSV; };
|
||||||
die("Please install Text::CSV CPAN module to use this feature.\n")
|
die("Please install Text::CSV CPAN module to use this feature.\n")
|
||||||
if $@;
|
if $@;
|
||||||
}
|
}
|
||||||
when( /json/ ) {
|
if ( $format =~ /json/ ) {
|
||||||
eval { require JSON; };
|
eval { require JSON; };
|
||||||
die("Please install JSON CPAN module to use this feature.\n")
|
die("Please install JSON CPAN module to use this feature.\n")
|
||||||
if $@;
|
if $@;
|
||||||
}
|
}
|
||||||
when( /html/ ) {
|
if ( $format =~ /html/ ) {
|
||||||
eval { require HTML::Entities; };
|
eval { require HTML::Entities; };
|
||||||
die("Please install HTML::Entities CPAN module to use this feature.\n")
|
die("Please install HTML::Entities CPAN module to use this feature.\n")
|
||||||
if $@;
|
if $@;
|
||||||
}
|
|
||||||
default { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Scan source dir and build NIC list
|
# Scan source dir and build NIC list
|
||||||
|
@ -339,9 +339,17 @@ sub sort_ipxe_nic_list {
|
||||||
my @sorted_list = @{ $ipxe_nic_list };
|
my @sorted_list = @{ $ipxe_nic_list };
|
||||||
while(@sort_column_names) {
|
while(@sort_column_names) {
|
||||||
my $column_name = pop @sort_column_names;
|
my $column_name = pop @sort_column_names;
|
||||||
|
my $reverse = substr($column_name, -1) eq '-' ? 1 : 0; # use reverse order if last character is minus
|
||||||
|
$column_name = substr($column_name, 0, -1) if $reverse; # chop of the minus
|
||||||
|
if ( $reverse ) {
|
||||||
|
@sorted_list = sort { ( $b->{$column_name} || "" ) cmp ( $a->{$column_name} || "" ) }
|
||||||
|
@sorted_list;
|
||||||
|
}
|
||||||
|
else {
|
||||||
@sorted_list = sort { ( $a->{$column_name} || "" ) cmp ( $b->{$column_name} || "" ) }
|
@sorted_list = sort { ( $a->{$column_name} || "" ) cmp ( $b->{$column_name} || "" ) }
|
||||||
@sorted_list;
|
@sorted_list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return \@sorted_list;
|
return \@sorted_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +367,7 @@ sub parse_columns_param {
|
||||||
sub is_valid_column {
|
sub is_valid_column {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $valid_column_map = {
|
my $valid_column_map = {
|
||||||
map { $_ => 1 }
|
map { $_ => 1, $_ . "-" => 1 } # also supports keyword with a - suffix
|
||||||
qw(
|
qw(
|
||||||
bus file legacy_api
|
bus file legacy_api
|
||||||
ipxe_driver ipxe_name ipxe_description
|
ipxe_driver ipxe_name ipxe_description
|
||||||
|
|
Loading…
Reference in New Issue