diff --git a/lib/App/gh.pm b/lib/App/gh.pm index eea8b07..7f1951d 100644 --- a/lib/App/gh.pm +++ b/lib/App/gh.pm @@ -26,8 +26,10 @@ sub github { my $github_id = $class->config->github_id; my $github_password = $class->config->github_password; - die('Please configure your github.user') unless $github_id; - die('Please configure your github.password') unless $github_password; + die "Please configure your github.user in .gitconfig (see App::gh pod)\n" + unless $github_id; + die "Please configure your github.password in .gitconfig (See App::gh pod)\n" + unless $github_password; return $GITHUB ||= Net::GitHub->new( # Net::GitHub::V3 login => $github_id, diff --git a/lib/App/gh/Command/List.pm b/lib/App/gh/Command/List.pm index b92630c..9f54f37 100644 --- a/lib/App/gh/Command/List.pm +++ b/lib/App/gh/Command/List.pm @@ -27,9 +27,12 @@ sub run { $acc =~ s{/$}{}; # TODO: use api class. - my $repolist = App::gh->api->user_repos( $acc ); + my $query = App::gh->github->repos; + my @repolist = $query->list_user($acc); + push @repolist, $query->next_page while $query->has_next_page; + my @lines = (); - for my $repo ( @$repolist ) { + for my $repo ( @repolist ) { my $repo_name = $repo->{name}; # name-only diff --git a/lib/App/gh/Config.pm b/lib/App/gh/Config.pm index 0b4e5d0..e519c12 100644 --- a/lib/App/gh/Config.pm +++ b/lib/App/gh/Config.pm @@ -3,46 +3,46 @@ use warnings; use strict; use File::HomeDir (); use File::Spec; - -sub _parse_options { - my $part = shift; - my $options; - while( $part =~ /^\s*(.+?)\s*=\s*(.*?)\s*$/gm ) { - my ($name,$value) = ($1,$2); - $options->{ $name } = $value; - } - return $options; -} +use File::Basename qw(dirname); +my %_parse_memoize; # XXX: use Config::Tiny to parse ini format config. sub parse { my ( $class, $file ) = @_; - # read file - open FH , "<" , $file; - local $/; - my $content = ; - close FH; + # Return cached result. + $file = File::Spec->rel2abs($file); + return $_parse_memoize{$file} if exists $_parse_memoize{$file}; - # TODO: simply parse config.... better choice ? - my @parts = split /(?=\[.*?\])/,$content; my %config; - for my $part ( @parts ) { - if( $part =~ /^\[(\w+)\s+["'](\w+)["']\]/g ) { - my ($o1 , $o2 ) = ($1, $2); - $config{ $o1 } ||= {}; - $config{ $o1 }->{ $o2 } - = _parse_options( $part ); - } - elsif( $part =~ /^\[(.*?)\]/g ) { - my $key = $1; - my $options = _parse_options( $part ); - $config{ $key } = $options; + for my $line (split "\n", qx(git config --list -f '$file')) { + # $line = foo.bar.baz=value + if (my ($key, $value) = ($line =~ m/^([^=]+)=(.*)/)) { + my $h = \%config; + if ($key eq 'include.path') { + my $path = File::Spec->file_name_is_absolute($value) ? $value : File::Spec->rel2abs($value, dirname($file)); + %config = (%config, %{ $class->parse($path) }); + # Uncomment this to get rid of "include.path" in %config + #next; + } + my @keys = split /\./, $key; + next unless @keys; + # Create empty hashref. + # %config = (foo => {bar => ($h = {})}) + for (@keys[0..$#keys-1]) { + $h->{$_} = {} unless exists $h->{$_}; + $h = $h->{$_}; + } + # $config{foo}{bar}{baz} = $value; + $h->{$keys[-1]} = $value; } } + + # Cache result not to invoke 'git' command frequently. + $_parse_memoize{$file} = \%config; return \%config; } diff --git a/lib/App/gh/Utils.pm b/lib/App/gh/Utils.pm index 1a6d967..a9d723f 100644 --- a/lib/App/gh/Utils.pm +++ b/lib/App/gh/Utils.pm @@ -74,7 +74,7 @@ sub print_list { if ( $ENV{WRAP} && ( $column_w + 3 + length( join(" ",@$arg)) ) > $screen_width ) { # wrap description my $string = - color('bold white') . + color('bold') . $title . color('reset') . " " x $padding . " - " . join(" ",@$arg) . "\n"; @@ -107,7 +107,7 @@ sub print_list { print "\n" if $wrapped; } else { - print color 'bold white'; + print color 'bold'; print $title; print color 'reset'; print " " x $padding;