[Git][debian-gis-team/scripts][master] Add config file option.
Bas Couwenberg
gitlab at salsa.debian.org
Thu Dec 12 18:55:54 GMT 2019
Bas Couwenberg pushed to branch master at Debian GIS Project / scripts
Commits:
69a07562 by Bas Couwenberg at 2019-12-12T18:55:43Z
Add config file option.
- - - - -
3 changed files:
- salsa-configure-repositories.pl
- salsa-create-repository.pl
- salsa-delete-pipelines.pl
Changes:
=====================================
salsa-configure-repositories.pl
=====================================
@@ -20,6 +20,7 @@
use strict;
use Data::Dumper;
use File::Basename;
+use File::Slurp;
use Getopt::Long qw(:config bundling no_ignore_case);
use HTTP::Request::Common;
use JSON;
@@ -29,9 +30,10 @@ use URI::Escape;
$|=1;
my %cfg = (
+ config_file => '',
url => 'https://salsa.debian.org/api/v4',
- token => '',
- token_file => $ENV{HOME}.'/.salsa-token',
+ token => '',
+ token_file => $ENV{HOME}.'/.salsa-token',
namespace => '2052',
user => '',
group => 'debian-gis-team',
@@ -47,6 +49,7 @@ my %cfg = (
);
my $result = GetOptions(
+ 'C|config-file=s' => \$cfg{config_file},
'u|url=s' => \$cfg{url},
'n|namespace=i' => \$cfg{namespace},
'U|user=s' => \$cfg{user},
@@ -63,11 +66,28 @@ my $result = GetOptions(
'h|help' => \$cfg{help},
);
+if($cfg{config_file}) {
+ if(!-r $cfg{config_file}) {
+ print "Error: Cannot read config file: $cfg{config_file}\n";
+ exit 1;
+ }
+
+ my $data = from_json(read_file($cfg{config_file}));
+
+ foreach my $key (keys %cfg) {
+ if(exists $data->{$key}) {
+ $cfg{$key} = $data->{$key};
+ }
+ }
+}
+
if(!$result || $cfg{help}) {
print STDERR "\n" if(!$result);
print "Usage: ". basename($0) ." [OPTIONS]\n\n";
print "Options:\n";
+ print "-C, --config-file <PATH> Path to config file\n";
+ print "\n";
print "-u, --url <URL> Salsa URL ($cfg{url})\n";
print "-t, --token <STRING> Salsa token (". '*' x length($cfg{token}) .")\n";
print "-T, --token-file <PATH> Salsa token file ($cfg{token_file})\n";
=====================================
salsa-create-repository.pl
=====================================
@@ -20,6 +20,7 @@
use strict;
use Data::Dumper;
use File::Basename;
+use File::Slurp;
use Getopt::Long qw(:config bundling no_ignore_case);
use HTTP::Request::Common;
use JSON;
@@ -29,9 +30,10 @@ use URI::Escape;
$|=1;
my %cfg = (
+ config_file => '',
url => 'https://salsa.debian.org/api/v4',
- token => '',
- token_file => $ENV{HOME}.'/.salsa-token',
+ token => '',
+ token_file => $ENV{HOME}.'/.salsa-token',
namespace => '2052',
user => '',
group => 'debian-gis-team',
@@ -52,6 +54,7 @@ my %cfg = (
);
my $result = GetOptions(
+ 'C|config-file=s' => \$cfg{config_file},
'u|url=s' => \$cfg{url},
'n|namespace=i' => \$cfg{namespace},
'U|user=s' => \$cfg{user},
@@ -73,11 +76,28 @@ my $result = GetOptions(
'h|help' => \$cfg{help},
);
+if($cfg{config_file}) {
+ if(!-r $cfg{config_file}) {
+ print "Error: Cannot read config file: $cfg{config_file}\n";
+ exit 1;
+ }
+
+ my $data = from_json(read_file($cfg{config_file}));
+
+ foreach my $key (keys %cfg) {
+ if(exists $data->{$key}) {
+ $cfg{$key} = $data->{$key};
+ }
+ }
+}
+
if(!$result || $cfg{help} || !$cfg{project}) {
print STDERR "\n" if(!$result);
print "Usage: ". basename($0) ." -p <NAME> [OPTIONS]\n\n";
print "Options:\n";
+ print "-C, --config-file <PATH> Path to config file\n";
+ print "\n";
print "-u, --url <URL> Salsa URL ($cfg{url})\n";
print "-t, --token <STRING> Salsa token (". '*' x length($cfg{token}) .")\n";
print "-T, --token-file <PATH> Salsa token file ($cfg{token_file})\n";
=====================================
salsa-delete-pipelines.pl
=====================================
@@ -20,6 +20,7 @@
use strict;
use Data::Dumper;
use File::Basename;
+use File::Slurp;
use Getopt::Long qw(:config bundling no_ignore_case);
use HTTP::Request::Common;
use JSON;
@@ -42,6 +43,7 @@ my %cfg = (
);
my $result = GetOptions(
+ 'C|config-file=s' => \$cfg{config_file},
'u|url=s' => \$cfg{url},
'n|namespace=i' => \$cfg{namespace},
'U|user=s' => \$cfg{user},
@@ -53,11 +55,28 @@ my $result = GetOptions(
'h|help' => \$cfg{help},
);
+if($cfg{config_file}) {
+ if(!-r $cfg{config_file}) {
+ print "Error: Cannot read config file: $cfg{config_file}\n";
+ exit 1;
+ }
+
+ my $data = from_json(read_file($cfg{config_file}));
+
+ foreach my $key (keys %cfg) {
+ if(exists $data->{$key}) {
+ $cfg{$key} = $data->{$key};
+ }
+ }
+}
+
if(!$result || $cfg{help} || !$cfg{project}) {
print STDERR "\n" if(!$result);
print "Usage: ". basename($0) ." [OPTIONS]\n\n";
print "Options:\n";
+ print "-C, --config-file <PATH> Path to config file\n";
+ print "\n";
print "-u, --url <URL> Salsa URL ($cfg{url})\n";
print "-t, --token <STRING> Salsa token (". '*' x length($cfg{token}) .")\n";
print "-T, --token-file <PATH> Salsa token file ($cfg{token_file})\n";
View it on GitLab: https://salsa.debian.org/debian-gis-team/scripts/commit/69a07562d63a98892cca2bff7c158c9e707738a2
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/scripts/commit/69a07562d63a98892cca2bff7c158c9e707738a2
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20191212/e005d880/attachment-0001.html>
More information about the Pkg-grass-devel
mailing list