finance-quote-wrapper - implement check and fetch in one file via command line switches

This obsoletes gnc-fq-check as the same function can now be
performed with 'finance-quote-wrapper -v'
This commit is contained in:
Geert Janssens 2021-03-16 16:42:01 +01:00 committed by John Ralls
parent 8c08fedaa1
commit bf357315fd
2 changed files with 48 additions and 4 deletions

View File

@ -119,8 +119,8 @@ GncQuotesImpl::check (QofBook *book)
m_dflt_curr = gnc_default_currency();
auto perl_executable = bp::search_path("perl");
auto fq_check = std::string(gnc_path_get_bindir()) + "/gnc-fq-check";
StrVec args { "-w", fq_check };
auto fq_wrapper = std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper";
StrVec args { "-w", fq_wrapper, "-v" };
auto cmd_out = run_cmd (perl_executable.string(), args, StrVec());
@ -180,7 +180,7 @@ GncQuotesImpl::fetch (const CommVec& commodities)
auto perl_executable = bp::search_path("perl");
auto fq_wrapper = std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper";
StrVec args { "-w", fq_wrapper };
StrVec args { "-w", fq_wrapper, "-f" };
auto cmd_out = run_cmd (perl_executable.string(), args, result.str());

View File

@ -72,7 +72,7 @@ non-zero - failure
=cut
sub check_modules {
my @modules = qw(Finance::Quote JSON::Parse);
my @modules = qw(Finance::Quote JSON::Parse Getopt::Std);
my @missing;
foreach my $mod (@modules) {
@ -101,6 +101,26 @@ sub check_modules {
exit 1;
}
sub print_version {
my $quoter = Finance::Quote->new();
my @sources = $quoter->sources();
print "$Finance::Quote::VERSION\n";
foreach my $source (@sources) {
print "$source\n";
}
exit 0;
}
sub print_usage {
print STDERR
"Usage:
Check proper installation and version:
finance-quote-wrapper -v
Fetch quotes (input should be passed as JSON via stdin):
finance-quote-wrapper -f
";
}
sub sanitize_hash {
my (%quotehash) = @_;
@ -160,6 +180,30 @@ sub parse_commodities {
# Check for and load non-standard modules
check_modules ();
my %opts;
my $status = getopts('hvf', \%opts);
if (!$status)
{
print_usage();
exit 1;
}
if (exists $opts{'v'})
{
print_version();
}
elsif (exists $opts{'h'})
{
print_usage();
exit 0;
}
elsif (!exists $opts{'f'})
{
print_usage();
exit 1;
}
JSON::Parse->import(qw(valid_json parse_json));
my $json_input = do { local $/; <STDIN> };