]>
git.saurik.com Git - apt.git/blob - cmdline/apt-helper.cc
1 // -*- mode: cpp; mode: fold -*-
3 /* #####################################################################
4 apt-helper - cmdline helpers
5 ##################################################################### */
7 // Include Files /*{{{*/
10 #include <apt-pkg/cmndline.h>
11 #include <apt-pkg/error.h>
12 #include <apt-pkg/init.h>
13 #include <apt-pkg/strutl.h>
14 #include <apt-pkg/pkgsystem.h>
15 #include <apt-pkg/fileutl.h>
16 #include <apt-pkg/acquire.h>
17 #include <apt-pkg/acquire-item.h>
19 #include <apt-private/acqprogress.h>
20 #include <apt-private/private-output.h>
21 #include <apt-private/private-cmndline.h>
25 #include <sys/types.h>
36 bool DoDownloadFile(CommandLine
&CmdL
)
38 if (CmdL
.FileSize() <= 2)
39 return _error
->Error(_("Must specify at least one pair url/filename"));
43 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
45 std::string download_uri
= CmdL
.FileList
[1];
46 std::string targetfile
= CmdL
.FileList
[2];
47 new pkgAcqFile(&Fetcher
, download_uri
, "", 0, "desc", "short-desc",
48 "dest-dir-ignored", targetfile
);
50 if (!FileExists(targetfile
))
52 _error
->Error(_("Download Failed"));
58 bool ShowHelp(CommandLine
&CmdL
)
60 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
61 COMMON_ARCH
,__DATE__
,__TIME__
);
63 if (_config
->FindB("version") == true)
67 _("Usage: apt-helper [options] command\n"
68 " apt-helper [options] download-file uri target-path\n"
70 "apt-helper is a internal helper for apt\n"
73 " download-file - download the given uri to the target-path\n"
75 " This APT helper has Super Meep Powers.\n");
80 int main(int argc
,const char *argv
[]) /*{{{*/
82 CommandLine::Dispatch Cmds
[] = {{"help",&ShowHelp
},
83 {"download-file", &DoDownloadFile
},
86 std::vector
<CommandLine::Args
> Args
= getCommandArgs(
87 "apt-download", CommandLine::GetCommand(Cmds
, argc
, argv
));
89 // Set up gettext support
93 // Parse the command line and initialize the package library
94 CommandLine
CmdL(Args
.data(),_config
);
95 if (pkgInitConfig(*_config
) == false ||
96 CmdL
.Parse(argc
,argv
) == false ||
97 pkgInitSystem(*_config
,_system
) == false)
99 if (_config
->FindB("version") == true)
101 _error
->DumpErrors();
105 // See if the help should be shown
106 if (_config
->FindB("help") == true ||
107 _config
->FindB("version") == true ||
108 CmdL
.FileSize() == 0)
116 // Match the operation
117 CmdL
.DispatchArg(Cmds
);
119 // Print any errors or warnings found during parsing
120 bool const Errors
= _error
->PendingError();
121 if (_config
->FindI("quiet",0) > 0)
122 _error
->DumpErrors();
124 _error
->DumpErrors(GlobalError::DEBUG
);
125 return Errors
== true ? 100 : 0;