apt.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 &)
  33. {
  34. ioprintf(c1out, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
  35. // FIXME: generate from CommandLine
  36. c1out <<
  37. _("Usage: apt [options] command\n"
  38. "\n"
  39. "CLI for apt.\n"
  40. "Basic commands: \n"
  41. " list - list packages based on package names\n"
  42. " search - search in package descriptions\n"
  43. " show - show package details\n"
  44. "\n"
  45. " update - update list of available packages\n"
  46. "\n"
  47. " install - install packages\n"
  48. " remove - remove packages\n"
  49. "\n"
  50. " upgrade - upgrade the system by installing/upgrading packages\n"
  51. " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
  52. "\n"
  53. " edit-sources - edit the source information file\n"
  54. );
  55. return true;
  56. }
  57. int main(int argc, const char *argv[]) /*{{{*/
  58. {
  59. CommandLine::Dispatch Cmds[] = {
  60. // query
  61. {"list",&DoList},
  62. {"search", &FullTextSearch},
  63. {"show", &APT::Cmd::ShowPackage},
  64. // package stuff
  65. {"install",&DoInstall},
  66. {"remove", &DoInstall},
  67. {"purge", &DoInstall},
  68. // system wide stuff
  69. {"update",&DoUpdate},
  70. {"upgrade",&DoUpgrade},
  71. {"full-upgrade",&DoDistUpgrade},
  72. // for compat with muscle memory
  73. {"dist-upgrade",&DoDistUpgrade},
  74. // misc
  75. {"edit-sources",&EditSources},
  76. // helper
  77. {"moo",&DoMoo},
  78. {"help",&ShowHelp},
  79. {0,0}};
  80. std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
  81. // Init the signals
  82. InitSignals();
  83. // Init the output
  84. InitOutput();
  85. // Set up gettext support
  86. setlocale(LC_ALL,"");
  87. textdomain(PACKAGE);
  88. if(pkgInitConfig(*_config) == false)
  89. {
  90. _error->DumpErrors();
  91. return 100;
  92. }
  93. // some different defaults
  94. _config->CndSet("DPkg::Progress-Fancy", "1");
  95. _config->CndSet("Apt::Color", "1");
  96. _config->CndSet("APT::Get::Upgrade-Allow-New", true);
  97. _config->CndSet("APT::Cmd::Show-Update-Stats", true);
  98. // Parse the command line and initialize the package library
  99. CommandLine CmdL;
  100. ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
  101. if(!isatty(STDOUT_FILENO) &&
  102. _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
  103. {
  104. std::cerr << std::endl
  105. << "WARNING: " << argv[0] << " "
  106. << "does not have a stable CLI interface yet. "
  107. << "Use with caution in scripts."
  108. << std::endl
  109. << std::endl;
  110. }
  111. // see if we are in simulate mode
  112. CheckSimulateMode(CmdL);
  113. // parse args
  114. CmdL.DispatchArg(Cmds);
  115. // Print any errors or warnings found during parsing
  116. bool const Errors = _error->PendingError();
  117. if (_config->FindI("quiet",0) > 0)
  118. _error->DumpErrors();
  119. else
  120. _error->DumpErrors(GlobalError::DEBUG);
  121. return Errors == true ? 100 : 0;
  122. }
  123. /*}}}*/