diff --git a/libgnucash/app-utils/gnc-quotes.cpp b/libgnucash/app-utils/gnc-quotes.cpp index 28cddccd77..42bbbacbb5 100644 --- a/libgnucash/app-utils/gnc-quotes.cpp +++ b/libgnucash/app-utils/gnc-quotes.cpp @@ -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()); diff --git a/libgnucash/quotes/finance-quote-wrapper.in b/libgnucash/quotes/finance-quote-wrapper.in index 5089dec74c..4f05516ad0 100755 --- a/libgnucash/quotes/finance-quote-wrapper.in +++ b/libgnucash/quotes/finance-quote-wrapper.in @@ -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 $/; };