diff options
author | Aki <please@ignore.pl> | 2021-10-14 23:58:34 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-10-14 23:58:34 +0200 |
commit | 2c1a508c304ac8b3109b46ff524ec02e71829a3f (patch) | |
tree | 439afd66b07d5aeb1fc79e87e61766789a29126d /sample_client | |
parent | 61ae209e2b851d5efe6f1b2b1f6a8b75e52df417 (diff) | |
download | hwd-2c1a508c304ac8b3109b46ff524ec02e71829a3f.zip hwd-2c1a508c304ac8b3109b46ff524ec02e71829a3f.tar.gz hwd-2c1a508c304ac8b3109b46ff524ec02e71829a3f.tar.bz2 |
Extended client by adding sample state mutation to daemon and lib
Diffstat (limited to 'sample_client')
-rw-r--r-- | sample_client/src/client.cpp | 50 |
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; + } } |