#!/usr/bin/perl -w
#========================================================================
#
# repo_ls
#
# DESCRIPTION
#
#   Administrative tool for viewing contents of a document repository
#   using the Document::Repository module.
#
# AUTHOR
#   Bryce W. Harrington <bryce at bryceharrington dot com>
#
# COPYRIGHT
#   Copyright (C) 2004 Bryce W. Harrington  
#   All Rights Reserved.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#------------------------------------------------------------------------
#
# Last Modified:  $Date: 2004/08/15 22:39:34 $
#
# $Id: repo_ls,v 1.2 2004/08/15 22:39:34 bryce Exp $
#
# $Log: repo_ls,v $
# Revision 1.2  2004/08/15 22:39:34  bryce
# Adding some new commands to init a repository, put revisions of existing
# documents, and export documents from the repository.
#
# Revision 1.1  2004/08/15 20:09:34  bryce
# Adding META.yml and working on pulling out put() from add(), and simplifying several commands...
#
#
#========================================================================

use strict;                             # Forces variable decl's
use Carp;                               # Improved error/warning prints
use Pod::Usage;                         # To report program usage
use Getopt::Long;                       # Basic cmdline arg handling
use Document::Repository;

#------------------------------------------------------------------------
# Commandline option processing
#------------------------------------------------------------------------

our $opt_help            = 0;    # Prints a brief help message
our $opt_debug           = 0;    # Prints debug messages
our $opt_repository_dir  = '';   # Location of the repository
our $opt_revisions       = 0;    # Whether to show past revisions
our $opt_files           = 0;    # Whether to list files in the document

Getopt::Long::Configure ("bundling", "no_ignore_case");  
GetOptions(
           "help|h",             # Prints a brief help message
           "debug|D=i",          # Prints debug messages
	   "repository_dir|R=s", # Location of the repository
	   "revisions|v",        # List revisions
	   "files|f",            # List files in document
            ) || pod2usage(1);

pod2usage(-verbose => 1, -exitstatus => 0) if $opt_help;

sub list_files {
    my $doc_id = shift;
    my $rev = shift;
}

my $repo = new Document::Repository( repository_dir => $opt_repository_dir,
				     debug          => $opt_debug );

foreach my $doc_id (@ARGV || $repo->documents()) {
    print "$doc_id\n";

    my @revs = $repo->revisions($doc_id);
    if (! @revs) {
	warn "No revisions for '$doc_id'  ".$repo->get_error()."\n";
	next;
    }
    foreach my $rev (sort { $b <=> $a } @revs) {
	next unless defined $rev;
	print "  Revision $rev\n";
	if ($opt_files) {
	    # List the files for this revision
	    foreach my $file ($repo->files($doc_id, $rev)) {
		print "    $file\n";
	    }
	}
	last unless ($opt_revisions);
    }
}



__END__

=head1 NAME

repo_add - Administrative tool to directly add a document to a document
repository.

=head1 SYNOPSIS

repo_get [options] doc_id

 Options:
   -h, --help                    Prints a brief help message
   -D, --debug=integer           Prints debug messages
   -R, --repository_dir          Location of the repository
   -d, --destination             Directory to put the files
   -r, --revision=integer        Revision number

=head1 DESCRIPTION

B<repo_get> - This retrieves the document specified by doc_id from the
repository.  Only one document can be retrieved at a time.

To retrieve a particular past revision of the document, use the
--revision parameter.

The user executing this script must have direct read/write/execute
permisison into the document repository.

=head1 AUTHOR

Bryce W. Harrington E<lt>bryce at bryceharrington dot comE<gt>

L<http://www.bryceharrington.com>

=head1 COPYRIGHT

Copyright (C) 2004 Bryce W. Harrington.
All Rights Reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 REVISION

Revision: $Revision: 1.2 $

=cut



