GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
Gnucash::GnucashCli Class Reference
Inheritance diagram for Gnucash::GnucashCli:
Gnucash::CoreApp

Public Member Functions

 GnucashCli (const char *app_name)
 
void parse_command_line (int argc, char **argv)
 
int start (int argc, char **argv)
 
- Public Member Functions inherited from Gnucash::CoreApp
 CoreApp (const char *app_name)
 
void parse_command_line (int argc, char **argv)
 
void start (void)
 

Additional Inherited Members

- Protected Attributes inherited from Gnucash::CoreApp
std::string m_app_name
 
std::string m_tagline
 
boost::optional< std::string > m_log_to_filename
 
boost::optional< std::string > m_file_to_load
 
bpo::options_description m_opt_desc_all
 
std::unique_ptr< bpo::options_description > m_opt_desc_display
 
bpo::variables_map m_opt_map
 
bpo::positional_options_description m_pos_opt_desc
 

Detailed Description

Definition at line 52 of file gnucash-cli.cpp.

Constructor & Destructor Documentation

◆ GnucashCli()

Gnucash::GnucashCli::GnucashCli ( const char *  app_name)

Definition at line 73 of file gnucash-cli.cpp.

73 : Gnucash::CoreApp (app_name)
74{
75 configure_program_options();
76}

Member Function Documentation

◆ parse_command_line()

void Gnucash::GnucashCli::parse_command_line ( int  argc,
char **  argv 
)

Definition at line 79 of file gnucash-cli.cpp.

80{
81 Gnucash::CoreApp::parse_command_line (argc, argv);
82
83 if (!m_log_to_filename || m_log_to_filename->empty())
84 m_log_to_filename = "stderr";
85
86 if (m_namespace)
87 gnc_prefs_set_namespace_regexp (m_namespace->c_str());
88}

◆ start()

int Gnucash::GnucashCli::start ( int  argc,
char **  argv 
)

Definition at line 130 of file gnucash-cli.cpp.

131{
132 Gnucash::CoreApp::start();
133
134 if (!m_quotes_cmd.empty())
135 {
136 if (m_quotes_cmd.front() == "info")
137 {
138 return Gnucash::check_finance_quote ();
139 }
140 else if (m_quotes_cmd.front() == "get")
141 {
142 if (!m_file_to_load && m_quotes_cmd.size() == 2)
143 m_file_to_load = m_quotes_cmd[1];
144
145 if (!m_file_to_load || m_file_to_load->empty())
146 {
147 std::cerr << bl::translate("Missing data file parameter") << "\n\n"
148 << *m_opt_desc_display.get() << std::endl;
149 return 1;
150 }
151 else
152 return Gnucash::add_quotes (m_file_to_load);
153 }
154 else if (m_quotes_cmd.front() == "dump")
155 {
156 if (m_quotes_cmd.size() < 3 ||
157 (m_quotes_cmd[1] == "currency" &&
158 m_quotes_cmd.size() < 4))
159 {
160 std::cerr << bl::translate("Not enough information for quotes dump") << std::endl;
161 return 1;
162 }
163 auto source = m_quotes_cmd[1];
164 m_quotes_cmd.erase(m_quotes_cmd.begin(), m_quotes_cmd.begin() + 2);
165 return Gnucash::report_quotes(source.c_str(), m_quotes_cmd,
166 m_verbose);
167 }
168 else
169 {
170 std::cerr << bl::format (bl::translate("Unknown quotes command '{1}'")) % m_quotes_cmd.front() << "\n\n"
171 << *m_opt_desc_display.get() << std::endl;
172 return 1;
173 }
174 }
175
176 if (m_report_cmd)
177 {
178 if (*m_report_cmd == "run")
179 {
180 if (!m_file_to_load || m_file_to_load->empty())
181 {
182 std::cerr << _("Missing data file parameter") << "\n\n"
183 << *m_opt_desc_display.get() << std::endl;
184 return 1;
185 }
186 else
187 return Gnucash::run_report(m_file_to_load, m_report_name,
188 m_export_type, m_output_file);
189 }
190
191 // The command "list" does *not* test&pass the m_file_to_load
192 // argument because the reports are global rather than
193 // per-file objects. In the future, saved reports may be saved
194 // into the datafile, therefore one will need to be specified
195 // for loading.
196 else if (*m_report_cmd == "list")
197 return Gnucash::report_list ();
198
199 // The command "show" does test&pass the m_file_to_load
200 // argument, and will attempt to load datafile prior to
201 // describing report. If loading fails, it will continue
202 // showing report options.
203 else if (*m_report_cmd == "show")
204 if (!m_report_name || m_report_name->empty())
205 {
206 std::cerr << _("Missing --name parameter") << "\n\n"
207 << *m_opt_desc_display.get() << std::endl;
208 return 1;
209 }
210 else
211 return Gnucash::report_show (m_file_to_load, m_report_name);
212 else
213 {
214 std::cerr << bl::format (std::string{_("Unknown report command '{1}'")}) % *m_report_cmd << "\n\n"
215 << *m_opt_desc_display.get();
216 return 1;
217 }
218 }
219
220 std::cerr << _("Missing command or option") << "\n\n"
221 << *m_opt_desc_display.get() << std::endl;
222
223 return 1;
224}

The documentation for this class was generated from the following file: