apt.cc 3.1 KB

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