]> git.saurik.com Git - apt.git/blame - cmdline/apt-helper.cc
use the pretty fullname of a pkg as download desciption
[apt.git] / cmdline / apt-helper.cc
CommitLineData
ed9665ae
MV
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* #####################################################################
4 apt-helper - cmdline helpers
5 ##################################################################### */
6 /*}}}*/
7// Include Files /*{{{*/
8#include <config.h>
9
453b82a3 10#include <apt-pkg/configuration.h>
ed9665ae
MV
11#include <apt-pkg/cmndline.h>
12#include <apt-pkg/error.h>
13#include <apt-pkg/init.h>
14#include <apt-pkg/strutl.h>
15#include <apt-pkg/pkgsystem.h>
16#include <apt-pkg/fileutl.h>
17#include <apt-pkg/acquire.h>
18#include <apt-pkg/acquire-item.h>
19
20#include <apt-private/acqprogress.h>
21#include <apt-private/private-output.h>
0d58c26a 22#include <apt-private/private-download.h>
ed9665ae
MV
23#include <apt-private/private-cmndline.h>
24
453b82a3
DK
25#include <iostream>
26#include <string>
27#include <vector>
ed9665ae
MV
28
29#include <apti18n.h>
30 /*}}}*/
ed9665ae 31
c3ccac92 32static bool DoDownloadFile(CommandLine &CmdL)
ed9665ae
MV
33{
34 if (CmdL.FileSize() <= 2)
35 return _error->Error(_("Must specify at least one pair url/filename"));
36
37
38 pkgAcquire Fetcher;
39 AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
40 Fetcher.Setup(&Stat);
41 std::string download_uri = CmdL.FileList[1];
42 std::string targetfile = CmdL.FileList[2];
43 new pkgAcqFile(&Fetcher, download_uri, "", 0, "desc", "short-desc",
44 "dest-dir-ignored", targetfile);
45 Fetcher.Run();
0d58c26a
DK
46 bool Failed = false;
47 if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == false ||
48 FileExists(targetfile) == false)
49 return _error->Error(_("Download Failed"));
ed9665ae
MV
50 return true;
51}
52
65512241 53static bool ShowHelp(CommandLine &)
ed9665ae 54{
0d58c26a 55 ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
ed9665ae
MV
56 COMMON_ARCH,__DATE__,__TIME__);
57
58 if (_config->FindB("version") == true)
59 return true;
60
0d58c26a 61 std::cout <<
ed9665ae
MV
62 _("Usage: apt-helper [options] command\n"
63 " apt-helper [options] download-file uri target-path\n"
64 "\n"
65 "apt-helper is a internal helper for apt\n"
66 "\n"
67 "Commands:\n"
68 " download-file - download the given uri to the target-path\n"
69 "\n"
70 " This APT helper has Super Meep Powers.\n");
71 return true;
72}
73
74
75int main(int argc,const char *argv[]) /*{{{*/
76{
77 CommandLine::Dispatch Cmds[] = {{"help",&ShowHelp},
78 {"download-file", &DoDownloadFile},
79 {0,0}};
80
81 std::vector<CommandLine::Args> Args = getCommandArgs(
82 "apt-download", CommandLine::GetCommand(Cmds, argc, argv));
83
84 // Set up gettext support
85 setlocale(LC_ALL,"");
86 textdomain(PACKAGE);
87
88 // Parse the command line and initialize the package library
89 CommandLine CmdL(Args.data(),_config);
90 if (pkgInitConfig(*_config) == false ||
91 CmdL.Parse(argc,argv) == false ||
92 pkgInitSystem(*_config,_system) == false)
93 {
94 if (_config->FindB("version") == true)
95 ShowHelp(CmdL);
96 _error->DumpErrors();
97 return 100;
98 }
99
100 // See if the help should be shown
101 if (_config->FindB("help") == true ||
102 _config->FindB("version") == true ||
103 CmdL.FileSize() == 0)
104 {
105 ShowHelp(CmdL);
106 return 0;
107 }
108
109 InitOutput();
110
111 // Match the operation
112 CmdL.DispatchArg(Cmds);
113
114 // Print any errors or warnings found during parsing
115 bool const Errors = _error->PendingError();
116 if (_config->FindI("quiet",0) > 0)
117 _error->DumpErrors();
118 else
119 _error->DumpErrors(GlobalError::DEBUG);
120 return Errors == true ? 100 : 0;
121}
122 /*}}}*/