Add --changesetup mode that allows easily changing options in a setup file.
authorJoey Hess <joey@kitenet.net>
Thu, 8 Jul 2010 18:01:52 +0000 (14:01 -0400)
committerJoey Hess <joey@kitenet.net>
Thu, 8 Jul 2010 18:05:39 +0000 (14:05 -0400)
debian/changelog
doc/setup.mdwn
doc/usage.mdwn
ikiwiki.in

index 9d88b5c9c73a318d49038b8f6be5c108ea4c9921..c340f89019fdd848efd11badfea67f159c3cc465 100644 (file)
@@ -5,6 +5,8 @@ ikiwiki (3.20100705) UNRELEASED; urgency=low
     comment moderation queue.
   * aggregate: Write timestamp next aggregation can happen to
     .ikiwiki/aggregatetime, to allow for more sophisticated cron jobs.
+  * Add --changesetup mode that allows easily changing options in a
+    setup file.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 05 Jul 2010 13:59:42 -0400
 
index 03fed3aa900d67019aa8a44472e5b6d927fc1636..266222cc3aad37950cacee3b88f7f66b5af259a9 100644 (file)
@@ -102,6 +102,12 @@ After making changes to this file, you need to tell ikiwiki to use it:
 
        % ikiwiki -setup foo.setup
 
+Alternatively, you can ask ikiwiki to change settings in the file for you:
+
+       % ikiwiki -changesetup foo.setup -plugin goodstuff
+
+See [[usage]] for more options.
+
 ## Customizing file locations
 
 As a wiki compiler, ikiwiki builds a wiki from files in a source directory,
index 2f87d60d5080a925ec8b4f98f3a992a3b217a192..840d105d2e5517e579f00ae67efe49f8f3bf3016 100644 (file)
@@ -32,14 +32,22 @@ These options control the mode that ikiwiki operates in.
 
 * --setup setupfile
 
-  In setup mode, ikiwiki reads the config file, which is really a perl
-  program that can call ikiwiki internal functions.
-
   The default action when --setup is specified is to automatically generate
   wrappers for a wiki based on data in a setup file, and rebuild the wiki.
   If you only want to build any changed pages, you can use --refresh with
   --setup.
 
+* --changesetup setupfile
+
+  Reads the setup file, adds any configuration changes specified by other
+  options, and writes the new configuration back to the setup file. Also
+  updates any configured wrappers. In this mode, the wiki is not fully
+  rebuilt, unless you also add --rebuild.
+
+  Example, to enable some plugins:
+
+       ikiwiki --changesetup ~/ikiwiki.setup --plugin goodstuff --plugin calendar
+
 * --dumpsetup setupfile
 
   Causes ikiwiki to write to the specified setup file, dumping out
index ac43044dfcbb6b927de2f83081f9cb67ce6bd384..aa333793836455eb558f9151e43e96d35d5abb63 100755 (executable)
@@ -14,24 +14,32 @@ sub usage () {
            gettext("       ikiwiki --setup configfile"), "\n";
 }
 
+sub setup (@) {
+       require IkiWiki::Setup;
+       my $verbose=$config{verbose};
+       my $syslog=$config{syslog};
+       IkiWiki::Setup::load($_[1]);
+       $config{setupverbose}=$config{verbose};
+       $config{setupsyslog}=$config{syslog};
+       $config{verbose}=$verbose || $config{setupverbose};
+       $config{syslog}=$syslog;
+       $config{setup}=1;
+}
+
 sub getconfig () {
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=defaultconfig();
                eval q{use Getopt::Long};
                Getopt::Long::Configure('pass_through');
                GetOptions(
-                       "setup|s=s" => sub {
-                               require IkiWiki::Setup;
-                               my $verbose=$config{verbose};
-                               my $syslog=$config{syslog};
-                               IkiWiki::Setup::load($_[1]);
-                               $config{setupverbose}=$config{verbose};
-                               $config{setupsyslog}=$config{syslog};
-                               $config{verbose}=$verbose || $config{setupverbose};
-                               $config{syslog}=$syslog;
-                               $config{setup}=1;
-                       },
+                       "setup|s=s" => \&setup,
                        "dumpsetup|s=s" => \$config{dumpsetup},
+                       "changesetup|s=s" => sub {
+                               $config{changesetup}=$_[1];
+                               $config{genwrappers}=1;
+                               $config{refresh}=1;
+                               setup(@_);
+                       },
                        "wikiname=s" => \$config{wikiname},
                        "verbose|v!" => \$config{verbose},
                        "syslog!" => \$config{syslog},
@@ -85,7 +93,8 @@ sub getconfig () {
                                $config{wrappermode}=possibly_foolish_untaint($_[1])
                        },
                        "plugin=s@" => sub {
-                               push @{$config{add_plugins}}, $_[1];
+                               push @{$config{add_plugins}}, $_[1]
+                                       unless grep { $_ eq $_[1] } @{$config{add_plugins}};
                        },
                        "disable-plugin=s@" => sub {
                                push @{$config{disable_plugins}}, $_[1];
@@ -181,6 +190,11 @@ sub main () {
                }
        }
 
+       if ($config{changesetup}) {
+               require IkiWiki::Setup;
+               IkiWiki::Setup::dump($config{changesetup});
+       }
+
        if ($config{dumpsetup}) {
                $config{srcdir}="" if ! defined $config{srcdir};
                $config{destdir}="" if ! defined $config{destdir};