| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package # hidden from PAUSE | ||
| 4 | github; | ||
| 5 | |||
| 6 | # ABSTRACT: GitHub Command Tools | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | use App::GitHub; | ||
| 12 | use Pod::Usage; | ||
| 13 | |||
| 14 | use Getopt::Long; | ||
| 15 | Getopt::Long::Configure("bundling"); | ||
| 16 | |||
| 17 | use 5.010; | ||
| 18 | |||
| 19 | if ( @ARGV == 0 ) { | ||
| 20 | App::GitHub->new->run(@ARGV); | ||
| 21 | } | ||
| 22 | else { | ||
| 23 | |||
| 24 | # Let's define some options! | ||
| 25 | my ( $create, $username, $password, $key, $name, $fork, $help ); | ||
| 26 | GetOptions( | ||
| 27 | 'create|c=s' => \$create, | ||
| 28 | 'key|k=s' => \$key, | ||
| 29 | 'name|n=s' => \$name, | ||
| 30 | 'fork|f=s' => \$fork, | ||
| 31 | 'username|u=s' => \$username, | ||
| 32 | 'password|p=s' => \$password, | ||
| 33 | 'help' => \$help, | ||
| 34 | ); | ||
| 35 | |||
| 36 | my $github = App::GitHub->new( silent => 1 ); | ||
| 37 | if ($help) { | ||
| 38 | pod2usage(1); | ||
| 39 | } | ||
| 40 | |||
| 41 | unless ( $username and $password ) { | ||
| 42 | $github->set_loadcfg; | ||
| 43 | } | ||
| 44 | else { | ||
| 45 | $github->set_login("$username $password"); | ||
| 46 | } | ||
| 47 | |||
| 48 | if ($create) { | ||
| 49 | eval { $github->repo_create($create); }; | ||
| 50 | |||
| 51 | if ($@) { | ||
| 52 | say STDERR "Could not create repo $create"; | ||
| 53 | print STDERR $@; | ||
| 54 | } | ||
| 55 | else { | ||
| 56 | say "Created repo $create"; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | elsif ($key) { | ||
| 60 | say STDERR "Provide a name for the key with -n" if not $name; | ||
| 61 | |||
| 62 | eval { $github->user_pub_keys( "add", $name, $key ); }; | ||
| 63 | |||
| 64 | if ($@) { | ||
| 65 | say STDERR "Could not add key"; | ||
| 66 | print STDERR $@; | ||
| 67 | } | ||
| 68 | else { | ||
| 69 | say "Added pubkey"; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | elsif ($fork) { | ||
| 73 | eval { $github->run_basic_repo_cmd( 'repos', 'create_fork', $fork ); }; | ||
| 74 | |||
| 75 | if ($@) { | ||
| 76 | say STDERR "Could not fork $fork"; | ||
| 77 | print STDERR $@; | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | say "Forked repo $fork"; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 1; | ||
| 86 | |||
| 87 | =pod | ||
| 88 | |||
| 89 | =head1 NAME | ||
| 90 | |||
| 91 | github - GitHub Command Tools | ||
| 92 | |||
| 93 | =head1 VERSION | ||
| 94 | |||
| 95 | version 1.0.1 | ||
| 96 | |||
| 97 | =head1 SYNOPSIS | ||
| 98 | |||
| 99 | github.pl [options] | ||
| 100 | |||
| 101 | When run with no options, drops you to the github command line. | ||
| 102 | |||
| 103 | If --username and --password aren't passed in, github.user and github.pass from .gitconfig are used | ||
| 104 | |||
| 105 | Options: | ||
| 106 | |||
| 107 | --username='username' | ||
| 108 | --password='password' | ||
| 109 | --create='name of repo to create' | ||
| 110 | --key='pubkey' --name='name of key' | ||
| 111 | --fork='name of repo to fork' | ||
| 112 | --help | ||
| 113 | |||
| 114 | =head1 NAME | ||
| 115 | |||
| 116 | github.pl - Interact with github.com through the command line | ||
| 117 | |||
| 118 | =head1 OPTIONS | ||
| 119 | |||
| 120 | =over 8 | ||
| 121 | |||
| 122 | =item B<--create> | ||
| 123 | |||
| 124 | Creates a new repo on github | ||
| 125 | |||
| 126 | =item B<--key --name> | ||
| 127 | |||
| 128 | Adds a key with a given name (passed by --name) to a github account | ||
| 129 | |||
| 130 | =item B<--fork> | ||
| 131 | |||
| 132 | Fork the given github repo to your account | ||
| 133 | |||
| 134 | =item B<--help> | ||
| 135 | |||
| 136 | Print help text and exit | ||
| 137 | |||
| 138 | =item B<--username> | ||
| 139 | |||
| 140 | Github username | ||
| 141 | |||
| 142 | =item B<--password> | ||
| 143 | |||
| 144 | Github password | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | =head1 AUTHOR | ||
| 149 | |||
| 150 | William Orr <will@worrbase.com> | ||
| 151 | |||
| 152 | Please report bugs L<here|https://github.com/worr/perl-app-github/> | ||
| 153 | |||
| 154 | =head1 AUTHORS | ||
| 155 | |||
| 156 | =over 4 | ||
| 157 | |||
| 158 | =item * | ||
| 159 | |||
| 160 | Fayland Lam <fayland@gmail.com> | ||
| 161 | |||
| 162 | =item * | ||
| 163 | |||
| 164 | William Orr <will@worrbase.com> | ||
| 165 | |||
| 166 | =back | ||
| 167 | |||
| 168 | =head1 COPYRIGHT AND LICENSE | ||
| 169 | |||
| 170 | This software is copyright (c) 2012 by Fayland Lam. | ||
| 171 | |||
| 172 | This is free software; you can redistribute it and/or modify it under | ||
| 173 | the same terms as the Perl 5 programming language system itself. | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | __END__ |