diff options
-rw-r--r-- | libpiny/lib/Piny/Config.pm | 20 | ||||
-rwxr-xr-x | pinyadmin/sbin/pinyconfig | 48 |
2 files changed, 50 insertions, 18 deletions
diff --git a/libpiny/lib/Piny/Config.pm b/libpiny/lib/Piny/Config.pm index 9f43c19..d37fa67 100644 --- a/libpiny/lib/Piny/Config.pm +++ b/libpiny/lib/Piny/Config.pm @@ -162,6 +162,24 @@ sub save { $cs->write( $s->confpath ); }; +# Dump all tweakables + +my @tweakables = ( ); + +sub all_tweakables { + my ( $s ) = @_; + + my $r = { }; + + foreach my $t ( @tweakables ) { + eval { + $r->{$t} = $s->$t; + }; + }; + + return $r; +}; + # Tweakable helper sub tweakable { @@ -174,6 +192,8 @@ sub tweakable { if ( $attrname =~ /_/ ) { croak "Illegal attribute name $attrname! (use only one underbar)"; }; + push @tweakables, $attr; + has $attr => ( is => 'rw' , isa => $isa diff --git a/pinyadmin/sbin/pinyconfig b/pinyadmin/sbin/pinyconfig index e78cf3c..8496cc7 100755 --- a/pinyadmin/sbin/pinyconfig +++ b/pinyadmin/sbin/pinyconfig @@ -7,13 +7,10 @@ use Piny; my ( $reponame, $attr, $value ) = @ARGV; -if ( not defined $reponame or not defined $attr ) { - die "Usage: $0 reponame|--user tweakable [value]\n"; +if ( not defined $reponame ) { + die "Usage: $0 reponame|--user [tweakable [value]]\n"; }; -$attr = lc $attr; -$attr =~ s/\./_/g; - my $config; if ( $reponame eq "--user" ) { @@ -22,23 +19,38 @@ if ( $reponame eq "--user" ) { $config = Piny::Repo->new( $reponame )->config; }; -if ( defined $value ) { +if ( not defined $attr ) { + + my $tweakables = $config->all_tweakables; + + foreach my $t ( sort keys %$tweakables ) { + print "$t => " . $tweakables->{$t} . "\n"; + }; + +} else { + + $attr = lc $attr; + $attr =~ s/\./_/g; + + if ( defined $value ) { + undef $@; + eval { + $config->$attr( $value ); + }; + if ( $@ ) { + print STDERR "$attr is not a legal tweakable, or $value is not a legal value for that tweakable.\n$@\n"; + }; + if ( $value ne $config->$attr ) { + print STDERR "Failed to set $attr (perhaps an override is in place)\n"; + }; + }; + undef $@; eval { - $config->$attr( $value ); + print "$attr = " . $config->$attr . "\n"; }; if ( $@ ) { - print STDERR "$attr is not a legal tweakable, or $value is not a legal value for that tweakable.\n$@\n"; + print STDERR "$attr is not a legal tweakable, or its current value is illegal.\n$@\n"; }; - if ( $value ne $config->$attr ) { - print STDERR "Failed to set $attr (perhaps an override is in place)\n"; - }; -}; -undef $@; -eval { - print "$attr = " . $config->$attr . "\n"; -}; -if ( $@ ) { - print STDERR "$attr is not a legal tweakable, or its current value is illegal.\n$@\n"; }; |