* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <cstdlib>
-#include <cstring>
-
#include "args.hh"
#include "call_type.hh"
-#include "commands.hh"
+#include "command.hh"
#include "usage.hh"
int
main(int argc, const char *argv[])
{
- Args args = { argc, argv };
-
- if (!args.argc)
- usage();
-
- progname = pop_arg(&args);
+ Args args(argc, argv);
- const DispatchTable &dt = CallType::detect(args).getDispatch();
+ progname = args.pop("{progname}");
- const char *command = pop_arg(&args);
-
- if (!command)
+ if (!args.size())
usage();
- for (int i = 0; i < num_commands; ++i) {
- if (strcmp(command, command_table[i].name) != 0)
- continue;
+ CallType *ct = CallType::detect(args);
+ if (!ct)
+ usage();
- command_table[i].func(dt, &args);
- exit(0);
- }
+ if (!Command::run(ct->getDispatch(), args))
+ usage();
- usage();
+ exit(0);
}