]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.7 1998/11/12 04:10:56 jgg Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
25 ##################################################################### */
27 // Include Files /*{{{*/
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/pkgcachegen.h>
34 #include <apt-pkg/algorithms.h>
35 #include <apt-pkg/acquire-item.h>
39 #include "acqprogress.h"
47 ofstream
devnull("/dev/null");
48 unsigned int ScreenWidth
= 80;
50 // ShowList - Show a list /*{{{*/
51 // ---------------------------------------------------------------------
52 /* This prints out a string of space seperated words with a title and
53 a two space indent line wraped to the current screen width. */
54 void ShowList(ostream
&out
,string Title
,string List
)
56 if (List
.empty() == true)
59 // Acount for the leading space
60 int ScreenWidth
= ::ScreenWidth
- 3;
63 string::size_type Start
= 0;
64 while (Start
< List
.size())
66 string::size_type End
;
67 if (Start
+ ScreenWidth
>= List
.size())
70 End
= List
.rfind(' ',Start
+ScreenWidth
);
72 if (End
== string::npos
|| End
< Start
)
73 End
= Start
+ ScreenWidth
;
74 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
79 // ShowBroken - Debugging aide /*{{{*/
80 // ---------------------------------------------------------------------
81 /* This prints out the names of all the packages that are broken along
82 with the name of each each broken dependency and a quite version
84 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
86 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
87 out
<< "dependencies:" << endl
;
88 pkgCache::PkgIterator I
= Cache
.PkgBegin();
89 for (;I
.end() != true; I
++)
91 if (Cache
[I
].InstBroken() == false)
94 // Print out each package and the failed dependencies
95 out
<<" " << I
.Name() << ":";
96 int Indent
= strlen(I
.Name()) + 3;
98 if (Cache
[I
].InstVerIter(Cache
).end() == true)
104 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
106 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
107 pkgDepCache::DepInstall
) != 0)
111 for (int J
= 0; J
!= Indent
; J
++)
115 if (D
->Type
== pkgCache::Dep::Conflicts
)
116 out
<< " Conflicts:" << D
.TargetPkg().Name();
118 out
<< " Depends:" << D
.TargetPkg().Name();
120 // Show a quick summary of the version requirements
121 if (D
.TargetVer() != 0)
122 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
125 /* Show a summary of the target package if possible. In the case
126 of virtual packages we show nothing */
128 pkgCache::PkgIterator Targ
= D
.TargetPkg();
129 if (Targ
->ProvidesList
== 0)
132 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
133 if (Ver
.end() == false)
134 out
<< Ver
.VerStr() << " is installed";
137 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
139 if (Targ
->ProvidesList
== 0)
140 out
<< "it is not installable";
142 out
<< "it is a virtual package";
145 out
<< "it is not installed";
154 // ShowNew - Show packages to newly install /*{{{*/
155 // ---------------------------------------------------------------------
157 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
159 /* Print out a list of packages that are going to be removed extra
160 to what the user asked */
161 pkgCache::PkgIterator I
= Dep
.PkgBegin();
163 for (;I
.end() != true; I
++)
164 if (Dep
[I
].NewInstall() == true)
165 List
+= string(I
.Name()) + " ";
166 ShowList(out
,"The following NEW packages will be installed:",List
);
169 // ShowDel - Show packages to delete /*{{{*/
170 // ---------------------------------------------------------------------
172 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
174 /* Print out a list of packages that are going to be removed extra
175 to what the user asked */
176 pkgCache::PkgIterator I
= Dep
.PkgBegin();
178 for (;I
.end() != true; I
++)
179 if (Dep
[I
].Delete() == true)
180 List
+= string(I
.Name()) + " ";
181 ShowList(out
,"The following packages will be REMOVED:",List
);
184 // ShowKept - Show kept packages /*{{{*/
185 // ---------------------------------------------------------------------
187 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
189 pkgCache::PkgIterator I
= Dep
.PkgBegin();
191 for (;I
.end() != true; I
++)
194 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
195 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
198 List
+= string(I
.Name()) + " ";
200 ShowList(out
,"The following packages have been kept back",List
);
203 // ShowUpgraded - Show upgraded packages /*{{{*/
204 // ---------------------------------------------------------------------
206 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
208 pkgCache::PkgIterator I
= Dep
.PkgBegin();
210 for (;I
.end() != true; I
++)
213 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
216 List
+= string(I
.Name()) + " ";
218 ShowList(out
,"The following packages will be upgraded",List
);
221 // ShowHold - Show held but changed packages /*{{{*/
222 // ---------------------------------------------------------------------
224 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
226 pkgCache::PkgIterator I
= Dep
.PkgBegin();
228 for (;I
.end() != true; I
++)
230 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
231 I
->SelectedState
== pkgCache::State::Hold
)
232 List
+= string(I
.Name()) + " ";
235 ShowList(out
,"The following held packages will be changed:",List
);
238 // ShowEssential - Show an essential package warning /*{{{*/
239 // ---------------------------------------------------------------------
240 /* This prints out a warning message that is not to be ignored. It shows
241 all essential packages and their dependents that are to be removed.
242 It is insanely risky to remove the dependents of an essential package! */
243 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
245 pkgCache::PkgIterator I
= Dep
.PkgBegin();
247 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
248 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
251 for (;I
.end() != true; I
++)
253 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
256 // The essential package is being removed
257 if (Dep
[I
].Delete() == true)
259 if (Added
[I
->ID
] == false)
262 List
+= string(I
.Name()) + " ";
266 if (I
->CurrentVer
== 0)
269 // Print out any essential package depenendents that are to be removed
270 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
272 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
273 if (Dep
[P
].Delete() == true)
275 if (Added
[P
->ID
] == true)
278 List
+= string(P
.Name()) + " ";
283 if (List
.empty() == false)
284 out
<< "WARNING: The following essential packages will be removed" << endl
;
285 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
290 // Stats - Show some statistics /*{{{*/
291 // ---------------------------------------------------------------------
293 void Stats(ostream
&out
,pkgDepCache
&Dep
)
295 unsigned long Upgrade
= 0;
296 unsigned long Install
= 0;
297 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
299 if (Dep
[I
].NewInstall() == true)
302 if (Dep
[I
].Upgrade() == true)
306 out
<< Upgrade
<< " packages upgraded, " <<
307 Install
<< " newly installed, " <<
308 Dep
.DelCount() << " to remove and " <<
309 Dep
.KeepCount() << " not upgraded." << endl
;
311 if (Dep
.BadCount() != 0)
312 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
316 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
317 // ---------------------------------------------------------------------
327 inline operator pkgDepCache
&() {return *Cache
;};
328 inline pkgDepCache
*operator ->() {return Cache
;};
329 inline pkgDepCache
&operator *() {return *Cache
;};
332 CacheFile() : File(0), Map(0), Cache(0) {};
341 // CacheFile::Open - Open the cache file /*{{{*/
342 // ---------------------------------------------------------------------
343 /* This routine generates the caches and then opens the dependency cache
344 and verifies that the system is OK. */
345 bool CacheFile::Open()
347 // Create a progress class
348 OpTextProgress
Progress(*_config
);
350 // Read the source list
352 if (List
.ReadMainList() == false)
353 return _error
->Error("The list of sources could not be read.");
355 // Build all of the caches
356 pkgMakeStatusCache(List
,Progress
);
357 if (_error
->PendingError() == true)
358 return _error
->Error("The package lists or status file could not be parsed or opened.");
362 // Open the cache file
363 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
364 if (_error
->PendingError() == true)
367 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
368 if (_error
->PendingError() == true)
371 Cache
= new pkgDepCache(*Map
,Progress
);
372 if (_error
->PendingError() == true)
377 // Check that the system is OK
378 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
379 return _error
->Error("Internal Error, non-zero counts");
381 // Apply corrections for half-installed packages
382 if (pkgApplyStatus(*Cache
) == false)
386 if (Cache
->BrokenCount() == 0)
389 // Attempt to fix broken things
390 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
392 c1out
<< "Correcting dependencies..." << flush
;
393 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
395 c1out
<< " failed." << endl
;
396 ShowBroken(c1out
,*this);
398 return _error
->Error("Unable to correct dependencies");
400 if (pkgMinimizeUpgrade(*Cache
) == false)
401 return _error
->Error("Unable to minimize the upgrade set");
403 c1out
<< " Done" << endl
;
407 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
408 ShowBroken(c1out
,*this);
410 return _error
->Error("Unmet dependencies. Try using -f.");
417 // InstallPackages - Actually download and install the packages /*{{{*/
418 // ---------------------------------------------------------------------
419 /* This displays the informative messages describing what is going to
420 happen and then calls the download routines */
421 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
)
423 ShowDel(c1out
,Cache
);
424 ShowNew(c1out
,Cache
);
426 ShowKept(c1out
,Cache
);
427 ShowHold(c1out
,Cache
);
428 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
429 ShowUpgraded(c1out
,Cache
);
430 ShowEssential(c1out
,Cache
);
434 if (Cache
.BrokenCount() != 0)
436 ShowBroken(c1out
,Cache
);
437 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
440 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
441 Cache
.BadCount() == 0)
448 // DoUpdate - Update the package lists /*{{{*/
449 // ---------------------------------------------------------------------
451 bool DoUpdate(CommandLine
&)
453 // Get the source list
455 if (List
.ReadMainList() == false)
458 // Create the download object
459 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
460 pkgAcquire
Fetcher(&Stat
);
462 // Populate it with the source selection
463 pkgSourceList::const_iterator I
;
464 for (I
= List
.begin(); I
!= List
.end(); I
++)
466 new pkgAcqIndex(&Fetcher
,I
);
467 if (_error
->PendingError() == true)
472 if (Fetcher
.Run() == false)
475 // Clean out any old list files
476 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
477 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
480 // Prepare the cache.
482 if (Cache
.Open() == false)
488 // DoUpgrade - Upgrade all packages /*{{{*/
489 // ---------------------------------------------------------------------
490 /* Upgrade all packages without installing new packages or erasing old
492 bool DoUpgrade(CommandLine
&CmdL
)
495 if (Cache
.Open() == false)
499 if (pkgAllUpgrade(Cache
) == false)
501 ShowBroken(c1out
,Cache
);
502 return _error
->Error("Internal Error, AllUpgrade broke stuff");
505 return InstallPackages(Cache
,true);
508 // DoInstall - Install packages from the command line /*{{{*/
509 // ---------------------------------------------------------------------
510 /* Install named packages */
511 bool DoInstall(CommandLine
&CmdL
)
514 if (Cache
.Open() == false)
517 int ExpectedInst
= 0;
519 pkgProblemResolver
Fix(Cache
);
521 bool DefRemove
= false;
522 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
525 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
527 // Duplicate the string
528 unsigned int Length
= strlen(*I
);
530 if (Length
>= sizeof(S
))
534 // See if we are removing the package
535 bool Remove
= DefRemove
;
536 if (S
[Length
- 1] == '-')
541 if (S
[Length
- 1] == '+')
547 // Locate the package
548 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
550 if (Pkg
.end() == true)
551 return _error
->Error("Couldn't find package %s",S
);
553 // Check if there is something new to install
554 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
555 if (State
.CandidateVer
== 0)
557 if (Pkg
->ProvidesList
!= 0)
559 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
561 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
562 for (; I
.end() == false; I
++)
564 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
566 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
567 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
569 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
570 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
571 " [Installed]"<< endl
;
573 c1out
<< "You should explicly select one to install." << endl
;
577 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
578 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
579 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
582 return _error
->Error("Package %s has no installation candidate",S
);
589 Cache
->MarkDelete(Pkg
);
594 Cache
->MarkInstall(Pkg
,false);
595 if (State
.Install() == false)
596 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
600 // Install it with autoinstalling enabled.
601 if (State
.InstBroken() == true)
602 Cache
->MarkInstall(Pkg
,true);
605 // Call the scored problem resolver
606 Fix
.InstallProtect();
607 if (Fix
.Resolve(true) == false)
610 // Now we check the state of the packages,
611 if (Cache
->BrokenCount() != 0)
613 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
614 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
615 c1out
<< "distribution that some required packages have not yet been created" << endl
;
616 c1out
<< "or been moved out of Incoming." << endl
;
620 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
621 c1out
<< "the package is simply not installable and a bug report against" << endl
;
622 c1out
<< "that package should be filed." << endl
;
625 c1out
<< "The following information may help to resolve the situation:" << endl
;
627 ShowBroken(c1out
,Cache
);
628 return _error
->Error("Sorry, broken packages");
631 /* Print out a list of packages that are going to be installed extra
632 to what the user asked */
633 if (Cache
->InstCount() != ExpectedInst
)
636 pkgCache::PkgIterator I
= Cache
->PkgBegin();
637 for (;I
.end() != true; I
++)
639 if ((*Cache
)[I
].Install() == false)
643 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
644 if (strcmp(*J
,I
.Name()) == 0)
648 List
+= string(I
.Name()) + " ";
651 ShowList(c1out
,"The following extra packages will be installed:",List
);
654 return InstallPackages(Cache
,false);
657 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
658 // ---------------------------------------------------------------------
659 /* Intelligent upgrader that will install and remove packages at will */
660 bool DoDistUpgrade(CommandLine
&CmdL
)
663 if (Cache
.Open() == false)
666 c0out
<< "Calculating Upgrade... " << flush
;
667 if (pkgDistUpgrade(*Cache
) == false)
669 c0out
<< "Failed" << endl
;
670 ShowBroken(c1out
,Cache
);
674 c0out
<< "Done" << endl
;
676 return InstallPackages(Cache
,true);
679 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
680 // ---------------------------------------------------------------------
681 /* Follows dselect's selections */
682 bool DoDSelectUpgrade(CommandLine
&CmdL
)
685 if (Cache
.Open() == false)
688 // Install everything with the install flag set
689 pkgCache::PkgIterator I
= Cache
->PkgBegin();
690 for (;I
.end() != true; I
++)
692 /* Install the package only if it is a new install, the autoupgrader
693 will deal with the rest */
694 if (I
->SelectedState
== pkgCache::State::Install
)
695 Cache
->MarkInstall(I
,false);
698 /* Now install their deps too, if we do this above then order of
699 the status file is significant for | groups */
700 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
702 /* Install the package only if it is a new install, the autoupgrader
703 will deal with the rest */
704 if (I
->SelectedState
== pkgCache::State::Install
)
705 Cache
->MarkInstall(I
);
708 // Apply erasures now, they override everything else.
709 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
712 if (I
->SelectedState
== pkgCache::State::DeInstall
||
713 I
->SelectedState
== pkgCache::State::Purge
)
714 Cache
->MarkDelete(I
);
717 /* Use updates smart upgrade to do the rest, it will automatically
719 if (pkgAllUpgrade(Cache
) == false)
721 ShowBroken(c1out
,Cache
);
722 return _error
->Error("Internal Error, AllUpgrade broke stuff");
725 return InstallPackages(Cache
,false);
728 // DoClean - Remove download archives /*{{{*/
729 // ---------------------------------------------------------------------
731 bool DoClean(CommandLine
&CmdL
)
736 // DoCheck - Perform the check operation /*{{{*/
737 // ---------------------------------------------------------------------
738 /* Opening automatically checks the system, this command is mostly used
740 bool DoCheck(CommandLine
&CmdL
)
749 // ShowHelp - Show a help screen /*{{{*/
750 // ---------------------------------------------------------------------
754 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
755 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
757 cout
<< "Usage: apt-get [options] command" << endl
;
758 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
760 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
761 cout
<< "installing packages. The most frequently used commands are update" << endl
;
762 cout
<< "and install." << endl
;
764 cout
<< "Commands:" << endl
;
765 cout
<< " update - Retrieve new lists of packages" << endl
;
766 cout
<< " upgrade - Perform an upgrade" << endl
;
767 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
768 cout
<< " remove - Remove packages" << endl
;
769 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
770 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
771 cout
<< " clean - Erase downloaded archive files" << endl
;
772 cout
<< " check - Verify that there are no broken dependencies" << endl
;
774 cout
<< "Options:" << endl
;
775 cout
<< " -h This help text." << endl
;
776 cout
<< " -q Loggable output - no progress indicator" << endl
;
777 cout
<< " -qq No output except for errors" << endl
;
778 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
779 cout
<< " -s No-act. Perform ordering simulation" << endl
;
780 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
781 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
782 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
783 cout
<< " -u Show a list of upgraded packages as well" << endl
;
784 cout
<< " -c=? Read this configuration file" << endl
;
785 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
786 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
787 cout
<< "pages for more information." << endl
;
791 // GetInitialize - Initialize things for apt-get /*{{{*/
792 // ---------------------------------------------------------------------
796 _config
->Set("quiet",0);
797 _config
->Set("help",false);
798 _config
->Set("APT::Get::Download-Only",false);
799 _config
->Set("APT::Get::Simulate",false);
800 _config
->Set("APT::Get::Assume-Yes",false);
801 _config
->Set("APT::Get::Fix-Broken",false);
805 int main(int argc
,const char *argv
[])
807 CommandLine::Args Args
[] = {
808 {'h',"help","help",0},
809 {'q',"quiet","quiet",CommandLine::IntLevel
},
810 {'q',"silent","quiet",CommandLine::IntLevel
},
811 {'d',"download-only","APT::Get::Download-Only",0},
812 {'s',"simulate","APT::Get::Simulate",0},
813 {'s',"just-print","APT::Get::Simulate",0},
814 {'s',"recon","APT::Get::Simulate",0},
815 {'s',"no-act","APT::Get::Simulate",0},
816 {'y',"yes","APT::Get::Assume-Yes",0},
817 {'y',"assume-yes","APT::Get::Assume-Yes",0},
818 {'f',"fix-broken","APT::Get::Fix-Broken",0},
819 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
820 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
821 {0,"ignore-hold","APT::Ingore-Hold",0},
822 {'c',"config-file",0,CommandLine::ConfigFile
},
823 {'o',"option",0,CommandLine::ArbItem
},
826 // Parse the command line and initialize the package library
827 CommandLine
CmdL(Args
,_config
);
828 if (pkgInitialize(*_config
) == false ||
829 CmdL
.Parse(argc
,argv
) == false)
831 _error
->DumpErrors();
835 // See if the help should be shown
836 if (_config
->FindB("help") == true ||
837 CmdL
.FileSize() == 0)
840 // Setup the output streams
841 c0out
.rdbuf(cout
.rdbuf());
842 c1out
.rdbuf(cout
.rdbuf());
843 c2out
.rdbuf(cout
.rdbuf());
844 if (_config
->FindI("quiet",0) > 0)
845 c0out
.rdbuf(devnull
.rdbuf());
846 if (_config
->FindI("quiet",0) > 1)
847 c1out
.rdbuf(devnull
.rdbuf());
849 // Match the operation
853 bool (*Handler
)(CommandLine
&);
854 } Map
[] = {{"update",&DoUpdate
},
855 {"upgrade",&DoUpgrade
},
856 {"install",&DoInstall
},
857 {"remove",&DoInstall
},
858 {"dist-upgrade",&DoDistUpgrade
},
859 {"dselect-upgrade",&DoDSelectUpgrade
},
864 for (I
= 0; Map
[I
].Match
!= 0; I
++)
866 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
868 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
869 _error
->Error("Handler silently failed");
875 if (Map
[I
].Match
== 0)
876 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
878 // Print any errors or warnings found during parsing
879 if (_error
->empty() == false)
881 bool Errors
= _error
->PendingError();
882 _error
->DumpErrors();
884 cout
<< "Returning 100." << endl
;
885 return Errors
== true?100:0;