]> mj.ucw.cz Git - gallery.git/blob - gal2/gal
Gallery2: Subcommands
[gallery.git] / gal2 / gal
1 #!/usr/bin/perl
2 # UCW Gallery -- Master Program
3 # (c) 2012 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use Getopt::Long;
8
9 use FindBin;
10 my $gallery_root = $FindBin::Bin;
11
12 sub show_help() {
13         print <<AMEN ;
14 Usage: gal <general-options> <command> <command-options> <args>
15
16 General options:
17 (none yet)
18
19 Common commands:
20 scan            Scan directory and obtain originals
21 gen             Generate web photos from originals
22 cache           Rebuild thumbnails and other cached info
23
24 Other commands:
25 dump-config     Show configuration settings
26 dump-meta       Show contents of metadata files
27 from-gqview     Parse gqview/geeqie collections
28 AMEN
29         exit 0;
30 }
31
32 Getopt::Long::Configure('require_order');
33 GetOptions(
34         "help" => \&show_help,
35         "version" => sub {
36                         print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
37                 },
38 ) or die "Try `gal help' for more information.\n";
39 Getopt::Long::Configure('default');
40
41 @ARGV or die "Missing subcommand.\n";
42 my $sub = shift @ARGV;
43 $sub =~ /^[0-9a-zA-Z-]+$/ or die "Invalid subcommand $sub\n";
44
45 if ($sub eq 'help') { show_help(); }
46
47 my $sub_path = "$gallery_root/bin/gal-$sub";
48 -x $sub_path or die "Unknown subcommand $sub\n";
49
50 $ENV{"GALLERY_ROOT"} = $gallery_root;
51 $ENV{"PERL5LIB"} = join(":", $gallery_root, $ENV{"PERL5LIB"} // ());
52 exec $sub_path, @ARGV;
53 die "Cannot execute $sub_path: $!\n";