diff --git a/src/Arguments.cpp b/src/Arguments.cpp index e63dbd3ac..ff4aacacf 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -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 >::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 Arguments::list () { diff --git a/src/Arguments.h b/src/Arguments.h index b7e06239c..cefbe4b3d 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -50,6 +50,7 @@ public: void get_data_location (std::string&); void apply_overrides (); void resolve_aliases (); + void inject_defaults (); std::vector list (); static std::vector operator_list (); diff --git a/src/Context.cpp b/src/Context.cpp index c21af7f61..2dcd332d7 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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. diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index 827e42efc..c014bdbb6 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -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 ..."