apt.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. apt - CLI UI for apt
  5. Returns 100 on failure, 0 on success.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include<config.h>
  10. #include <apt-pkg/cmndline.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/init.h>
  13. #include <apt-pkg/pkgsystem.h>
  14. #include <apt-pkg/strutl.h>
  15. #include <apt-pkg/configuration.h>
  16. #include <apt-private/private-list.h>
  17. #include <apt-private/private-search.h>
  18. #include <apt-private/private-install.h>
  19. #include <apt-private/private-output.h>
  20. #include <apt-private/private-update.h>
  21. #include <apt-private/private-cmndline.h>
  22. #include <apt-private/private-moo.h>
  23. #include <apt-private/private-upgrade.h>
  24. #include <apt-private/private-show.h>
  25. #include <apt-private/private-main.h>
  26. #include <apt-private/private-sources.h>
  27. #include <unistd.h>
  28. #include <iostream>
  29. #include <vector>
  30. #include <apti18n.h>
  31. /*}}}*/
  32. static bool ShowHelp(CommandLine &)
  33. {
  34. ioprintf(c1out, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
  35. // FIXME: generate from CommandLine
  36. c1out <<
  37. _("Usage: apt [options] command\n"
  38. "\n"
  39. "CLI for apt.\n"
  40. "Basic commands: \n"
  41. " list - list packages based on package names\n"
  42. " search - search in package descriptions\n"
  43. " show - show package details\n"
  44. "\n"
  45. " update - update list of available packages\n"
  46. "\n"
  47. " install - install packages\n"
  48. " remove - remove packages\n"
  49. " autoremove - Remove automatically all unused packages\n"
  50. "\n"
  51. " upgrade - upgrade the system by installing/upgrading packages\n"
  52. " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
  53. "\n"
  54. " edit-sources - edit the source information file\n"
  55. );
  56. return true;
  57. }
  58. int main(int argc, const char *argv[]) /*{{{*/
  59. {
  60. CommandLine::Dispatch Cmds[] = {
  61. // query
  62. {"list",&DoList},
  63. {"search", &DoSearch},
  64. {"show", &ShowPackage},
  65. // package stuff
  66. {"install",&DoInstall},
  67. {"remove", &DoInstall},
  68. {"autoremove", &DoInstall},
  69. {"auto-remove", &DoInstall},
  70. {"purge", &DoInstall},
  71. // system wide stuff
  72. {"update",&DoUpdate},
  73. {"upgrade",&DoUpgrade},
  74. {"full-upgrade",&DoDistUpgrade},
  75. // for compat with muscle memory
  76. {"dist-upgrade",&DoDistUpgrade},
  77. // misc
  78. {"edit-sources",&EditSources},
  79. // helper
  80. {"moo",&DoMoo},
  81. {"help",&ShowHelp},
  82. {0,0}};
  83. std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
  84. // Init the signals
  85. InitSignals();
  86. // Init the output
  87. InitOutput();
  88. // Set up gettext support
  89. setlocale(LC_ALL,"");
  90. textdomain(PACKAGE);
  91. if(pkgInitConfig(*_config) == false)
  92. {
  93. _error->DumpErrors();
  94. return 100;
  95. }
  96. // Parse the command line and initialize the package library
  97. CommandLine CmdL;
  98. ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
  99. if(!isatty(STDOUT_FILENO) &&
  100. _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
  101. {
  102. std::cerr << std::endl
  103. << "WARNING: " << argv[0] << " "
  104. << "does not have a stable CLI interface yet. "
  105. << "Use with caution in scripts."
  106. << std::endl
  107. << std::endl;
  108. }
  109. // see if we are in simulate mode
  110. CheckSimulateMode(CmdL);
  111. // parse args
  112. CmdL.DispatchArg(Cmds);
  113. // Print any errors or warnings found during parsing
  114. bool const Errors = _error->PendingError();
  115. if (_config->FindI("quiet",0) > 0)
  116. _error->DumpErrors();
  117. else
  118. _error->DumpErrors(GlobalError::DEBUG);
  119. return Errors == true ? 100 : 0;
  120. }
  121. /*}}}*/