]> git.mjollnir.org Git - cil.git/commitdiff
Issue:12 - Fixed, can now run in any dir in the project
authorAndrew Chilton <andychilton@gmail.com>
Sat, 30 Jul 2011 10:27:25 +0000 (22:27 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Sat, 30 Jul 2011 10:28:36 +0000 (22:28 +1200)
bin/cil
lib/CIL.pm
lib/CIL/Command/List.pm
lib/CIL/Command/ListLabels.pm
lib/CIL/Command/Summary.pm
lib/CIL/Utils.pm

diff --git a/bin/cil b/bin/cil
index f20b443bb749a8c2eaf67465120599d12b6cf0eb..c740b9836ac93f45526a39d050a526952b49c868 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -111,11 +111,21 @@ my %BOOLEAN_ARGS = (
     # 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();
 
@@ -125,11 +135,6 @@ my %BOOLEAN_ARGS = (
     $command->run($cil, $args, @ARGV);
 }
 
-## ----------------------------------------------------------------------------
-# hooks
-
-# none yet
-
 ## ----------------------------------------------------------------------------
 # helper functions for this command line tool
 
index 548ada30ef33b657df93b4d4481bc595987d6374..ee82ff206e3bc70be75147a197fb941de6424f57 100644 (file)
@@ -38,7 +38,7 @@ use Module::Pluggable
 
 use base qw(Class::Accessor);
 __PACKAGE__->mk_accessors(qw(
-    IssueDir
+    BaseDir IssueDir
     StatusStrict StatusAllowed StatusOpen StatusClosed
     LabelStrict LabelAllowed
     DefaultNewStatus
@@ -49,6 +49,7 @@ __PACKAGE__->mk_accessors(qw(
 ));
 
 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
@@ -85,6 +86,7 @@ sub new {
         # if we have been passed it in, use it, else use the default
         $self->$key( $cfg->{$key} || $defaults->{$key} );
     }
+
     return $self;
 }
 
@@ -240,7 +242,7 @@ sub read_config_user {
 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
@@ -275,7 +277,7 @@ sub read_config_file {
     }
 
     # set each config item
-    $self->IssueDir( $cfg->{IssueDir} );
+    $self->IssueDir( $self->BaseDir() . q{/} . $cfg->{IssueDir} );
     $self->UseGit( $cfg->{UseGit} );
 
     # Status info
index cdb5b0364e2cb1ca75f7213dd316b8fa7fe11f46..98fbad4eeb3d0856058ed3d1dde5e6748bd68e2f 100644 (file)
@@ -33,8 +33,6 @@ sub name { 'list' }
 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 );
index 7ba69e8795b7ee25019bfa4f78df66302b96084e..a7a7c57f0be41ce8f76b989087ea75fe20fdb227 100644 (file)
@@ -33,8 +33,6 @@ sub name { 'list-labels' }
 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 );
index f5a3ab609b4c2d2ac315a80660ec1de52de9f2e4..2a5e3257a1f3e998f6c34115878be7d166fab0fa 100644 (file)
@@ -33,8 +33,6 @@ sub name { 'summary' }
 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 );
index 563cf34d4918492b0168867839d14850c10c80c6..6ca3cf47a7cebc1665cfd4884e749b95f6c51bb8 100644 (file)
@@ -26,6 +26,8 @@ use warnings;
 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);
@@ -533,13 +535,20 @@ sub text {
 ## ----------------------------------------------------------------------------
 # 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 {