| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | package Git::Open; | ||
| 4 | use Moose; | ||
| 5 | use Git::Open::Util; | ||
| 6 | |||
| 7 | use Moose::Util::TypeConstraints; | ||
| 8 | |||
| 9 | with 'MooseX::Getopt::Usage'; | ||
| 10 | |||
| 11 | our $VERSION = '0.1.9'; # VERSION: generated by DZP::OurPkgVersion | ||
| 12 | |||
| 13 | subtype 'MaybeStr' | ||
| 14 | => as 'Str' | ||
| 15 | => where { defined $_ }; | ||
| 16 | |||
| 17 | MooseX::Getopt::OptionTypeMap->add_option_type_to_map( | ||
| 18 | 'MaybeStr' => ':s' | ||
| 19 | ); | ||
| 20 | |||
| 21 | has compare => ( | ||
| 22 | is => 'ro', | ||
| 23 | isa => 'MaybeStr', | ||
| 24 | documentation => 'To open compare view, ex: --compare master-develop' | ||
| 25 | ); | ||
| 26 | |||
| 27 | has 'branch' => ( | ||
| 28 | is => 'ro', | ||
| 29 | isa => 'MaybeStr', | ||
| 30 | documentation => 'To open branch view: --branch develop' | ||
| 31 | ); | ||
| 32 | |||
| 33 | has generator => ( | ||
| 34 | is => 'ro', | ||
| 35 | metaclass => 'NoGetopt', | ||
| 36 | isa => 'Git::Open::Util', | ||
| 37 | default => sub { | ||
| 38 | return Git::Open::Util->new(); | ||
| 39 | }, | ||
| 40 | handles => { | ||
| 41 | url => 'generate_url' | ||
| 42 | } | ||
| 43 | ); | ||
| 44 | |||
| 45 | # ABSTRACT: The totally cool way to open repository page, sometime it's hard to remember and open via browser manually. | ||
| 46 | |||
| 47 | |||
| 48 | sub run { | ||
| 49 | my $self = shift; | ||
| 50 | |||
| 51 | my $url = $self->get_url(); | ||
| 52 | system("git web--browse $url"); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub get_url { | ||
| 56 | my $self = shift; | ||
| 57 | |||
| 58 | my @opts = qw( compare branch ); | ||
| 59 | |||
| 60 | my $args; | ||
| 61 | foreach my $opt ( @opts ) { | ||
| 62 | my $value = $self->meta->get_attribute($opt)->get_value($self); | ||
| 63 | $args->{$opt} = $value if defined $value; | ||
| 64 | } | ||
| 65 | |||
| 66 | return $self->url( $args ); | ||
| 67 | }; | ||
| 68 | |||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ | ||
| 72 | |||
| 73 | =pod | ||
| 74 | |||
| 75 | =encoding UTF-8 | ||
| 76 | |||
| 77 | =head1 NAME | ||
| 78 | |||
| 79 | Git::Open - The totally cool way to open repository page, sometime it's hard to remember and open via browser manually. | ||
| 80 | |||
| 81 | =head1 VERSION | ||
| 82 | |||
| 83 | version 0.1.9 | ||
| 84 | |||
| 85 | =head1 USAGE | ||
| 86 | |||
| 87 | git open # it will open homepage of your repository | ||
| 88 | |||
| 89 | git open --compare # it will open compare page | ||
| 90 | |||
| 91 | git open --compare master-develop # Open compare page betwee master and develop | ||
| 92 | |||
| 93 | git open --branch master # Open master branch's page | ||
| 94 | |||
| 95 | git open --branch # Open current branch's page | ||
| 96 | |||
| 97 | =head1 AUTHOR | ||
| 98 | |||
| 99 | Pattarawat Chormai <pat.chormai@gmail.com> | ||
| 100 | |||
| 101 | =head1 COPYRIGHT AND LICENSE | ||
| 102 | |||
| 103 | This software is copyright (c) 2014 by Pattarawat Chormai. | ||
| 104 | |||
| 105 | This is free software; you can redistribute it and/or modify it under | ||
| 106 | the same terms as the Perl 5 programming language system itself. | ||
| 107 | |||
| 108 | =cut |