use strict;
use warnings;
+use Data::Dumper;
+
use Digest::MD5 qw(md5_hex);
use File::Touch;
use File::Glob ':glob';
use File::Basename;
use Term::CallEditor qw(solicit);
+use CIL;
use CIL::Issue;
use CIL::Comment;
check_paths();
# find all the issues
- my $issues = get_all_issues();
+ my $issues = CIL->instance->get_issues();
if ( @$issues ) {
separator();
foreach my $issue ( @$issues ) {
check_paths();
# find all the issues
- my $issues = get_all_issues();
- separator();
- title('Summary');
- foreach my $issue ( @$issues ) {
- display_issue_summary($issue);
+ my $issues = CIL->instance->get_issues();
+ if ( @$issues ) {
+ separator();
+ foreach my $issue ( @$issues ) {
+ display_issue_summary($issue);
+ }
+ separator();
+ }
+ else {
+ msg('no issues found');
}
- separator();
}
sub show {
my ($issue_name) = @_;
# firstly, read the issue in
- my $issue = CIL::Issue->new_load_issue($issue_name);
+ my $issue = CIL::Issue->load($issue_name);
unless ( defined $issue ) {
fatal("Couldn't load issue '$issue'");
}
sub edit {
my ($issue_name) = @_;
- my $issue = CIL::Issue->new_load_issue($issue_name);
+ my $issue = CIL::Issue->load($issue_name);
unless ( defined $issue ) {
fatal("Couldn't load issue '$issue'");
}
- my $summary = $issue->Summary;
- my $status = $issue->Status;
- my $created_by = $issue->CreatedBy;
- my $assigned_to = $issue->AssignedTo;
- my $label = $issue->Label;
- my $description = $issue->Description;
-
# create the ini file, then edit it
- my $edit_issue_text = <<"EOF";
-[Issue]
-
-Summary = $summary
-Status = $status
-CreatedBy = $created_by
-AssignedTo = $assigned_to
-Label = $label
-Description = <<END_OF_DESCRIPTION
-$description
-END_OF_DESCRIPTION
-EOF
+ my $edit_issue_text = $issue->as_output;
# read in the new issue text
- my $fh = solicit( $edit_issue_text );
+ my $fh = solicit( join('', @$edit_issue_text) );
my $issue_edited;
eval {
- $issue_edited = CIL::Issue->new_parse_issue( $fh );
+ $issue_edited = CIL::Issue->new_from_fh( $issue->name, $fh );
};
if ( $@ ) {
fatal("couldn't parse issue: $@");
fatal("couldn't create issue (program error)");
}
- # for the fields we're interested in, set them
- foreach my $field ( qw(Summary Status CreatedBy AssignedTo Labels Description) ) {
- $issue->$field( $issue_edited->$field() );
- }
- if ( $issue->changed ) {
- $issue->save();
- }
- else {
- msg('Issue not changed');
- }
+ $issue_edited->save();
+ display_issue_full( $issue_edited );
}
sub comment {
sub display_issue_summary {
my ($issue) = @_;
- my $msg = $issue->Name;
+ my $msg = $issue->name;
$msg .= "\t";
$msg .= $issue->Status;
$msg .= "\t";
- $msg .= $issue->AssignedTo;
- $msg .= "\t";
$msg .= $issue->Summary;
msg($msg);
sub display_issue_short {
my ($issue) = @_;
- title( "Issue " . $issue->Name );
+ title( "Issue " . $issue->name );
field( 'Summary', $issue->Summary() );
- field( 'Name', $issue->Name() );
field( 'CreatedBy', $issue->CreatedBy() );
field( 'AssignedTo', $issue->AssignedTo() );
field( 'Inserted', $issue->Inserted() );
field( 'Status', $issue->Status() );
- field( 'Labels', $issue->Labels() );
+ field( 'Labels', join(' ', @{$issue->Label()}) );
}
sub display_issue_full {
my ($issue) = @_;
separator();
- title('Issue: ' . $issue->name);
+ title('Issue ' . $issue->name);
field( 'Summary', $issue->Summary() );
field( 'Status', $issue->Status() );
field( 'CreatedBy', $issue->CreatedBy() );
field( 'AssignedTo', $issue->AssignedTo() );
field( 'Inserted', $issue->Inserted() );
field( 'Updated', $issue->Inserted() );
- field( 'Label', $issue->Label() );
+ field( 'Label', $_ )
+ foreach sort @{$issue->Label()};
+ field( 'Comment', $_ )
+ foreach sort @{$issue->Comment()};
+ field( 'Attachment', $_ )
+ foreach sort @{$issue->Attachment()};
separator();
text('Description', $issue->Description());
separator();
--- /dev/null
+## ----------------------------------------------------------------------------
+# cil is a Command line Issue List
+# Copyright (C) 2008 Andrew Chilton
+#
+# This file is part of 'cil'.
+#
+# cil is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+## ----------------------------------------------------------------------------
+
+package CIL;
+
+use strict;
+use warnings;
+use File::Glob qw(:glob);
+
+use base qw(Class::Singleton Class::Accessor);
+__PACKAGE__->mk_accessors(qw(issue_dir));
+
+my $defaults = {
+ issue_dir => 'issues',
+};
+
+## ----------------------------------------------------------------------------
+
+sub _new_instance {
+ my ($proto) = @_;
+ my $class = ref $proto || $proto;
+ my $self = bless {}, $class;
+ foreach my $key ( keys %$defaults ) {
+ $self->$key( $defaults->{$key} );
+ }
+ return $self;
+}
+
+sub set_config {
+ my ($self, $config) = @_;
+
+ foreach my $key ( qw(issue_dir) ) {
+ $self->$key( $config->{$key} )
+ if defined $config->{$key};
+ }
+}
+
+sub list_issues {
+ my ($self) = @_;
+
+ my $globpath = $self->issue_dir . "/i_*.cil";
+ my @filenames = bsd_glob($globpath);
+
+ my @issues;
+ foreach my $filename ( sort @filenames ) {
+ my ($name) = $filename =~ m{/i_(.*)\.cil$}xms;
+ push @issues, {
+ name => $name,
+ filename => $filename,
+ };
+ }
+ return \@issues;
+}
+
+sub get_issues {
+ my ($self) = @_;
+
+ my $issue_list = $self->list_issues();
+
+ my @issues;
+ foreach my $issue ( @$issue_list ) {
+ push @issues, CIL::Issue->load( $issue->{name} );
+ }
+ return \@issues;
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
use Config::IniFiles;
use YAML qw(LoadFile DumpFile);
+use CIL;
use CIL::Utils;
use base qw(CIL::Base);
__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo Label Comment Attachment));
my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo Label Comment Attachment Inserted Updated Description) );
+my $cfg = {
+ array => {
+ Label => 1,
+ Comment => 1,
+ Attachment => 1,
+ },
+};
## ----------------------------------------------------------------------------
foreach my $field ( @FIELDS ) {
next unless defined $data->{$field};
+ # make it an array if it should be one
+ if ( exists $cfg->{array}{$field} and ref $data->{$field} ne 'ARRAY' ) {
+ $data->{$field} = [ $data->{$field} ];
+ }
+
# modify the data directly, otherwise Updated will kick in
$self->set_no_update($field, $data->{$field});
}
croak 'provide an issue name to load'
unless defined $name;
- my $filename = "issues/$name.cil";
+ my $filename = CIL->instance->issue_dir . "/i_$name.cil";
croak "filename '$filename' does no exist"
unless -f $filename;
return $issue;
}
+sub as_output {
+ my ($self) = @_;
+ return CIL::Utils->format_data_as_output( $self->{data}, @FIELDS );
+}
+
sub save {
my ($self) = @_;
my $name = $self->name;
- my $filename = "issues/i_$name.cil";
+ my $filename = CIL->instance->issue_dir . "/i_$name.cil";
CIL::Utils->write_cil_file( $filename, $self->{data}, @FIELDS );
}
return $data;
}
-sub write_cil_file {
- my ($class, $filename, $data, @fields) = @_;
+sub format_data_as_output {
+ my ($class, $data, @fields) = @_;
+ # we format the last field differently, so pop it off now
my $last_field = pop @fields;
my @lines;
-
foreach my $field ( @fields ) {
next if $field eq $last_field;
if ( ref $data->{$field} eq 'ARRAY' ) {
+ # don't output this field if there is nothing in it
+ next unless @{$data->{$field}};
+
foreach ( sort @{$data->{$field}} ) {
push @lines, "$field: $_\n";
}
}
}
+ # finally, output the last field on it's own
push @lines, "\n";
push @lines, $data->{$last_field}, "\n";
- write_file($filename, \@lines);
+ return \@lines;
+}
+
+sub write_cil_file {
+ my ($class, $filename, $data, @fields) = @_;
+
+ # get the output format
+ my $lines = $class->format_data_as_output($data, @fields);
+
+ # ... and save
+ write_file($filename, $lines);
}
## ----------------------------------------------------------------------------