Skip to content

Commit

Permalink
first element of newArgv will be the actual program name
Browse files Browse the repository at this point in the history
instead of the hard-coded "gnucash-cli"
  • Loading branch information
christopherlam committed Oct 27, 2023
1 parent 403728b commit c63ae6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 7 additions & 1 deletion gnucash/gnucash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ Gnucash::GnucashCli::start (int argc, char **argv)
std::cout << "Readwrite: " << (m_open_readwrite ? 'Y' : 'N') << std::endl;
std::cout << "Interactive: " << (m_interactive ? 'Y' : 'N') << "\n\n" << std::endl;

return Gnucash::run_scripting (m_script_args, m_file_to_load, m_language, m_script,
std::vector<const char*> newArgv =
{ argc ? argv[0] : "", m_file_to_load ? m_file_to_load->c_str() : ""};
std::transform (m_script_args.begin(), m_script_args.end(), std::back_inserter(newArgv),
[](const std::string& s) { return s.c_str(); });
// note the vector<const char*> is valid as long as script_args's strings are not damaged!

return Gnucash::run_scripting (newArgv, m_file_to_load, m_language, m_script,
m_open_readwrite, m_interactive);
}

Expand Down
8 changes: 1 addition & 7 deletions gnucash/gnucash-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ run_python_cli (int argc, char **argv, scripting_args* args)
#endif

int
Gnucash::run_scripting (std::vector<std::string> script_args,
Gnucash::run_scripting (std::vector<const char*> newArgv,
const bo_str& file_to_load,
std::string& language,
const bo_str& script,
Expand Down Expand Up @@ -666,12 +666,6 @@ Gnucash::run_scripting (std::vector<std::string> script_args,
gnc_shutdown_cli (1);
}

std::vector<const char*> newArgv =
{ "gnucash-cli", file_to_load ? file_to_load->c_str() : ""};
std::transform (script_args.begin(), script_args.end(), std::back_inserter(newArgv),
[](const std::string& s) { return s.c_str(); });
// note the vector<const char*> is valid as long as script_args's strings are not damaged!

gnc_prefs_init ();
gnc_ui_util_init();
if (file_to_load && boost::filesystem::is_regular_file (*file_to_load))
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnucash-commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Gnucash {
int report_list (void);
int report_show (const bo_str& file_to_load,
const bo_str& run_report);
int run_scripting (std::vector<std::string> m_script_args,
int run_scripting (std::vector<const char*> newArgv,
const bo_str& m_file_to_load,
std::string& m_language,
const bo_str& m_script,
Expand Down

0 comments on commit c63ae6d

Please sign in to comment.