-Satisfy request 1965017, gettab and nodels now have -H support and default to no names if a single value is requested

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1443 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-05-19 17:59:56 +00:00
parent 05267bdd4d
commit f37f0a917c
3 changed files with 26 additions and 10 deletions

View File

@ -4,7 +4,7 @@ B<gettab> - search through tables using keys and return attributes.
=head1 SYNOPSIS
B<gettab> I<key=value,... table.attribute ...>
B<gettab> [B<-H> | B<--with-fieldname>] I<key=value,... table.attribute ...>
B<gettab> [B<-?> | B<-h> | B<--help>]
@ -17,6 +17,10 @@ row, the specified attributes are displayed.
=over 10
=item B<-H|--with-fieldname>
Always display table.column description next to result
=item B<-?|-h|--help>
Display usage message.
@ -67,4 +71,4 @@ The output would be similar to:
=head1 SEE ALSO
nodels(1), chtab(1), tabdump(1)
nodels(1), chtab(1), tabdump(1)

View File

@ -5,9 +5,9 @@ B<nodels> - lists the nodes in the noderange.
=head1 SYNOPSIS
B<nodels> [I<noderange>] [I<table.column> | I<shortname>] [I<...>]
B<nodels> [I<noderange>] [B<-H> | B<--with-fieldname>] [I<table.column> | I<shortname>] [I<...>]
B<nodels> [I<noderange>] [I<table>]
B<nodels> [I<noderange>] [B<-H> | B<--with-fieldname>] [I<table>]
B<nodels> {B<-v> | B<--version>}
@ -56,6 +56,10 @@ will not do this, instead they will just display the single regular expression r
Command Version.
=item B<-H|--with-fieldname>
Force display table name and column name context for each result
=item B<-?|-h|--help>
Display usage message.

View File

@ -129,11 +129,12 @@ sub gettab
my $req = shift;
my $callback = shift;
my $HELP;
my $NOTERSE;
sub gettab_usage {
my $exitcode = shift @_;
my %rsp;
push @{$rsp{data}}, "Usage: gettab key=value,... table.attribute ...";
push @{$rsp{data}}, "Usage: gettab [-H|--with-fieldname] key=value,... table.attribute ...";
push @{$rsp{data}}, " gettab [-?|-h|--help]";
if ($exitcode) { $rsp{errorcode} = $exitcode; }
$callback->(\%rsp);
@ -141,7 +142,7 @@ sub gettab
# Process arguments
@ARGV = @{$req->{arg}};
if (!GetOptions('h|?|help' => \$HELP)) { gettab_usage(1); return; }
if (!GetOptions('h|?|help' => \$HELP,'H|with-fieldname' => \$NOTERSE)) { gettab_usage(1); return; }
if ($HELP) { gettab_usage(0); return; }
if (scalar(@ARGV)<2) { gettab_usage(1); return; }
@ -163,6 +164,9 @@ sub gettab
# Group the columns asked for by table (so we can do 1 query per table)
my %tabhash;
my $terse = 2;
if ($NOTERSE) {
$terse = 0;
}
foreach my $tabvalue (@ARGV)
{
$terse--;
@ -186,7 +190,7 @@ sub gettab
(my $ent) = $tab->getAttribs(\%keyhash, keys %{$tabhash{$tabn}});
foreach my $coln (keys %{$tabhash{$tabn}})
{
if ($terse) {
if ($terse > 0) {
$callback->({data => ["" . $ent->{$coln}]});
} else {
$callback->({data => ["$tabn.$coln: " . $ent->{$coln}]});
@ -739,7 +743,7 @@ sub nodels
my $exitcode = shift @_;
my %rsp;
push @{$rsp{data}}, "Usage:";
push @{$rsp{data}}, " nodels [noderange] [table.attribute | shortname] [...]";
push @{$rsp{data}}, " nodels [noderange] [-H|--with-fieldname] [table.attribute | shortname] [...]";
push @{$rsp{data}}, " nodels {-v|--version}";
push @{$rsp{data}}, " nodels [-?|-h|--help]";
##### xcat 1.2 nodels usage:
@ -758,7 +762,8 @@ sub nodels
}
@ARGV = @{$args};
if (!GetOptions('h|?|help' => \$HELP, 'v|version' => \$VERSION,) ) { nodels_usage(1); return; }
my $NOTERSE;
if (!GetOptions('h|?|help' => \$HELP, 'H|with-fieldname' => \$NOTERSE, 'v|version' => \$VERSION,) ) { nodels_usage(1); return; }
# Help
if ($HELP) { nodels_usage(0); return; }
@ -781,6 +786,9 @@ sub nodels
# }
my $argc = @ARGV;
my $terse = 2;
if ($NOTERSE) {
$terse = 0;
}
if (@$nodes > 0 or $noderange)
{ #Make sure that there are zero nodes *and* that a noderange wasn't requested
@ -849,7 +857,7 @@ sub nodels
foreach (keys %$rec)
{
my %datseg;
unless ($terse) {
unless ($terse > 0) {
$datseg{data}->[0]->{desc} = [$labels{$_}];
}
$datseg{data}->[0]->{contents} = [$rec->{$_}];