# make a new $cil object
my $cil = CIL->new();
- # for all commands (except init), we need to know we can see the proper paths
- # (ie. issues/)
- CIL::Utils->check_paths( $cil )
- unless $command_name eq 'init';
+ # do only the init command locally, do it first and exit - much easier
+ if ( $command_name eq 'init' ) {
+ $command->run($cil, $args, @ARGV);
+ exit 0;
+ }
+
+ # for all other commands, we need to know we can see the proper paths (ie. '.cil')
+ my $base_dir = CIL::Utils->get_basedir( $cil );
+ unless ( $base_dir ) {
+ Getopt::Mixed::abortMsg("Couldn't find '.cil' file - is this a 'cil' project?");
+ exit 2;
+ }
+ # set the BaseDir and read in the other configs
+ $cil->BaseDir( $base_dir );
$cil->read_config_user();
$cil->read_config_file();
$command->run($cil, $args, @ARGV);
}
-## ----------------------------------------------------------------------------
-# hooks
-
-# none yet
-
## ----------------------------------------------------------------------------
# helper functions for this command line tool
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(
- IssueDir
+ BaseDir IssueDir
StatusStrict StatusAllowed StatusOpen StatusClosed
LabelStrict LabelAllowed
DefaultNewStatus
));
my $defaults = {
+ BaseDir => q{.}, # the dir where the .cil file is
IssueDir => 'issues', # the dir to save the issues in
StatusStrict => 0, # whether to complain if a status is invalid
LabelStrict => 0, # whether to complain if a label is invalid
# if we have been passed it in, use it, else use the default
$self->$key( $cfg->{$key} || $defaults->{$key} );
}
+
return $self;
}
sub read_config_file {
my ( $self ) = @_;
- my $filename = '.cil';
+ my $filename = $self->BaseDir() . q{/.cil};
# since we might not have a '.cil' file yet (in the case where we're calling 'init',
# then we should just return whatever the defaults are
}
# set each config item
- $self->IssueDir( $cfg->{IssueDir} );
+ $self->IssueDir( $self->BaseDir() . q{/} . $cfg->{IssueDir} );
$self->UseGit( $cfg->{UseGit} );
# Status info
sub run {
my ($self, $cil, $args) = @_;
- CIL::Utils->check_paths($cil);
-
# find all the issues
my $issues = $cil->get_issues();
$issues = CIL::Utils->filter_issues( $cil, $issues, $args );
sub run {
my ($self, $cil, $args) = @_;
- CIL::Utils->check_paths($cil);
-
# find all the issues
my $issues = $cil->get_issues();
$issues = CIL::Utils->filter_issues( $cil, $issues, $args );
sub run {
my ($self, $cil, $args) = @_;
- CIL::Utils->check_paths($cil);
-
# find all the issues
my $issues = $cil->get_issues();
$issues = CIL::Utils->filter_issues( $cil, $issues, $args );
use Carp;
use File::Slurp;
use File::Temp qw(tempfile);
+use Cwd;
+use File::Basename;
use Email::Find;
use POSIX qw(getpgrp tcgetpgrp);
use Fcntl qw(:DEFAULT :flock);
## ----------------------------------------------------------------------------
# system
-sub check_paths {
+sub get_basedir {
my ($class, $cil) = @_;
- # make sure an issue directory is available
- unless ( $cil->dir_exists($cil->IssueDir) ) {
- $class->fatal("couldn't find '" . $cil->IssueDir . "' directory");
+ # ok, we just need to check that we can find a '.cil' file somewhere
+ my $dir = cwd();
+ while ( ! -f qq{$dir/.cil} ) {
+ $dir = dirname($dir);
+ if ( $dir eq q{/} ) {
+ $class->fatal("couldn't find '.cil' file");
+ }
}
+
+ # ok, we've found our .cil file, return this directory
+ return $dir;
}
sub ans {