From cfacba5230f2e6bb88a1949505843ac22ed342d5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 25 Nov 2013 08:36:57 +0100 Subject: add basic "edit-sources" command --- cmdline/apt.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index e30967ec2..ef31d0029 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -54,8 +54,28 @@ #include #include #include +#include /*}}}*/ +// EditSource - EditSourcesList /*{{{*/ +// --------------------------------------------------------------------- +bool EditSources(CommandLine &CmdL) +{ + // FIXME: suport CmdL.FileList to specify sources.list.d files + + std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist"); + + // FIXME: take hash before, + // when changed display message to apt update + // do syntax check after save (like visudo) + + EditFileInSensibleEditor(sourceslist); + + return true; +} + /*}}}*/ + + bool ShowHelp(CommandLine &CmdL) { ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, @@ -74,6 +94,8 @@ bool ShowHelp(CommandLine &CmdL) " update - update list of available packages\n" " install - install packages\n" " upgrade - upgrade the systems packages\n" + "\n" + " edit-sources - edit the source information file\n" ); return true; @@ -89,6 +111,8 @@ int main(int argc, const char *argv[]) /*{{{*/ {"remove", &DoInstall}, {"update",&DoUpdate}, {"upgrade",&DoUpgradeWithAllowNewPackages}, + // misc + {"edit-sources",&EditSources}, // helper {"moo",&DoMoo}, {"help",&ShowHelp}, -- cgit v1.2.3 From d2524a53bbd219ee6d069006fd243a5bcda0245b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Nov 2013 09:22:40 +0100 Subject: add syntax check for sources.list --- cmdline/apt.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index ef31d0029..38610e731 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -67,9 +67,22 @@ bool EditSources(CommandLine &CmdL) // FIXME: take hash before, // when changed display message to apt update - // do syntax check after save (like visudo) - - EditFileInSensibleEditor(sourceslist); + bool res; + pkgSourceList sl; + + do { + EditFileInSensibleEditor(sourceslist); + _error->PushToStack(); + res = sl.Read(sourceslist); + if (!res) { + std::string outs; + strprintf(outs, _("Failed to parse %s. Edit again? "), + sourceslist.c_str()); + std::cout << outs; + res = !YnPrompt(true); + } + _error->RevertToStack(); + } while (res == false); return true; } -- cgit v1.2.3 From e6645b9fb9ba3a7ff7b6663af3f5e1bcb6f23d78 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Nov 2013 10:32:21 +0100 Subject: add check when sources.list changed --- cmdline/apt.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 38610e731..47187fac2 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -61,21 +62,21 @@ // --------------------------------------------------------------------- bool EditSources(CommandLine &CmdL) { - // FIXME: suport CmdL.FileList to specify sources.list.d files + bool res; + pkgSourceList sl; + std::string outs; + // FIXME: suport CmdL.FileList to specify sources.list.d files std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist"); - // FIXME: take hash before, - // when changed display message to apt update - bool res; - pkgSourceList sl; + HashString before; + before.FromFile(sourceslist); do { EditFileInSensibleEditor(sourceslist); _error->PushToStack(); res = sl.Read(sourceslist); if (!res) { - std::string outs; strprintf(outs, _("Failed to parse %s. Edit again? "), sourceslist.c_str()); std::cout << outs; @@ -84,6 +85,13 @@ bool EditSources(CommandLine &CmdL) _error->RevertToStack(); } while (res == false); + if (!before.VerifyFile(sourceslist)) { + strprintf( + outs, _("Your '%s' file changed, please run 'apt-get update'."), + sourceslist.c_str()); + std::cout << outs << std::endl; + } + return true; } /*}}}*/ -- cgit v1.2.3 From 9e6b13f3751f8a1287ff79861980afb7792a5f9e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Nov 2013 12:15:47 +0100 Subject: move EditSources into its own file --- cmdline/apt.cc | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 47187fac2..4bcae0aba 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -56,45 +56,9 @@ #include #include #include +#include /*}}}*/ -// EditSource - EditSourcesList /*{{{*/ -// --------------------------------------------------------------------- -bool EditSources(CommandLine &CmdL) -{ - bool res; - pkgSourceList sl; - std::string outs; - - // FIXME: suport CmdL.FileList to specify sources.list.d files - std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist"); - - HashString before; - before.FromFile(sourceslist); - - do { - EditFileInSensibleEditor(sourceslist); - _error->PushToStack(); - res = sl.Read(sourceslist); - if (!res) { - strprintf(outs, _("Failed to parse %s. Edit again? "), - sourceslist.c_str()); - std::cout << outs; - res = !YnPrompt(true); - } - _error->RevertToStack(); - } while (res == false); - - if (!before.VerifyFile(sourceslist)) { - strprintf( - outs, _("Your '%s' file changed, please run 'apt-get update'."), - sourceslist.c_str()); - std::cout << outs << std::endl; - } - - return true; -} - /*}}}*/ bool ShowHelp(CommandLine &CmdL) -- cgit v1.2.3 From 82e7f817a434e29df9ec6fbf19acfd8e7cd890e5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 07:48:43 +0100 Subject: add apt upgrade --dist --- cmdline/apt.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 4bcae0aba..4dc826632 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -86,6 +86,15 @@ bool ShowHelp(CommandLine &CmdL) return true; } +// figure out what kind of upgrade the user wants +bool DoAptUpgrade(CommandLine &CmdL) +{ + if (_config->FindB("Apt::Cmd::Dist-Upgrade")) + return DoDistUpgrade(CmdL); + else + return DoUpgradeWithAllowNewPackages(CmdL); +} + int main(int argc, const char *argv[]) /*{{{*/ { CommandLine::Dispatch Cmds[] = {{"list",&List}, @@ -95,7 +104,7 @@ int main(int argc, const char *argv[]) /*{{{*/ {"install",&DoInstall}, {"remove", &DoInstall}, {"update",&DoUpdate}, - {"upgrade",&DoUpgradeWithAllowNewPackages}, + {"upgrade",&DoAptUpgrade}, // misc {"edit-sources",&EditSources}, // helper -- cgit v1.2.3 From b7159ec8835e61ea3069213d9188be91c109e32c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 07:52:22 +0100 Subject: reword !isatty() warning --- cmdline/apt.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 4dc826632..2d3966e86 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -117,10 +117,9 @@ int main(int argc, const char *argv[]) /*{{{*/ if(!isatty(1)) { std::cerr << std::endl - << "WARNING WARNING " - << argv[0] - << " is *NOT* intended for scripts " - << "use at your own peril^Wrisk" + << "WARNING: " << argv[0] << " " + << "does not have a stable CLI interface yet. " + << "Use with caution in scripts." << std::endl << std::endl; } -- cgit v1.2.3 From 1410955589dc9f0eaa290907cac070b7ebf93b6a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 08:43:14 +0100 Subject: add missing integration test for "apt list" --- cmdline/apt.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 2d3966e86..8dc4c292a 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -114,16 +114,6 @@ int main(int argc, const char *argv[]) /*{{{*/ std::vector Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv)); - if(!isatty(1)) - { - std::cerr << std::endl - << "WARNING: " << argv[0] << " " - << "does not have a stable CLI interface yet. " - << "Use with caution in scripts." - << std::endl - << std::endl; - } - InitOutput(); // Set up gettext support @@ -149,6 +139,19 @@ int main(int argc, const char *argv[]) /*{{{*/ return 100; } + if(!isatty(STDOUT_FILENO) && + _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false) + { + std::cerr << std::endl + << "WARNING: " << argv[0] << " " + << "does not have a stable CLI interface yet. " + << "Use with caution in scripts." + << std::endl + << std::endl; + } + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) + _config->Set("quiet","1"); + // See if the help should be shown if (_config->FindB("help") == true || _config->FindB("version") == true || -- cgit v1.2.3 From 8a59cc322ac57c6662949e957611ed718a5f5119 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 21:38:23 +0100 Subject: add purge to the apt cmdline --- cmdline/apt.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 8dc4c292a..61d5d938a 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -71,13 +71,16 @@ bool ShowHelp(CommandLine &CmdL) _("Usage: apt [options] command\n" "\n" "CLI for apt.\n" - "Commands: \n" + "Basic commands: \n" " list - list packages based on package names\n" " search - search in package descriptions\n" " show - show package details\n" "\n" " update - update list of available packages\n" + "\n" " install - install packages\n" + " remove - remove packages\n" + "\n" " upgrade - upgrade the systems packages\n" "\n" " edit-sources - edit the source information file\n" @@ -103,6 +106,7 @@ int main(int argc, const char *argv[]) /*{{{*/ // needs root {"install",&DoInstall}, {"remove", &DoInstall}, + {"purge", &DoInstall}, {"update",&DoUpdate}, {"upgrade",&DoAptUpgrade}, // misc -- cgit v1.2.3 From 6d73fe5be080e66a4f6ff2b250ed1957ae7ac063 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Jan 2014 16:41:00 +0100 Subject: add test for apt show --- cmdline/apt.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 61d5d938a..07ade6b7c 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -103,10 +103,11 @@ int main(int argc, const char *argv[]) /*{{{*/ CommandLine::Dispatch Cmds[] = {{"list",&List}, {"search", &FullTextSearch}, {"show", &APT::Cmd::ShowPackage}, - // needs root + // package stuff {"install",&DoInstall}, {"remove", &DoInstall}, {"purge", &DoInstall}, + // system wide stuff {"update",&DoUpdate}, {"upgrade",&DoAptUpgrade}, // misc -- cgit v1.2.3 From 59e81cec3e2277e367f14f113168421909c42035 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 24 Jan 2014 20:33:02 +0100 Subject: add "apt full-upgrade" and tweak "apt upgrade" There is a new "apt full-upgrade" that performs a apt-get dist-upgrade. "apt dist-upgrade" is still supported as a alias. The "apt upgrade" code is changed so that it mirrors the behavior of "apt-get upgrade --with-new-pkgs" and also honors "apt uprade --no-new-pkgs". --- cmdline/apt.cc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 07ade6b7c..6fe25e3f3 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -81,7 +81,8 @@ bool ShowHelp(CommandLine &CmdL) " install - install packages\n" " remove - remove packages\n" "\n" - " upgrade - upgrade the systems packages\n" + " upgrade - upgrade the system by installing/upgrading packages\n" + "full-upgrade - upgrade the system by removing/installing/upgrading packages\n" "\n" " edit-sources - edit the source information file\n" ); @@ -89,29 +90,29 @@ bool ShowHelp(CommandLine &CmdL) return true; } -// figure out what kind of upgrade the user wants -bool DoAptUpgrade(CommandLine &CmdL) -{ - if (_config->FindB("Apt::Cmd::Dist-Upgrade")) - return DoDistUpgrade(CmdL); - else - return DoUpgradeWithAllowNewPackages(CmdL); -} - int main(int argc, const char *argv[]) /*{{{*/ { - CommandLine::Dispatch Cmds[] = {{"list",&List}, + CommandLine::Dispatch Cmds[] = { + // query + {"list",&List}, {"search", &FullTextSearch}, {"show", &APT::Cmd::ShowPackage}, + // package stuff {"install",&DoInstall}, {"remove", &DoInstall}, {"purge", &DoInstall}, + // system wide stuff {"update",&DoUpdate}, - {"upgrade",&DoAptUpgrade}, + {"upgrade",&DoUpgrade}, + {"full-upgrade",&DoDistUpgrade}, + // for compat with muscle memory + {"dist-upgrade",&DoDistUpgrade}, + // misc {"edit-sources",&EditSources}, + // helper {"moo",&DoMoo}, {"help",&ShowHelp}, @@ -131,9 +132,10 @@ int main(int argc, const char *argv[]) /*{{{*/ return 100; } - // FIXME: move into a new libprivate/private-install.cc:Install() - _config->Set("DPkgPM::Progress", "1"); - _config->Set("Apt::Color", "1"); + // some different defaults + _config->CndSet("DPkgPM::Progress", "1"); + _config->CndSet("Apt::Color", "1"); + _config->CndSet("APT::Get::Upgrade-Allow-New", true); // Parse the command line and initialize the package library CommandLine CmdL(Args.data(), _config); -- cgit v1.2.3 From 33b813ce44c7bafeb2a36b66fd004f8d94a2cbe4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 5 Feb 2014 17:35:33 +0100 Subject: move isatty() check into InitOutput() --- cmdline/apt.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 6fe25e3f3..6ad470faa 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -156,8 +156,6 @@ int main(int argc, const char *argv[]) /*{{{*/ << std::endl << std::endl; } - if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) - _config->Set("quiet","1"); // See if the help should be shown if (_config->FindB("help") == true || -- cgit v1.2.3 From 52090faab4401ad6a2acb4d2c0c2cb53aa6b8f7f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 13 Feb 2014 14:47:34 +0100 Subject: trivial indent fix --- cmdline/apt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline/apt.cc') diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 6ad470faa..7ef9060aa 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -82,7 +82,7 @@ bool ShowHelp(CommandLine &CmdL) " remove - remove packages\n" "\n" " upgrade - upgrade the system by installing/upgrading packages\n" - "full-upgrade - upgrade the system by removing/installing/upgrading packages\n" + " full-upgrade - upgrade the system by removing/installing/upgrading packages\n" "\n" " edit-sources - edit the source information file\n" ); -- cgit v1.2.3