Fixes Bug 695, ledger ignores --init-file
Handle --init-file as a special command option like the debug options. That wway we can have the argument captured before teh global scope is created.
This commit is contained in:
parent
41cc9a7f3c
commit
4b261f99bc
3 changed files with 18 additions and 4 deletions
|
|
@ -44,6 +44,7 @@
|
|||
namespace ledger {
|
||||
|
||||
static bool args_only = false;
|
||||
std::string _init_file;
|
||||
|
||||
global_scope_t::global_scope_t(char ** envp)
|
||||
{
|
||||
|
|
@ -126,6 +127,8 @@ void global_scope_t::read_init()
|
|||
}
|
||||
|
||||
TRACE_FINISH(init, 1);
|
||||
} else {
|
||||
throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -473,6 +476,10 @@ void handle_debug_options(int argc, char * argv[])
|
|||
_log_level = LOG_INFO;
|
||||
#endif
|
||||
}
|
||||
else if (i + 1 < argc && std::strcmp(argv[i], "--init-file") == 0) {
|
||||
_init_file = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (i + 1 < argc && std::strcmp(argv[i], "--debug") == 0) {
|
||||
#if DEBUG_ON
|
||||
_log_level = LOG_DEBUG;
|
||||
|
|
|
|||
14
src/global.h
14
src/global.h
|
|
@ -46,6 +46,8 @@ namespace ledger {
|
|||
class session_t;
|
||||
class report_t;
|
||||
|
||||
extern std::string _init_file;
|
||||
|
||||
class global_scope_t : public noncopyable, public scope_t
|
||||
{
|
||||
shared_ptr<session_t> session_ptr;
|
||||
|
|
@ -151,10 +153,14 @@ See LICENSE file included with the distribution for details and disclaimer.");
|
|||
OPTION__
|
||||
(global_scope_t, init_file_, // -i
|
||||
CTOR(global_scope_t, init_file_) {
|
||||
if (const char * home_var = std::getenv("HOME"))
|
||||
on(none, (path(home_var) / ".ledgerrc").string());
|
||||
else
|
||||
on(none, path("./.ledgerrc").string());
|
||||
if(!_init_file.empty())
|
||||
// _init_file is filled during handle_debug_options
|
||||
on(none, _init_file);
|
||||
else
|
||||
if (const char * home_var = std::getenv("HOME"))
|
||||
on(none, (path(home_var) / ".ledgerrc").string());
|
||||
else
|
||||
on(none, path("./.ledgerrc").string());
|
||||
});
|
||||
|
||||
OPTION(global_scope_t, options);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ int main(int argc, char * argv[], char * envp[])
|
|||
// --debug CATEGORY ; turns on debug logging
|
||||
// --trace LEVEL ; turns on trace logging
|
||||
// --memory ; turns on memory usage tracing
|
||||
// --init-file ; directs ledger to use a different init file
|
||||
handle_debug_options(argc, argv);
|
||||
#if VERIFY_ON
|
||||
IF_VERIFY() initialize_memory_tracing();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue