summaryrefslogtreecommitdiff
path: root/sample_client/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sample_client/src/client.cpp')
-rw-r--r--sample_client/src/client.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/sample_client/src/client.cpp b/sample_client/src/client.cpp
index 87421ca..c0125c2 100644
--- a/sample_client/src/client.cpp
+++ b/sample_client/src/client.cpp
@@ -1,6 +1,52 @@
+#include <cstdlib>
+#include <iostream>
+#include <stdexcept>
+#include <string_view>
+
#include <hwd.h>
-int main(int, char **)
+int main(int argc, char ** argv)
{
- hwd::stop_server();
+ 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;
+ }
}