apt.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/
  33. {
  34. std::cout <<
  35. _("Usage: apt [options] command\n"
  36. "\n"
  37. "CLI for apt.\n")
  38. << std::endl;
  39. ShowHelpListCommands(Cmds);
  40. return true;
  41. }
  42. /*}}}*/
  43. std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
  44. {
  45. return {
  46. // query
  47. {"list", &DoList, _("list packages based on package names")},
  48. {"search", &DoSearch, _("search in package descriptions")},
  49. {"show", &ShowPackage, _("show package details")},
  50. // package stuff
  51. {"install", &DoInstall, _("install packages")},
  52. {"remove", &DoInstall, _("remove packages")},
  53. {"autoremove", &DoInstall, _("Remove automatically all unused packages")},
  54. {"auto-remove", &DoInstall, nullptr},
  55. {"purge", &DoInstall, nullptr},
  56. // system wide stuff
  57. {"update", &DoUpdate, _("update list of available packages")},
  58. {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
  59. {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
  60. {"dist-upgrade", &DoDistUpgrade, nullptr}, // for compat with muscle memory
  61. // misc
  62. {"edit-sources", &EditSources, _("edit the source information file")},
  63. {"moo", &DoMoo, nullptr},
  64. {nullptr, nullptr, nullptr}
  65. };
  66. }
  67. /*}}}*/
  68. int main(int argc, const char *argv[]) /*{{{*/
  69. {
  70. InitLocale();
  71. CommandLine CmdL;
  72. auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv);
  73. int const quiet = _config->FindI("quiet", 0);
  74. if (quiet == 2)
  75. {
  76. _config->CndSet("quiet::NoProgress", true);
  77. _config->Set("quiet", 1);
  78. }
  79. InitSignals();
  80. InitOutput();
  81. CheckIfCalledByScript(argc, argv);
  82. CheckIfSimulateMode(CmdL);
  83. return DispatchCommandLine(CmdL, Cmds);
  84. }
  85. /*}}}*/