You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

120 lines
3.7 KiB

  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/configuration.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/init.h>
  14. #include <apt-pkg/pkgsystem.h>
  15. #include <apt-pkg/strutl.h>
  16. #include <apt-private/private-cmndline.h>
  17. #include <apt-private/private-depends.h>
  18. #include <apt-private/private-download.h>
  19. #include <apt-private/private-install.h>
  20. #include <apt-private/private-list.h>
  21. #include <apt-private/private-main.h>
  22. #include <apt-private/private-moo.h>
  23. #include <apt-private/private-output.h>
  24. #include <apt-private/private-search.h>
  25. #include <apt-private/private-show.h>
  26. #include <apt-private/private-source.h>
  27. #include <apt-private/private-sources.h>
  28. #include <apt-private/private-update.h>
  29. #include <apt-private/private-upgrade.h>
  30. #include <iostream>
  31. #include <vector>
  32. #include <unistd.h>
  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. {"autopurge",&DoInstall, nullptr},
  61. {"purge", &DoInstall, nullptr},
  62. // system wide stuff
  63. {"update", &DoUpdate, _("update list of available packages")},
  64. {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
  65. {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
  66. // misc
  67. {"edit-sources", &EditSources, _("edit the source information file")},
  68. {"moo", &DoMoo, nullptr},
  69. // for compat with muscle memory
  70. {"dist-upgrade", &DoDistUpgrade, nullptr},
  71. {"showsrc",&ShowSrcPackage, nullptr},
  72. {"depends",&Depends, nullptr},
  73. {"rdepends",&RDepends, nullptr},
  74. {"policy",&Policy, nullptr},
  75. {"build-dep", &DoBuildDep,nullptr},
  76. {"clean", &DoClean, nullptr},
  77. {"autoclean", &DoAutoClean, nullptr},
  78. {"auto-clean", &DoAutoClean, nullptr},
  79. {"source", &DoSource, nullptr},
  80. {"download", &DoDownload, nullptr},
  81. {"changelog", &DoChangelog, nullptr},
  82. {nullptr, nullptr, nullptr}
  83. };
  84. }
  85. /*}}}*/
  86. int main(int argc, const char *argv[]) /*{{{*/
  87. {
  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. /*}}}*/