mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-26 02:40:43 -06:00
[price quotes] Pass short errors to gnc-quotes.
And wordier but not translated messages when STDERR is a tty.
This commit is contained in:
parent
88d658fef0
commit
fe9b23ff2b
@ -86,6 +86,11 @@ sub check_modules {
|
|||||||
|
|
||||||
return unless @missing;
|
return unless @missing;
|
||||||
|
|
||||||
|
# Test for STDERR being a tty and output a detailed message if it is
|
||||||
|
# and a short message if it isn't; in the latter case we're probably
|
||||||
|
# being called from GnuCash and it will emit its own localized error.
|
||||||
|
if (-t STDERR)
|
||||||
|
{
|
||||||
print STDERR "\n";
|
print STDERR "\n";
|
||||||
print STDERR "You need to install the following Perl modules:\n";
|
print STDERR "You need to install the following Perl modules:\n";
|
||||||
foreach my $mod (@missing) {
|
foreach my $mod (@missing) {
|
||||||
@ -93,11 +98,14 @@ sub check_modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print STDERR "\n";
|
print STDERR "\n";
|
||||||
print STDERR "Use your system's package manager to install them,\n";
|
print STDERR "Please see https://wiki.gnucash.org/wiki/Online_Quotes#Finance::Quote for detailed corrective action.\n";
|
||||||
print STDERR "or run 'gnc-fq-update' as root.\n";
|
|
||||||
|
|
||||||
print "missing-lib\n";
|
print "missing-lib\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print STDERR "missing_modules ", join(" ", @missing), "\n";
|
||||||
|
}
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,13 +120,17 @@ sub print_version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub print_usage {
|
sub print_usage {
|
||||||
print STDERR
|
if (-t STDERR)
|
||||||
"Usage:
|
{
|
||||||
|
my $message = << 'END';
|
||||||
|
Usage:
|
||||||
Check proper installation and version:
|
Check proper installation and version:
|
||||||
finance-quote-wrapper -v
|
finance-quote-wrapper -v
|
||||||
Fetch quotes (input should be passed as JSON via stdin):
|
Fetch quotes (input should be passed as JSON via stdin):
|
||||||
finance-quote-wrapper -f
|
finance-quote-wrapper -f
|
||||||
";
|
END
|
||||||
|
print STDERR $message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub sanitize_hash {
|
sub sanitize_hash {
|
||||||
@ -209,18 +221,29 @@ JSON::Parse->import(qw(valid_json parse_json));
|
|||||||
my $json_input = do { local $/; <STDIN> };
|
my $json_input = do { local $/; <STDIN> };
|
||||||
|
|
||||||
if (!valid_json($json_input)) {
|
if (!valid_json($json_input)) {
|
||||||
|
if (-t STDERR)
|
||||||
|
{
|
||||||
print STDERR "Could not parse input as valid JSON.\n";
|
print STDERR "Could not parse input as valid JSON.\n";
|
||||||
print STDERR "Received input:\n$json_input\n";
|
print STDERR "Received input:\n$json_input\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print STDERR "invalid_json\n";
|
||||||
|
}
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $requests = parse_json ($json_input);
|
my $requests = parse_json ($json_input);
|
||||||
|
|
||||||
my $defaultcurrency = $$requests{'defaultcurrency'};
|
my $defaultcurrency = $$requests{'defaultcurrency'};
|
||||||
|
# This shouldn't be possible if we're called from GnuCash, so only warn in interactive use.
|
||||||
if (!$defaultcurrency) {
|
if (!$defaultcurrency) {
|
||||||
$defaultcurrency = "USD";
|
$defaultcurrency = "USD";
|
||||||
|
if (-t STDERR)
|
||||||
|
{
|
||||||
print STDERR "Warning: no default currency was specified, assuming 'USD'\n";
|
print STDERR "Warning: no default currency was specified, assuming 'USD'\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Create a stockquote object.
|
# Create a stockquote object.
|
||||||
my $quoter = Finance::Quote->new();
|
my $quoter = Finance::Quote->new();
|
||||||
|
Loading…
Reference in New Issue
Block a user