summaryrefslogtreecommitdiff
path: root/sample_client/src/client.cpp
blob: c0125c24b681c49c3fbc658b5014ab499b95e154 (plain)
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
50
51
52
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string_view>

#include <hwd.h>

int main(int argc, char ** argv)
{
	if (2 > argc)
	{
		std::cerr << "missing operation" << std::endl;
		return 1;
	}
	std::string_view op {argv[1]};
	if (0 == op.compare("shutdown"))
	{
		hwd::stop_server();
	}
	else if (0 == op.compare("set"))
	{
		if (3 > argc)
		{
			std::cerr << "missing int argument to set" << std::endl;
			return 1;
		}
		std::string input {argv[2]};
		try
		{
			hwd::set_value(std::stoi(input));
		}
		catch (const std::invalid_argument &)
		{
			std::cerr << "bad argument to set" << std::endl;
			return 1;
		}
		catch (const std::out_of_range &)
		{
			std::cerr << "int argument is too large" << std::endl;
			return 1;
		}
	}
	else if (0 == op.compare("get"))
	{
		std::cout << hwd::get_value() << std::endl;
	}
	else
	{
		std::cerr << "invalid operation" << std::endl;
		return 1;
	}
}