Support for memory-only caching
[ntk/apt.git] / cmdline / apt-config.cc
index 7dfb591..3a2a4d9 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: apt-config.cc,v 1.1 1998/11/22 23:37:07 jgg Exp $
+// $Id: apt-config.cc,v 1.4 1999/03/29 19:28:52 jgg Exp $
 /* ######################################################################
    
    APT Config - Program to manipulate APT configuration files
@@ -47,6 +47,8 @@ int ShowHelp()
 {
    cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
        " compiled on " << __DATE__ << "  " << __TIME__ << endl;
+   if (_config->FindB("version") == true)
+      return 100;
    
    cout << "Usage: apt-config [options] command" << endl;
    cout << endl;
@@ -58,7 +60,7 @@ int ShowHelp()
    cout << "Options:" << endl;
    cout << "  -h   This help text." << endl;
    cout << "  -c=? Read this configuration file" << endl;
-   cout << "  -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
+   cout << "  -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
    return 100;
 }
                                                                        /*}}}*/
@@ -67,9 +69,12 @@ int main(int argc,const char *argv[])
 {
    CommandLine::Args Args[] = {
       {'h',"help","help",0},
+      {'v',"version","version",0},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'o',"option",0,CommandLine::ArbItem},
       {0,0,0,0}};
+   CommandLine::Dispatch Cmds[] = {{"shell",&DoShell},
+                                   {0,0}};
    
    // Parse the command line and initialize the package library
    CommandLine CmdL(Args,_config);
@@ -84,29 +89,10 @@ int main(int argc,const char *argv[])
    if (_config->FindB("help") == true ||
        CmdL.FileSize() == 0)
       return ShowHelp();
-   
-   // Match the operation
-   struct 
-   {
-      const char *Match;
-      bool (*Handler)(CommandLine &);
-   } Map[] = {{"shell",&DoShell},
-              {0,0}};
-   int I;
-   for (I = 0; Map[I].Match != 0; I++)
-   {
-      if (strcmp(CmdL.FileList[0],Map[I].Match) == 0)
-      {
-        if (Map[I].Handler(CmdL) == false && _error->PendingError() == false)
-           _error->Error("Handler silently failed");
-        break;
-      }
-   }
-      
-   // No matching name
-   if (Map[I].Match == 0)
-      _error->Error("Invalid operation %s", CmdL.FileList[0]);
 
+   // Match the operation
+   CmdL.DispatchArg(Cmds);
+   
    // Print any errors or warnings found during parsing
    if (_error->empty() == false)
    {