Browse Source

Add "--namespace" to push.pl

Tianon Gravi 8 years ago
parent
commit
161bc52791
1 changed files with 7 additions and 5 deletions
  1. 7 5
      push.pl

+ 7 - 5
push.pl

@@ -19,10 +19,12 @@ my $githubBase = 'https://github.com/docker-library/docs/tree/master';
 my $username;
 my $username;
 my $password;
 my $password;
 my $batchmode;
 my $batchmode;
+my $namespace;
 GetOptions(
 GetOptions(
 	'u|username=s' => \$username,
 	'u|username=s' => \$username,
 	'p|password=s' => \$password,
 	'p|password=s' => \$password,
 	'batchmode!' => \$batchmode,
 	'batchmode!' => \$batchmode,
+	'namespace=s' => \$namespace,
 ) or die 'bad args';
 ) or die 'bad args';
 
 
 die 'no repos specified' unless @ARGV;
 die 'no repos specified' unless @ARGV;
@@ -108,15 +110,15 @@ sub prompt_for_edit {
 	return $currentText;
 	return $currentText;
 }
 }
 
 
-while (my $repo = shift) { # '/library/hylang', '/tianon/perl', etc
-	$repo =~ s!/+$!!;
-	$repo = '/library/' . $repo unless $repo =~ m!/!;
-	$repo = '/' . $repo unless $repo =~ m!^/!;
+while (my $repo = shift) { # 'library/hylang', 'tianon/perl', etc
+	$repo =~ s!^/+|/+$!!; # trim extra slashes (from "*/" globbing, for example)
+	$repo = $namespace . '/' . $repo if $namespace; # ./push.pl --namespace xxx ...
+	$repo = 'library/' . $repo unless $repo =~ m!/!; # "hylang" -> "library/hylang"
 	
 	
 	my $repoName = $repo;
 	my $repoName = $repo;
 	$repoName =~ s!^.*/!!; # 'hylang', 'perl', etc
 	$repoName =~ s!^.*/!!; # 'hylang', 'perl', etc
 	
 	
-	my $repoUrl = 'https://hub.docker.com/v2/repositories' . $repo . '/';
+	my $repoUrl = 'https://hub.docker.com/v2/repositories/' . $repo . '/';
 	my $repoTx = $ua->get($repoUrl => $authorizationHeader);
 	my $repoTx = $ua->get($repoUrl => $authorizationHeader);
 	warn 'warning: failed to get: ' . $repoUrl . ' (skipping)' and next unless $repoTx->success;
 	warn 'warning: failed to get: ' . $repoUrl . ' (skipping)' and next unless $repoTx->success;