aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/info_cmd.cpp
blob: b147b93c33fba8a039ccd5e1ed36a4832b3ae723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Epic Games, Inc. All Rights Reserved.

#include "info_cmd.h"

#include "zenserviceclient.h"

#include <zencore/fmtutils.h>
#include <zencore/logging.h>
#include <zencore/string.h>
#include <zenhttp/httpclient.h>

using namespace std::literals;

namespace zen {

InfoCommand::InfoCommand()
{
	m_Options.add_options()("h,help", "Print help");
	m_Options.add_option("", "u", "hosturl", kHostUrlHelp, cxxopts::value(m_HostName)->default_value(""), "<hosturl>");
}

InfoCommand::~InfoCommand()
{
}

void
InfoCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
	ZEN_UNUSED(GlobalOptions);

	if (!ParseOptions(argc, argv))
	{
		return;
	}

	ZenServiceClient Service({.HostSpec = m_HostName, .CommandName = Name});
	HttpClient&		 Http = Service.Http();

	if (HttpClient::Response Result = Http.Get("/admin/info", HttpClient::Accept(ZenContentType::kJSON)))
	{
		ZEN_CONSOLE("{}", Result.ToText());
	}
	else
	{
		Result.ThrowError(fmt::format("Failed getting info from {}", Service.HostSpec()));
	}
}

}  // namespace zen