Skip to content

Commit

Permalink
[14] Implemented possibilty of prompting user input
Browse files Browse the repository at this point in the history
Signed-off-by: DoesntMatter <jaed1@gmx.net>
  • Loading branch information
DoesntMatter committed Jan 22, 2012
1 parent 459db2b commit 0cd1f57
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions gitlog_to_rss.pl
Expand Up @@ -35,28 +35,36 @@
\%options,
"repo=s",
"outfile=s",
"prompt",
"help|?",
);

#
# Check and set options
#

if ($options{'help'}) {
ShowHelp();
}

if ($options{'repo'} and $options{'repo'} ne '') {
unless (CheckRepo($options{'repo'})) {
unless ($options{'prompt'}) {
if ($options{'help'}) {
ShowHelp();
}
if ($options{'repo'} and $options{'repo'} ne '') {
unless (CheckRepo($options{'repo'})) {
ShowHelp();
}
}
else {
ShowHelp();
}
unless ($options{'outfile'} and $options{'outfile'} ne '') {
$options{'outfile'} = cwd() . "/feed.rss";
}
}
else {
ShowHelp();
}

unless ($options{'outfile'} and $options{'outfile'} ne '') {
$options{'outfile'} = cwd() . "/feed.rss";
$options{'repo'} = GetInput("Please enter repository path: ", 1);
unless (CheckRepo($options{'repo'})) {
ShowHelp();
}
$options{'outfile'} = GetInput("Please enter outfile path: ");
}

#
Expand Down Expand Up @@ -85,12 +93,33 @@ sub ShowHelp {
Options:
--repo REPO Path to your Git repository
--outfile FILE Name and path of generated RSS file
--prompt Prompt for input and do not use options
--help Show this output
HELP

exit;
};

sub GetInput {
my $text = shift || return undef;
my $mandatory = shift || 0;
my $input;

if ($mandatory) {
until ($input) {
print STDERR $text;
$input = <>;
chomp($input);
}
}
else {
print STDERR $text;
$input = <>;
chomp($input);
}
return $input;
}

sub CheckRepo {
my $repo = shift || return undef;

Expand Down

0 comments on commit 0cd1f57

Please sign in to comment.