dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / options-parsers.c
CommitLineData
1479465f
GJ
1/*
2 * dpkg - main program for package management
3 * options-helper.c - command-line options parser helpers
4 *
5 * Copyright © 2014 Guillem Jover <guillem@debian.org>
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <config.h>
22#include <compat.h>
23
24#include <dpkg/i18n.h>
25#include <dpkg/dpkg-db.h>
26#include <dpkg/error.h>
27#include <dpkg/pkg-spec.h>
28#include <dpkg/options.h>
29
30/**
31 * Parse an argument as a package name.
32 *
33 * The string is parsed as a singleton package name, and a #pkginfo instance
34 * is returned.
35 *
36 * @param cmd The command information structure currently parsed.
37 * @param name The package name argument
38 *
39 * @return A package instance.
40 */
41struct pkginfo *
42dpkg_options_parse_pkgname(const struct cmdinfo *cmd, const char *name)
43{
44 struct pkginfo *pkg;
45 struct dpkg_error err;
46
47 pkg = pkg_spec_parse_pkg(name, &err);
48 if (pkg == NULL)
49 badusage(_("--%s needs a valid package name but '%.250s' is not: %s"),
50 cmd->olong, name, err.str);
51
52 return pkg;
53}