]> git.mjollnir.org Git - cil.git/commitdiff
Initial revision
authorAndrew Chilton <andychilton@gmail.com>
Fri, 18 Apr 2008 12:03:22 +0000 (00:03 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Fri, 18 Apr 2008 12:03:22 +0000 (00:03 +1200)
bin/cil [new file with mode: 0755]
lib/CIL/Attachment.pm [new file with mode: 0644]
lib/CIL/Base.pm [new file with mode: 0644]
lib/CIL/Comment.pm [new file with mode: 0644]
lib/CIL/Issue.pm [new file with mode: 0644]

diff --git a/bin/cil b/bin/cil
new file mode 100755 (executable)
index 0000000..860efe9
--- /dev/null
+++ b/bin/cil
@@ -0,0 +1,121 @@
+#!/usr/bin/perl
+## ----------------------------------------------------------------------------
+
+use strict;
+use warnings;
+use Data::Dumper;
+use CIL::Issue;
+use Term::CallEditor;
+
+my $COMMANDS = {
+    add     => 1,
+    show    => 1,
+    comment => 1,
+    update  => 1
+};
+
+## ----------------------------------------------------------------------------
+
+{
+    my ($command) = shift;
+    unless ( defined $command and exists $COMMANDS->{$command} ) {
+        usage();
+        exit 2;
+    }
+
+    if ( $command eq 'show' ) {
+        my ($issue_name) = @ARGV;
+        show($issue_name);
+
+    }
+    elsif ( $command eq 'add' ) {
+        add();
+    }
+
+}
+
+sub show {
+    my ($issue_name) = @_;
+
+    # firstly, read the issue in
+    my $issue = CIL::Issue->load_issue('2008-04-17T22:05:02.000Z');
+
+    unless ( defined $issue ) {
+        print STDERR "Couldn't load issue '$issue'\n";
+        return;
+    }
+
+    separator();
+    title('Details');
+    field( 'Summary', $issue->Summary() );
+    field( 'Name', $issue->Name() );
+    field( 'CreatedBy', $issue->CreatedBy() );
+    field( 'Inserted', $issue->Inserted() );
+    field( 'Status', $issue->Status() );
+    field( 'Labels', $issue->Labels() );
+    separator();
+    text('Description', $issue->Description());
+    separator();
+    title('Comments');
+    separator();
+}
+
+sub add {
+    my ($issue_name) = @_;
+    my $fh = solicit('FOO: please replace this text');
+    die "$Term::CallEditor::errstr\n" unless $fh;
+    my $text;
+    $text .= $_ while <$fh>;
+    separator();
+    text('You said:', $text);
+    separator();
+}
+
+## ----------------------------------------------------------------------------
+
+sub usage {
+   print <<"END_USAGE";
+Usage: $0 <command> [options]
+
+Commands:
+   add
+   show    <issue>
+   comment <issue>
+   update  <issue>
+
+See <http://github.com/andychilton/cil/> for further information.
+Report bugs to <andychilton -at- gmail -dot- com>.
+END_USAGE
+}
+
+sub say {
+    print $_[0], "\n";
+}
+
+sub separator {
+    say('=' x 79);
+}
+
+sub title {
+    my ($title) = @_;
+    my $msg = "--- $title ";
+    $msg .= '-' x (74 - length($title));
+    say($msg);
+}
+
+sub field {
+    my ($field, $value) = @_;
+    my $msg = "$field";
+    $msg .= " " x (12 - length($field));
+    say("$msg: " . (defined $value ? $value : '') );
+}
+
+sub text {
+    my ($field, $value) = @_;
+    title($field);
+    say "";
+    say($value);
+    say "";
+}
+
+## ----------------------------------------------------------------------------
diff --git a/lib/CIL/Attachment.pm b/lib/CIL/Attachment.pm
new file mode 100644 (file)
index 0000000..91d6f30
--- /dev/null
@@ -0,0 +1,12 @@
+## ----------------------------------------------------------------------------
+package CIL::Attachment;
+
+use strict;
+use warnings;
+
+use base qw(Class::Accessor);
+__PACKAGE__->mk_accessors(qw(filename));
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
diff --git a/lib/CIL/Base.pm b/lib/CIL/Base.pm
new file mode 100644 (file)
index 0000000..a061d19
--- /dev/null
@@ -0,0 +1,23 @@
+## ----------------------------------------------------------------------------
+package CIL::Base;
+
+use strict;
+use warnings;
+use DateTime;
+
+use base qw(Class::Accessor);
+__PACKAGE__->mk_accessors(qw(Description CreatedBy Inserted Updated));
+
+sub inserted {
+    my ($self) = @_;
+    $self->{Inserted} = DateTime->new()->iso8601;
+}
+
+sub updated {
+    my ($self) = @_;
+    $self->{Updated} = DateTime->new()->iso8601;
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
diff --git a/lib/CIL/Comment.pm b/lib/CIL/Comment.pm
new file mode 100644 (file)
index 0000000..9bda63a
--- /dev/null
@@ -0,0 +1,10 @@
+## ----------------------------------------------------------------------------
+package CIL::Comment;
+
+use strict;
+use warnings;
+use base qw(CIL::Base);
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm
new file mode 100644 (file)
index 0000000..6475983
--- /dev/null
@@ -0,0 +1,65 @@
+## ----------------------------------------------------------------------------
+package CIL::Issue;
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Config::IniFiles;
+
+use base qw(CIL::Base);
+__PACKAGE__->mk_accessors(qw(Name Summary Status Labels Comments));
+
+## ----------------------------------------------------------------------------
+
+sub load_issue {
+    my ($self, $name) = @_;
+    return unless defined $name;
+
+    my $filename = "issues/$name.ini";
+
+    return unless -f $filename;
+    my $issue = CIL::Issue->new();
+    $issue->read_issue( $filename );
+    $issue->Name( $name );
+    return $issue;
+}
+
+sub read_issue {
+    my ($self, $filename) = @_;
+
+    my $cfg = Config::IniFiles->new( -file => $filename );
+
+    foreach my $attr ( qw(Summary Description) ) {
+         $self->{$attr} = $cfg->val( 'Issue', $attr );
+    }
+}
+
+sub reset {
+    my ($self) = @_;
+
+    foreach my $attr ( qw(changed) ) {
+        delete $self->{$attr};
+    }
+}
+
+sub inserted {
+    my ($self) = @_;
+    $self->{data}{inserted} = time;
+}
+
+sub updated {
+    my ($self) = @_;
+    $self->{changed} = '1';
+    $self->{data}{updated} = time;
+}
+
+sub add_comment {
+    my ($self, $comment_h) = @_;
+
+    my $comment = CIL::Comment->new($comment_h);
+
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------