mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[cli-reports] implement --report list
Lists available reports.
This commit is contained in:
parent
e4e36e6843
commit
4d921c67c3
@ -100,7 +100,8 @@ Gnucash::GnucashCli::configure_program_options (void)
|
|||||||
bpo::options_description report_options(_("Report Generation Options"));
|
bpo::options_description report_options(_("Report Generation Options"));
|
||||||
report_options.add_options()
|
report_options.add_options()
|
||||||
("report,R", bpo::value (&m_report_cmd),
|
("report,R", bpo::value (&m_report_cmd),
|
||||||
_("Execute report related commands. Currently only one command is supported.\n\n"
|
_("Execute report related commands. The following commands are supported.\n\n"
|
||||||
|
" list: \tLists available reports.\n"
|
||||||
" run: \tRun the named report in the given GnuCash datafile.\n"))
|
" run: \tRun the named report in the given GnuCash datafile.\n"))
|
||||||
("name", bpo::value (&m_report_name),
|
("name", bpo::value (&m_report_name),
|
||||||
_("Name of the report to run\n"))
|
_("Name of the report to run\n"))
|
||||||
@ -150,6 +151,8 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
|
|||||||
return Gnucash::run_report(m_file_to_load, m_report_name,
|
return Gnucash::run_report(m_file_to_load, m_report_name,
|
||||||
m_export_type, m_output_file);
|
m_export_type, m_output_file);
|
||||||
}
|
}
|
||||||
|
else if (*m_report_cmd == "list")
|
||||||
|
return Gnucash::report_list ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n"
|
std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n"
|
||||||
|
@ -197,6 +197,20 @@ scm_run_report (void *data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
scm_report_list ([[maybe_unused]] void *data,
|
||||||
|
[[maybe_unused]] int argc, [[maybe_unused]] char **argv)
|
||||||
|
{
|
||||||
|
scm_c_eval_string("(debug-set! stack 200000)");
|
||||||
|
scm_c_use_module ("gnucash app-utils");
|
||||||
|
scm_c_use_module ("gnucash reports");
|
||||||
|
gnc_report_init ();
|
||||||
|
|
||||||
|
scm_call_0 (scm_c_eval_string ("gnc:cmdline-report-list"));
|
||||||
|
gnc_shutdown (0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Gnucash::add_quotes (const bo_str& uri)
|
Gnucash::add_quotes (const bo_str& uri)
|
||||||
{
|
{
|
||||||
@ -221,3 +235,10 @@ Gnucash::run_report (const bo_str& file_to_load,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Gnucash::report_list (void)
|
||||||
|
{
|
||||||
|
scm_boot_guile (0, nullptr, scm_report_list, NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -37,6 +37,6 @@ namespace Gnucash {
|
|||||||
const bo_str& run_report,
|
const bo_str& run_report,
|
||||||
const bo_str& export_type,
|
const bo_str& export_type,
|
||||||
const bo_str& output_file);
|
const bo_str& output_file);
|
||||||
|
int report_list (void);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -799,6 +799,18 @@ not found.")))
|
|||||||
(assoc-ref parent-export-types export-type) output-file)
|
(assoc-ref parent-export-types export-type) output-file)
|
||||||
(display "done!\n" (current-error-port))))))
|
(display "done!\n" (current-error-port))))))
|
||||||
|
|
||||||
|
(define-public (gnc:cmdline-report-list)
|
||||||
|
(for-each
|
||||||
|
(lambda (template)
|
||||||
|
(stderr-log "* ~a ~a\n"
|
||||||
|
(if (gnc:report-template-parent-type template) "C" " ")
|
||||||
|
(gnc:report-template-name template)))
|
||||||
|
(sort (hash-fold
|
||||||
|
(lambda (k v p) (if (gnc:report-template-in-menu? v) (cons v p) p))
|
||||||
|
'() *gnc:_report-templates_*)
|
||||||
|
(lambda (a b)
|
||||||
|
(string<? (gnc:report-template-name a) (gnc:report-template-name b))))))
|
||||||
|
|
||||||
(define-public (gnc:cmdline-run-report report export-type output-file dry-run?)
|
(define-public (gnc:cmdline-run-report report export-type output-file dry-run?)
|
||||||
(let ((templates (or (and=> (gnc:find-report-template report) list)
|
(let ((templates (or (and=> (gnc:find-report-template report) list)
|
||||||
(hash-fold
|
(hash-fold
|
||||||
@ -817,17 +829,7 @@ not found.")))
|
|||||||
(cond
|
(cond
|
||||||
((null? templates)
|
((null? templates)
|
||||||
(stderr-log "Cannot find ~s. Valid reports:\n" report)
|
(stderr-log "Cannot find ~s. Valid reports:\n" report)
|
||||||
(for-each
|
(gnc:cmdline-report-list)
|
||||||
(lambda (pair)
|
|
||||||
(when (gnc:report-template-in-menu? (cdr pair))
|
|
||||||
(stderr-log "* ~a ~a\n"
|
|
||||||
(if (gnc:report-template-parent-type (cdr pair)) "C" " ")
|
|
||||||
(gnc:report-template-name (cdr pair)))))
|
|
||||||
(sort (hash-map->list cons *gnc:_report-templates_*)
|
|
||||||
(lambda (a b)
|
|
||||||
(string<?
|
|
||||||
(gnc:report-template-name (cdr a))
|
|
||||||
(gnc:report-template-name (cdr b))))))
|
|
||||||
(stderr-log "\n"))
|
(stderr-log "\n"))
|
||||||
|
|
||||||
((pair? (cdr templates))
|
((pair? (cdr templates))
|
||||||
|
Loading…
Reference in New Issue
Block a user