apt.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <apt-private/private-source.h>
  28. #include <apt-private/private-depends.h>
  29. #include <apt-private/private-download.h>
  30. #include <unistd.h>
  31. #include <iostream>
  32. #include <vector>
  33. #include <apti18n.h>
  34. /*}}}*/
  35. static bool ShowHelp(CommandLine &) /*{{{*/
  36. {
  37. std::cout <<
  38. _("Usage: apt [options] command\n"
  39. "\n"
  40. "apt is a commandline package manager and provides commands for\n"
  41. "searching and managing as well as querying information about packages.\n"
  42. "It provides the same functionality as the specialized APT tools,\n"
  43. "like apt-get and apt-cache, but enables options more suitable for\n"
  44. "interactive use by default.\n");
  45. return true;
  46. }
  47. /*}}}*/
  48. static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
  49. {
  50. return {
  51. // query
  52. {"list", &DoList, _("list packages based on package names")},
  53. {"search", &DoSearch, _("search in package descriptions")},
  54. {"show", &ShowPackage, _("show package details")},
  55. // package stuff
  56. {"install", &DoInstall, _("install packages")},
  57. {"remove", &DoInstall, _("remove packages")},
  58. {"autoremove", &DoInstall, _("Remove automatically all unused packages")},
  59. {"auto-remove", &DoInstall, nullptr},
  60. {"purge", &DoInstall, nullptr},
  61. // system wide stuff
  62. {"update", &DoUpdate, _("update list of available packages")},
  63. {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
  64. {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
  65. // misc
  66. {"edit-sources", &EditSources, _("edit the source information file")},
  67. {"moo", &DoMoo, nullptr},
  68. // for compat with muscle memory
  69. {"dist-upgrade", &DoDistUpgrade, nullptr},
  70. {"showsrc",&ShowSrcPackage, nullptr},
  71. {"depends",&Depends, nullptr},
  72. {"rdepends",&RDepends, nullptr},
  73. {"policy",&Policy, nullptr},
  74. {"build-dep", &DoBuildDep,nullptr},
  75. {"clean", &DoClean, nullptr},
  76. {"autoclean", &DoAutoClean, nullptr},
  77. {"auto-clean", &DoAutoClean, nullptr},
  78. {"source", &DoSource, nullptr},
  79. {"download", &DoDownload, nullptr},
  80. {"changelog", &DoChangelog, nullptr},
  81. {nullptr, nullptr, nullptr}
  82. };
  83. }
  84. /*}}}*/
  85. int main(int argc, const char *argv[]) /*{{{*/
  86. {
  87. InitLocale();
  88. CommandLine CmdL;
  89. auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
  90. int const quiet = _config->FindI("quiet", 0);
  91. if (quiet == 2)
  92. {
  93. _config->CndSet("quiet::NoProgress", true);
  94. _config->Set("quiet", 1);
  95. }
  96. InitSignals();
  97. InitOutput();
  98. CheckIfCalledByScript(argc, argv);
  99. CheckIfSimulateMode(CmdL);
  100. return DispatchCommandLine(CmdL, Cmds);
  101. }
  102. /*}}}*/