CLI
- Added a strict analysis mode that throws errors. In non-strict mode no errors are thrown because parsing is incomplete most of the time, and only the final pass needs to be strict.
This commit is contained in:
13
src/CLI.cpp
13
src/CLI.cpp
@@ -219,6 +219,7 @@ const std::string A::dump () const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CLI::CLI ()
|
CLI::CLI ()
|
||||||
|
: _strict (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,13 +284,16 @@ void CLI::add (const std::string& arg)
|
|||||||
// Intended to be called after ::initialize() and ::add(), to perform the final
|
// Intended to be called after ::initialize() and ::add(), to perform the final
|
||||||
// analysis. Analysis is also performed directly after the above, because there
|
// analysis. Analysis is also performed directly after the above, because there
|
||||||
// is a need to extract overrides early, before entities are proviedd.
|
// is a need to extract overrides early, before entities are proviedd.
|
||||||
void CLI::analyze (bool parse /* = true */)
|
void CLI::analyze (bool parse /* = true */, bool strict /* = false */)
|
||||||
{
|
{
|
||||||
// Clean what needs to be cleaned. Most in this case.
|
// Clean what needs to be cleaned. Most in this case.
|
||||||
_args.clear ();
|
_args.clear ();
|
||||||
_id_ranges.clear ();
|
_id_ranges.clear ();
|
||||||
_uuid_list.clear ();
|
_uuid_list.clear ();
|
||||||
|
|
||||||
|
// For propagation.
|
||||||
|
_strict = strict;
|
||||||
|
|
||||||
for (int i = 0; i < _original_args.size (); ++i)
|
for (int i = 0; i < _original_args.size (); ++i)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
@@ -1785,13 +1789,10 @@ void CLI::injectDefaults ()
|
|||||||
context.header ("[" + combined + "]");
|
context.header ("[" + combined + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO This fails because when ::injectDefaults is first run,
|
// Only an error in strict mode.
|
||||||
// ::applyOverrides has not yet been called.
|
else if (_strict)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
throw std::string (STRING_TRIVIAL_INPUT);
|
throw std::string (STRING_TRIVIAL_INPUT);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
void entity (const std::string&, const std::string&);
|
void entity (const std::string&, const std::string&);
|
||||||
void initialize (int, const char**);
|
void initialize (int, const char**);
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
void analyze (bool parse = true);
|
void analyze (bool parse = true, bool strict = false);
|
||||||
void applyOverrides ();
|
void applyOverrides ();
|
||||||
void getOverride (std::string&, File&);
|
void getOverride (std::string&, File&);
|
||||||
void getDataLocation (Path&);
|
void getDataLocation (Path&);
|
||||||
@@ -132,6 +132,7 @@ public:
|
|||||||
|
|
||||||
std::vector <std::pair <int, int> > _id_ranges;
|
std::vector <std::pair <int, int> > _id_ranges;
|
||||||
std::vector <std::string> _uuid_list;
|
std::vector <std::string> _uuid_list;
|
||||||
|
bool _strict;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ int Context::initialize (int argc, const char** argv)
|
|||||||
cli.entity ("attribute", col->first);
|
cli.entity ("attribute", col->first);
|
||||||
|
|
||||||
staticInitialization (); // Decouple code from Context.
|
staticInitialization (); // Decouple code from Context.
|
||||||
cli.analyze (); // Parse all elements.
|
cli.analyze (true, true); // Parse all elements, strict mode.
|
||||||
|
|
||||||
tdb2.set_location (data_dir); // Prepare the task database.
|
tdb2.set_location (data_dir); // Prepare the task database.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user