pkgman: Add --debug option for most commands
* Add CommonOptions class and add an instance to Command. It supports a debug level. * full-sync, install, search, uninstall, update: Add option --debug. This allows getting some debug output from the solver in cases where the result seems weird.
This commit is contained in:
parent
d228f29f6e
commit
dd15db954b
@ -26,6 +26,7 @@ compare_commands_by_name(const Command* a, const Command* b)
|
||||
Command::Command(const BString& name, const BString& shortUsage,
|
||||
const BString& longUsage, const BString& category)
|
||||
:
|
||||
fCommonOptions(),
|
||||
fName(name),
|
||||
fShortUsage(shortUsage),
|
||||
fLongUsage(longUsage),
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "CommonOptions.h"
|
||||
|
||||
|
||||
class Command {
|
||||
public:
|
||||
@ -33,6 +35,9 @@ public:
|
||||
|
||||
virtual int Execute(int argc, const char* const* argv) = 0;
|
||||
|
||||
protected:
|
||||
CommonOptions fCommonOptions;
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
BString fShortUsage;
|
||||
|
45
src/bin/pkgman/CommonOptions.cpp
Normal file
45
src/bin/pkgman/CommonOptions.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "CommonOptions.h"
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
CommonOptions::CommonOptions()
|
||||
:
|
||||
fDebugLevel(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CommonOptions::~CommonOptions()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CommonOptions::HandleOption(int option)
|
||||
{
|
||||
switch (option) {
|
||||
case OPTION_DEBUG:
|
||||
{
|
||||
char* end;
|
||||
fDebugLevel = strtol(optarg, &end, 0);
|
||||
if (end == optarg) {
|
||||
fprintf(stderr,
|
||||
"*** invalid argument for option --debug\n");
|
||||
exit(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
35
src/bin/pkgman/CommonOptions.h
Normal file
35
src/bin/pkgman/CommonOptions.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef COMMON_OPTIONS_H
|
||||
#define COMMON_OPTIONS_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
// common options
|
||||
enum {
|
||||
OPTION_DEBUG = 256,
|
||||
};
|
||||
|
||||
|
||||
class CommonOptions {
|
||||
public:
|
||||
CommonOptions();
|
||||
~CommonOptions();
|
||||
|
||||
int32 DebugLevel() const
|
||||
{ return fDebugLevel; }
|
||||
void SetDebugLevel(int level)
|
||||
{ fDebugLevel = level; }
|
||||
|
||||
bool HandleOption(int option);
|
||||
|
||||
private:
|
||||
int32 fDebugLevel;
|
||||
};
|
||||
|
||||
|
||||
#endif // COMMON_OPTIONS_H
|
@ -14,6 +14,7 @@ BinCommand pkgman :
|
||||
command_resolve_dependencies.cpp
|
||||
command_search.cpp
|
||||
command_uninstall.cpp
|
||||
CommonOptions.cpp
|
||||
DecisionProvider.cpp
|
||||
JobStateListener.cpp
|
||||
PackageManager.cpp
|
||||
|
@ -34,6 +34,9 @@ static const char* const kLongUsage =
|
||||
"downgrades or removes packages, if necessary.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --debug <level>\n"
|
||||
" Print debug output. <level> should be between 0 (no debug output,\n"
|
||||
" the default) and 10 (most debug output).\n"
|
||||
" -H, --home\n"
|
||||
" Synchronizes the packages in the user's home directory. Default is\n"
|
||||
" to synchronize the packages in the system directory.\n"
|
||||
@ -56,6 +59,7 @@ FullSyncCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "debug", required_argument, 0, OPTION_DEBUG },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "home", no_argument, 0, 'H' },
|
||||
{ 0, 0, 0, 0 }
|
||||
@ -66,6 +70,9 @@ FullSyncCommand::Execute(int argc, const char* const* argv)
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
if (fCommonOptions.HandleOption(c))
|
||||
continue;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
PrintUsageAndExit(false);
|
||||
@ -91,6 +98,7 @@ FullSyncCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
// perform the sync
|
||||
PackageManager packageManager(location, interactive);
|
||||
packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
|
||||
packageManager.FullSync();
|
||||
|
||||
return 0;
|
||||
|
@ -34,6 +34,9 @@ static const char* const kLongUsage =
|
||||
"path to a local package file. In the latter case the file is copied.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --debug <level>\n"
|
||||
" Print debug output. <level> should be between 0 (no debug output,\n"
|
||||
" the default) and 10 (most debug output).\n"
|
||||
" -H, --home\n"
|
||||
" Install the packages in the user's home directory. Default is to\n"
|
||||
" install in the system directory.\n"
|
||||
@ -56,6 +59,7 @@ InstallCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "debug", required_argument, 0, OPTION_DEBUG },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "home", no_argument, 0, 'H' },
|
||||
{ 0, 0, 0, 0 }
|
||||
@ -66,6 +70,9 @@ InstallCommand::Execute(int argc, const char* const* argv)
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
if (fCommonOptions.HandleOption(c))
|
||||
continue;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
PrintUsageAndExit(false);
|
||||
@ -94,6 +101,7 @@ InstallCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
// perform the installation
|
||||
PackageManager packageManager(location, interactive);
|
||||
packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
|
||||
packageManager.Install(packages, packageCount);
|
||||
|
||||
return 0;
|
||||
|
@ -43,6 +43,9 @@ static const char* const kLongUsage =
|
||||
"Options:\n"
|
||||
" -a, --all\n"
|
||||
" List all packages. Specified instead of <search-string>.\n"
|
||||
" --debug <level>\n"
|
||||
" Print debug output. <level> should be between 0 (no debug output,\n"
|
||||
" the default) and 10 (most debug output).\n"
|
||||
" -D, --details\n"
|
||||
" Print more details. Matches in each installation location and each\n"
|
||||
" repository will be listed individually with their version.\n"
|
||||
@ -133,6 +136,7 @@ SearchCommand::Execute(int argc, const char* const* argv)
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "all", no_argument, 0, 'a' },
|
||||
{ "debug", required_argument, 0, OPTION_DEBUG },
|
||||
{ "details", no_argument, 0, 'D' },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "installed-only", no_argument, 0, 'i' },
|
||||
@ -145,6 +149,9 @@ SearchCommand::Execute(int argc, const char* const* argv)
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
if (fCommonOptions.HandleOption(c))
|
||||
continue;
|
||||
|
||||
switch (c) {
|
||||
case 'a':
|
||||
listAll = true;
|
||||
@ -183,6 +190,7 @@ SearchCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
// create the solver
|
||||
PackageManager packageManager(B_PACKAGE_INSTALLATION_LOCATION_HOME);
|
||||
packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
|
||||
packageManager.Init(
|
||||
(!uninstalledOnly ? PackageManager::B_ADD_INSTALLED_REPOSITORIES : 0)
|
||||
| (!installedOnly ? PackageManager::B_ADD_REMOTE_REPOSITORIES : 0));
|
||||
|
@ -32,6 +32,9 @@ static const char* const kLongUsage =
|
||||
"Uninstalls the specified packages.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --debug <level>\n"
|
||||
" Print debug output. <level> should be between 0 (no debug output,\n"
|
||||
" the default) and 10 (most debug output).\n"
|
||||
" -H, --home\n"
|
||||
" Uninstall the packages from the user's home directory. Default is to\n"
|
||||
" uninstall from the system directory.\n"
|
||||
@ -54,6 +57,7 @@ UninstallCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "debug", required_argument, 0, OPTION_DEBUG },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "home", no_argument, 0, 'H' },
|
||||
{ 0, 0, 0, 0 }
|
||||
@ -64,6 +68,9 @@ UninstallCommand::Execute(int argc, const char* const* argv)
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
if (fCommonOptions.HandleOption(c))
|
||||
continue;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
PrintUsageAndExit(false);
|
||||
@ -92,6 +99,7 @@ UninstallCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
// perform the installation
|
||||
PackageManager packageManager(location, interactive);
|
||||
packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
|
||||
packageManager.Uninstall(packages, packageCount);
|
||||
|
||||
return 0;
|
||||
|
@ -36,6 +36,9 @@ static const char* const kLongUsage =
|
||||
"package file. In the latter case the file is copied.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --debug <level>\n"
|
||||
" Print debug output. <level> should be between 0 (no debug output,\n"
|
||||
" the default) and 10 (most debug output).\n"
|
||||
" -H, --home\n"
|
||||
" Update the packages in the user's home directory. Default is to\n"
|
||||
" update in the system directory.\n"
|
||||
@ -58,6 +61,7 @@ UpdateCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "debug", required_argument, 0, OPTION_DEBUG },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "home", no_argument, 0, 'H' },
|
||||
{ 0, 0, 0, 0 }
|
||||
@ -68,6 +72,9 @@ UpdateCommand::Execute(int argc, const char* const* argv)
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
if (fCommonOptions.HandleOption(c))
|
||||
continue;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
PrintUsageAndExit(false);
|
||||
@ -93,6 +100,7 @@ UpdateCommand::Execute(int argc, const char* const* argv)
|
||||
|
||||
// perform the update
|
||||
PackageManager packageManager(location, interactive);
|
||||
packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
|
||||
packageManager.Update(packages, packageCount);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user