Commit 8852ad88 authored by Leigh B Stoller's avatar Leigh B Stoller

Add -c option to print out the value in clean mode, suitable for

backtick operation from scripts.
parent 25ada4a3
#!/usr/bin/perl -wT #!/usr/bin/perl -w
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group. # Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -31,9 +31,10 @@ sub usage() ...@@ -31,9 +31,10 @@ sub usage()
"setsitevar\n". "setsitevar\n".
" - displays list of all sitevar names and values.\n". " - displays list of all sitevar names and values.\n".
"\n". "\n".
"setsitevar <variablename>\n". "setsitevar [-c] <variablename>\n".
" - displays name, description, value, \n". " - displays name, description, value, \n".
" and default value for <variablename>.\n". " and default value for <variablename>.\n".
" With -c option, just display current value.\n".
"\n". "\n".
"setsitevar <variablename> -\n". "setsitevar <variablename> -\n".
" - sets <variablename> to default value.\n". " - sets <variablename> to default value.\n".
...@@ -43,6 +44,8 @@ sub usage() ...@@ -43,6 +44,8 @@ sub usage()
exit(-1); exit(-1);
} }
my $optlist = "dc";
my $curvalue = 0;
# #
# Configure variables # Configure variables
...@@ -55,12 +58,23 @@ use libdb; ...@@ -55,12 +58,23 @@ use libdb;
# #
$| = 1; $| = 1;
$name = shift; #
# Check args.
if (defined $name && $name eq "-h") { #
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"h"})) {
usage(); usage();
} }
if (defined($options{"c"})) {
$curvalue = 1;
}
usage()
if (!@ARGV);
$name = shift;
$value = shift; $value = shift;
shift and usage(); # too many args shift and usage(); # too many args
...@@ -110,6 +124,14 @@ if ($result->numrows == 0) { ...@@ -110,6 +124,14 @@ if ($result->numrows == 0) {
# List a specific sitevar in detail # List a specific sitevar in detail
# #
if (! defined $value) { if (! defined $value) {
if ($curvalue) {
if (defined $currentvalue) {
print "$currentvalue\n";
} else {
print "$default\n";
}
exit(0)
}
print "sitevar name: $name\n". print "sitevar name: $name\n".
"description: $desc\n". "description: $desc\n".
"value: "; "value: ";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment