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:
Paul Beckingham 2011-06-26 01:21:11 -04:00
parent 91e5a5e02e
commit 7faad5fb44
4 changed files with 54 additions and 44 deletions

View file

@ -436,48 +436,6 @@ void Arguments::categorize ()
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 ()
{

View file

@ -50,6 +50,7 @@ public:
void get_data_location (std::string&);
void apply_overrides ();
void resolve_aliases ();
void inject_defaults ();
std::vector <std::string> list ();
static std::vector <std::string> operator_list ();

View file

@ -116,9 +116,12 @@ void Context::initialize (int argc, const char** argv)
// Instantiate built-in column objects.
Column::factory (columns);
// Finally categorize all arguments.
// Categorize all arguments one more time.
args.categorize ();
// Handle default command and assumed 'info' command.
args.inject_defaults ();
// TODO Instantiate extension command objects.
// TODO Instantiate default command object.

View file

@ -149,7 +149,6 @@ int CmdCustom::execute (std::string& output)
if (maxlines)
maxlines -= (context.verbose ("blank") ? 1 : 0)
+ table_header
+ context.headers.size ()
+ context.footnotes.size ()
+ 1; // "X tasks shown ..."