mdisk: Remove color from "Already mounted" message
[sunny256-utils.git] / githubnetwork
blobd71ccb2973d21796c428e6e45694897f3b245325
1 #!/usr/bin/env perl
3 #=======================================================================
4 # githubnetwork
5 # File ID: 3a9abebc-691e-11e0-9c71-8be79eda2807
6 # [Description]
8 # Character set: UTF-8
9 # ©opyleft 2011– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 local $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'create' => 0,
25 'debug' => 0,
26 'help' => 0,
27 'verbose' => 0,
28 'version' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.00';
36 Getopt::Long::Configure('bundling');
37 GetOptions(
39 'create|c' => \$Opt{'create'},
40 'debug' => \$Opt{'debug'},
41 'help|h' => \$Opt{'help'},
42 'verbose|v+' => \$Opt{'verbose'},
43 'version' => \$Opt{'version'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 $Opt{'debug'} && ($Debug = 1);
48 $Opt{'help'} && usage(0);
49 if ($Opt{'version'}) {
50 print_version();
51 exit(0);
54 my $json = '';
56 if (scalar(@ARGV)) {
57 $json = `curl -s http://github.com/api/v2/json/repos/show/$ARGV[0]/network`;
58 } else {
59 local $/ = undef;
60 $json = <STDIN>;
63 $json =~ s{
64 "url":"([^"]+?)"
65 .*?
66 "owner":"([^"]+?)"
68 my ($url, $owner) = ($1, $2);
69 $url =~ s/^https:/git:/;
70 $url .= '.git';
71 my $cmdstr = sprintf("git remote add github/%s %s", $owner, $url);
72 if ($Opt{'create'}) {
73 system($cmdstr)
74 && print("Error creating remote github/$owner\n")
75 || print("Created remote github/$owner\n");
76 } else {
77 print("$cmdstr\n");
79 }gsex;
81 sub print_version {
82 # Print program version {{{
83 print("$progname v$VERSION\n");
84 return;
85 # }}}
86 } # print_version()
88 sub usage {
89 # Send the help message to stdout {{{
90 my $Retval = shift;
92 if ($Opt{'verbose'}) {
93 print("\n");
94 print_version();
96 print(<<"END");
98 Usage: $progname [options] [user/repository]
100 If user/repository is specified, get info from GitHub, otherwise read
101 JSON from stdin. Needs curl(1).
103 Options:
105 -c, --create
106 Create remotes in current repository instead of merely printing
107 them to stdout.
108 -h, --help
109 Show this help.
110 -v, --verbose
111 Increase level of verbosity. Can be repeated.
112 --version
113 Print version information.
114 --debug
115 Print debugging messages.
118 exit($Retval);
119 # }}}
120 } # usage()
122 sub msg {
123 # Print a status message to stderr based on verbosity level {{{
124 my ($verbose_level, $Txt) = @_;
126 if ($Opt{'verbose'} >= $verbose_level) {
127 print(STDERR "$progname: $Txt\n");
129 return;
130 # }}}
131 } # msg()
133 sub D {
134 # Print a debugging message {{{
135 $Debug || return;
136 my @call_info = caller;
137 chomp(my $Txt = shift);
138 my $File = $call_info[1];
139 $File =~ s#\\#/#g;
140 $File =~ s#^.*/(.*?)$#$1#;
141 print(STDERR "$File:$call_info[2] $$ $Txt\n");
142 return('');
143 # }}}
144 } # D()
146 __END__
148 # Plain Old Documentation (POD) {{{
150 =pod
152 =head1 NAME
156 =head1 SYNOPSIS
158 [options] [file [files [...]]]
160 =head1 DESCRIPTION
164 =head1 OPTIONS
166 =over 4
168 =item B<-h>, B<--help>
170 Print a brief help summary.
172 =item B<-v>, B<--verbose>
174 Increase level of verbosity. Can be repeated.
176 =item B<--version>
178 Print version information.
180 =item B<--debug>
182 Print debugging messages.
184 =back
186 =head1 BUGS
190 =head1 AUTHOR
192 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
194 =head1 COPYRIGHT
196 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
197 This is free software; see the file F<COPYING> for legalese stuff.
199 =head1 LICENCE
201 This program is free software: you can redistribute it and/or modify it
202 under the terms of the GNU General Public License as published by the
203 Free Software Foundation, either version 2 of the License, or (at your
204 option) any later version.
206 This program is distributed in the hope that it will be useful, but
207 WITHOUT ANY WARRANTY; without even the implied warranty of
208 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
209 See the GNU General Public License for more details.
211 You should have received a copy of the GNU General Public License along
212 with this program.
213 If not, see L<http://www.gnu.org/licenses/>.
215 =head1 SEE ALSO
217 =cut
219 # }}}
221 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :