]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add getopt hook type, this allows plugins to add new command-line options.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 28 Jul 2006 05:26:49 +0000 (05:26 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 28 Jul 2006 05:26:49 +0000 (05:26 +0000)
* Add --tagbase option to tag plugin.

IkiWiki.pm
IkiWiki/Plugin/skeleton.pm
IkiWiki/Plugin/tag.pm
IkiWiki/Setup/Standard.pm
debian/changelog
doc/plugins/tag.mdwn
doc/plugins/write.mdwn
doc/usage.mdwn
ikiwiki

index 4964f97a1ad59797e34f745e8a9f01e50f73169d..2b877a370d7f37a95147d9a7eb6bdd92ca3d3095 100644 (file)
@@ -81,6 +81,14 @@ sub checkconfig () { #{{{
                require IkiWiki::Rcs::Stub;
        }
 
+       if (exists $hooks{checkconfig}) {
+                foreach my $id (keys %{$hooks{checkconfig}}) {
+                        $hooks{checkconfig}{$id}{call}->();
+                }
+        }
+} #}}}
+
+sub loadplugins () { #{{{
        foreach my $plugin (@{$config{plugin}}) {
                my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
                eval qq{use $mod};
@@ -88,12 +96,6 @@ sub checkconfig () { #{{{
                        error("Failed to load plugin $mod: $@");
                }
        }
-
-       if (exists $hooks{checkconfig}) {
-                foreach my $id (keys %{$hooks{checkconfig}}) {
-                        $hooks{checkconfig}{$id}{call}->();
-                }
-        }
 } #}}}
 
 sub error ($) { #{{{
index acbc88994048e31e6020f8f11bf8cba98711a000..27da50e6fba80fe7c998dbbcb7b4265c56f42a76 100644 (file)
@@ -9,6 +9,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
+       IkiWiki::hook(type => "getopt", id => "skeleton", 
+               call => \&getopt);
        IkiWiki::hook(type => "checkconfig", id => "skeleton", 
                call => \&checkconfig);
        IkiWiki::hook(type => "preprocess", id => "skeleton", 
@@ -29,6 +31,10 @@ sub import { #{{{
                call => \&cgi);
 } # }}}
 
+sub getopt () { #{{{
+       IkiWiki::debug("skeleton plugin getopt");
+} #}}}
+
 sub checkconfig () { #{{{
        IkiWiki::debug("skeleton plugin checkconfig");
 } #}}}
index c4e12e61dd01f4dc31d4777d00d78a63300f503b..56bf17e2c1042ae367c1cd9afa63012ff33723ab 100644 (file)
@@ -9,12 +9,20 @@ use IkiWiki;
 my %tags;
 
 sub import { #{{{
+       IkiWiki::hook(type => "getopt", id => "tag",
+               call => \&getopt);
        IkiWiki::hook(type => "preprocess", id => "tag",
                call => \&preprocess);
        IkiWiki::hook(type => "pagetemplate", id => "tag",
                call => \&pagetemplate);
 } # }}}
 
+sub getopt () { #{{{
+       eval q{use Getopt::Long};
+       Getopt::Long::Configure('pass_through');
+       GetOptions("tagbase=s" => \$IkiWiki::config{tagbase});
+} #}}}
+
 sub preprocess (@) { #{{{
        if (! @_) {
                return "";
@@ -26,6 +34,9 @@ sub preprocess (@) { #{{{
 
        $tags{$page} = [];
        foreach my $tag (keys %params) {
+               if (exists $IkiWiki::config{tagbase}) {
+                       $tag=$IkiWiki::config{tagbase}."/".$tag;
+               }
                push @{$tags{$page}}, $tag;
                # hidden WikiLink
                push @{$IkiWiki::links{$page}}, $tag;
index 25f038a064ac8ceab4333f0d93ba13b1203262f2..4082ca7af664e0662325c6bb0f408372789e35f4 100644 (file)
@@ -64,6 +64,7 @@ sub setup_standard {
                debug("refreshing wiki..");
        }
 
+       loadplugins();
        checkconfig();
        lockwiki();
        loadindex();
index db76807b157a56fa9b2e45c4811804ea37c0787f..1f4cabf2dc4562bb3d6c5023bea38d1dac16aa33 100644 (file)
@@ -1,3 +1,10 @@
+ikiwiki (1.12) UNRELEASED; urgency=low
+
+  * Add getopt hook type, this allows plugins to add new command-line options.
+  * Add --tagbase option to tag plugin.
+
+ -- Joey Hess <joeyh@debian.org>  Fri, 28 Jul 2006 01:17:48 -0400
+
 ikiwiki (1.11) unstable; urgency=low
 
   * Patch from Enrico that
index fc8534dcbe6cd9789e1d11a29c625206590ca8c6..517bbaa37b0b29ef4041640b7582461eeb4041bf 100644 (file)
@@ -6,6 +6,12 @@ The tags work the same as if you had put a (hidden) [[WikiLink]] on the page
 for each tag, so you can use a [[GlobList]] to link to all pages that are
 tagged with a given tag, for example.
 
+This plugin has a configuration option. Set --tagbase=tag and all tags will
+be located inside a "tag" subdirectory, so in the above example, the tags
+are really set to tag/tech, tag/life, and tag/linux. This is a useful way
+to avoid having to write the full path to tags, if you want to keep them
+grouped together out of the way.
+
 This plugin is included in ikiwiki, but is not enabled by default. If it is
 enabled, you'll see a note below that this page is tagged with the "tags"
 tag.
index 90ffca3f44a1de2fdcba7ee089ff0ce2c3fdf8fc..a31f78b4ee7d79c8c519044af7e11bead051972d 100644 (file)
@@ -64,6 +64,18 @@ with the rest of the page.
 Beyond PreProcessorDirectives, Other types of hooks that can be used by
 plugins include:
 
+## getopt
+
+       IkiWiki::hook(type => "getopt", id => "foo", call => \&getopt);
+
+This allows for plugins to perform their own processing of command-line
+options and so add options to the ikiwiki command line. It's called during
+command line processing, with @ARGV full of any options that ikiwiki was
+not able to process on its own. The function should process any options it
+can, removing them from @ARGV. It should take care not to abort if it sees
+an option it cannot process, and should just skip over those options and
+leave them in @ARGV.
+
 ## checkconfig
 
        IkiWiki::hook(type => "checkconfig", id => "foo", call => \&checkconfig);
index 8404d15daee510ba46125e297824348547f97091..691880a96a701b3cb4b71c140735f5db79b5f5e5 100644 (file)
@@ -66,7 +66,8 @@ These options control the mode that ikiwiki is operating in.
 
 # CONFIG OPTIONS
 
-These options configure the wiki.
+These options configure the wiki. Note that plugins can add additional
+configuration options of their own.
 
 * --wikiname
 
diff --git a/ikiwiki b/ikiwiki
index cdb2042e170a3f8a89373b76429a2a0f93c784b9..a10876a96ba10b6fb888c13742f32c34ddf97939 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -15,6 +15,7 @@ sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=defaultconfig();
                eval q{use Getopt::Long};
+               Getopt::Long::Configure('pass_through');
                GetOptions(
                        "setup|s=s" => \$config{setup},
                        "wikiname=s" => \$config{wikiname},
@@ -66,6 +67,17 @@ sub getconfig () { #{{{
                ) || usage();
 
                if (! $config{setup}) {
+                       loadplugins();
+                       if (exists $hooks{getopt}) {
+                               foreach my $id (keys %{$hooks{getopt}}) {
+                                       $hooks{getopt}{$id}{call}->();
+                               }
+                       }
+                       if (grep /^-/, @ARGV) {
+                               print STDERR "Unknown option: $_\n"
+                                       foreach grep /^-/, @ARGV;
+                               usage();
+                       }
                        usage() unless @ARGV == 2;
                        $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
                        $config{destdir} = possibly_foolish_untaint(shift @ARGV);
@@ -79,6 +91,7 @@ sub getconfig () { #{{{
                if ($@) {
                        error("WRAPPED_OPTIONS: $@");
                }
+               loadplugins();
                checkconfig();
        }
 } #}}}