Command Line Defaults
- Implemented support for rc.default.command. - Implemented support for assumed info command. - Implemented Arguments::inject_defaults to insert default arguments at just the right location. - Corrected CmdCustom handling of limit:page.
This commit is contained in:
@@ -436,48 +436,6 @@ void Arguments::categorize ()
|
|||||||
arg->second = "word";
|
arg->second = "word";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no command was specified, and there were no command line arguments
|
|
||||||
// then invoke the default command.
|
|
||||||
if (!found_command)
|
|
||||||
{
|
|
||||||
if (!found_sequence)
|
|
||||||
{
|
|
||||||
// TODO Invoke the default command.
|
|
||||||
std::cout << "DEFAULT COMMAND\n";
|
|
||||||
/*
|
|
||||||
// Apply overrides, if any.
|
|
||||||
std::string defaultCommand = config.get ("default.command");
|
|
||||||
if (defaultCommand != "")
|
|
||||||
{
|
|
||||||
// Add on the overrides.
|
|
||||||
defaultCommand += " " + file_override + " " + var_overrides;
|
|
||||||
|
|
||||||
// Stuff the command line.
|
|
||||||
args.clear ();
|
|
||||||
split (args, defaultCommand, ' ');
|
|
||||||
header ("[task " + trim (defaultCommand) + "]");
|
|
||||||
|
|
||||||
// Reinitialize the context and recurse.
|
|
||||||
file_override = "";
|
|
||||||
var_overrides = "";
|
|
||||||
footnotes.clear ();
|
|
||||||
//initialize ();
|
|
||||||
parse (args, cmd, task, sequence, subst, filter);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw std::string (STRING_TRIVIAL_INPUT);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the command "task 123" is entered, but with no modifier arguments,
|
|
||||||
// then the actual command is assumed to be "info".
|
|
||||||
else if (!found_non_sequence)
|
|
||||||
{
|
|
||||||
context.header (STRING_ASSUME_INFO);
|
|
||||||
push_back (std::make_pair ("information", "command"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -609,6 +567,55 @@ void Arguments::resolve_aliases ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Arguments::inject_defaults ()
|
||||||
|
{
|
||||||
|
bool found_command = false;
|
||||||
|
bool found_sequence = false;
|
||||||
|
bool found_other = false;
|
||||||
|
|
||||||
|
std::vector <std::pair <std::string, std::string> >::iterator arg;
|
||||||
|
for (arg = this->begin (); arg != this->end (); ++arg)
|
||||||
|
{
|
||||||
|
if (arg->second == "command")
|
||||||
|
found_command = true;
|
||||||
|
|
||||||
|
else if (arg->second == "id")
|
||||||
|
found_sequence = true;
|
||||||
|
|
||||||
|
else if (arg->second != "program" &&
|
||||||
|
arg->second != "override" &&
|
||||||
|
arg->second != "rc")
|
||||||
|
found_other = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no command was specified, and there were no command line arguments
|
||||||
|
// then invoke the default command.
|
||||||
|
if (!found_command)
|
||||||
|
{
|
||||||
|
if (found_other || !found_sequence)
|
||||||
|
{
|
||||||
|
// Apply overrides, if any.
|
||||||
|
std::string defaultCommand = context.config.get ("default.command");
|
||||||
|
if (defaultCommand != "")
|
||||||
|
{
|
||||||
|
capture_first (defaultCommand);
|
||||||
|
context.header ("[task " + trim (defaultCommand) + "]");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw std::string (STRING_TRIVIAL_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the command "task 123" is entered, but with no modifier arguments,
|
||||||
|
// then the actual command is assumed to be "info".
|
||||||
|
else if (found_sequence)
|
||||||
|
{
|
||||||
|
context.header (STRING_ASSUME_INFO);
|
||||||
|
push_back (std::make_pair ("information", "command"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::vector <std::string> Arguments::list ()
|
std::vector <std::string> Arguments::list ()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
void get_data_location (std::string&);
|
void get_data_location (std::string&);
|
||||||
void apply_overrides ();
|
void apply_overrides ();
|
||||||
void resolve_aliases ();
|
void resolve_aliases ();
|
||||||
|
void inject_defaults ();
|
||||||
|
|
||||||
std::vector <std::string> list ();
|
std::vector <std::string> list ();
|
||||||
static std::vector <std::string> operator_list ();
|
static std::vector <std::string> operator_list ();
|
||||||
|
|||||||
@@ -116,9 +116,12 @@ void Context::initialize (int argc, const char** argv)
|
|||||||
// Instantiate built-in column objects.
|
// Instantiate built-in column objects.
|
||||||
Column::factory (columns);
|
Column::factory (columns);
|
||||||
|
|
||||||
// Finally categorize all arguments.
|
// Categorize all arguments one more time.
|
||||||
args.categorize ();
|
args.categorize ();
|
||||||
|
|
||||||
|
// Handle default command and assumed 'info' command.
|
||||||
|
args.inject_defaults ();
|
||||||
|
|
||||||
// TODO Instantiate extension command objects.
|
// TODO Instantiate extension command objects.
|
||||||
// TODO Instantiate default command object.
|
// TODO Instantiate default command object.
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ int CmdCustom::execute (std::string& output)
|
|||||||
if (maxlines)
|
if (maxlines)
|
||||||
maxlines -= (context.verbose ("blank") ? 1 : 0)
|
maxlines -= (context.verbose ("blank") ? 1 : 0)
|
||||||
+ table_header
|
+ table_header
|
||||||
+ context.headers.size ()
|
|
||||||
+ context.footnotes.size ()
|
+ context.footnotes.size ()
|
||||||
+ 1; // "X tasks shown ..."
|
+ 1; // "X tasks shown ..."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user