apt.cc 3.5 KB

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