1bb7d146cSRene Gollent/*
2bb7d146cSRene Gollent * Copyright 2012, Rene Gollent, rene@gollent.com.
3bb7d146cSRene Gollent * Distributed under the terms of the MIT License.
4bb7d146cSRene Gollent */
5bb7d146cSRene Gollent
6bb7d146cSRene Gollent
7bb7d146cSRene Gollent#include "CliDebugReportCommand.h"
8bb7d146cSRene Gollent
9bb7d146cSRene Gollent#include <Entry.h>
10bb7d146cSRene Gollent#include <FindDirectory.h>
11bb7d146cSRene Gollent#include <Path.h>
12bb7d146cSRene Gollent#include <String.h>
13bb7d146cSRene Gollent
14bb7d146cSRene Gollent#include "CliContext.h"
15bb7d146cSRene Gollent#include "UiUtils.h"
16bb7d146cSRene Gollent#include "UserInterface.h"
17bb7d146cSRene Gollent
18bb7d146cSRene Gollent
19bb7d146cSRene GollentCliDebugReportCommand::CliDebugReportCommand()
20bb7d146cSRene Gollent	:
21bb7d146cSRene Gollent	CliCommand("save debug report",
22bb7d146cSRene Gollent		"%s\n"
23bb7d146cSRene Gollent		"Saves a debug information report for the current team.")
24bb7d146cSRene Gollent{
25bb7d146cSRene Gollent}
26bb7d146cSRene Gollent
27bb7d146cSRene Gollent
28bb7d146cSRene Gollentvoid
29bb7d146cSRene GollentCliDebugReportCommand::Execute(int argc, const char* const* argv, CliContext& context)
30bb7d146cSRene Gollent{
31bb7d146cSRene Gollent	BPath path;
32137bb1e2SRene Gollent	if (argc > 1) {
33137bb1e2SRene Gollent		path.SetTo(argv[1]);
34137bb1e2SRene Gollent		if (path.InitCheck() != B_OK) {
35137bb1e2SRene Gollent			printf("Invalid report path %s given.\n", argv[1]);
36137bb1e2SRene Gollent			return;
37137bb1e2SRene Gollent		}
38137bb1e2SRene Gollent	} else {
39137bb1e2SRene Gollent		char buffer[B_FILE_NAME_LENGTH];
40137bb1e2SRene Gollent		UiUtils::ReportNameForTeam(context.GetTeam(), buffer, sizeof(buffer));
41137bb1e2SRene Gollent		find_directory(B_DESKTOP_DIRECTORY, &path);
42137bb1e2SRene Gollent		path.Append(buffer);
43137bb1e2SRene Gollent	}
44137bb1e2SRene Gollent
45bb7d146cSRene Gollent	entry_ref ref;
46137bb1e2SRene Gollent	if (get_ref_for_path(path.Path(), &ref) == B_OK) {
47137bb1e2SRene Gollent		printf("Saving debug information report to %s...\n", path.Path());
48bb7d146cSRene Gollent		context.GetUserInterfaceListener()->DebugReportRequested(&ref);
49137bb1e2SRene Gollent	}
50bb7d146cSRene Gollent}
51