# HG changeset patch # User František Kučera # Date 1617292486 -7200 # Node ID dbf093b8b9ac3231bc01c17798eb40a04c97bb87 # Parent e5baa07d6e6066e0db3b9d60a8b33afd6b2d7248 add boolean options: --debug and --dry-run diff -r e5baa07d6e60 -r dbf093b8b9ac bash-completion.sh --- a/bash-completion.sh Tue Mar 30 20:26:08 2021 +0200 +++ b/bash-completion.sh Thu Apr 01 17:54:46 2021 +0200 @@ -22,15 +22,17 @@ w2=${COMP_WORDS[COMP_CWORD-2]} w3=${COMP_WORDS[COMP_CWORD-3]} - WRITE_HEADER=( + BOOLEAN_VALUES=( "true" "false" ) - if [[ "$w1" == "--TODO" ]]; then COMPREPLY=($(compgen -W "${WRITE_HEADER[*]}" -- "$w0")) + if [[ "$w1" == "--debug" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + elif [[ "$w1" == "--dry-run" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) else OPTIONS=( - "--TODO" + "--debug" + "--dry-run" ) COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) fi diff -r e5baa07d6e60 -r dbf093b8b9ac src/CLIParser.h --- a/src/CLIParser.h Tue Mar 30 20:26:08 2021 +0200 +++ b/src/CLIParser.h Thu Apr 01 17:54:46 2021 +0200 @@ -48,7 +48,8 @@ public: - static const relpipe::reader::string_t OPTION_WRITE_HEADER; + static const relpipe::reader::string_t OPTION_DEBUG; + static const relpipe::reader::string_t OPTION_DRY_RUN; Configuration parse(const std::vector& arguments) { Configuration c; @@ -56,8 +57,10 @@ for (int i = 0; i < arguments.size();) { relpipe::reader::string_t option = readNext(arguments, i); - if (option == OPTION_WRITE_HEADER) { - c.writeHeader = parseBoolean(readNext(arguments, i)); + if (option == OPTION_DEBUG) { + c.debug = parseBoolean(readNext(arguments, i)); + } else if (option == OPTION_DRY_RUN) { + c.dryRun = parseBoolean(readNext(arguments, i)); } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } @@ -68,7 +71,8 @@ } }; -const relpipe::reader::string_t CLIParser::OPTION_WRITE_HEADER = L"--write-header"; +const relpipe::reader::string_t CLIParser::OPTION_DEBUG = L"--debug"; +const relpipe::reader::string_t CLIParser::OPTION_DRY_RUN = L"--dry-run"; } } diff -r e5baa07d6e60 -r dbf093b8b9ac src/Configuration.h --- a/src/Configuration.h Tue Mar 30 20:26:08 2021 +0200 +++ b/src/Configuration.h Thu Apr 01 17:54:46 2021 +0200 @@ -19,7 +19,7 @@ #include #include -#include +#include namespace relpipe { @@ -28,7 +28,8 @@ class Configuration { public: - relpipe::reader::boolean_t writeHeader = true; + relpipe::common::type::Boolean debug = false; + relpipe::common::type::Boolean dryRun = false; virtual ~Configuration() { } diff -r e5baa07d6e60 -r dbf093b8b9ac src/X11Handler.h --- a/src/X11Handler.h Tue Mar 30 20:26:08 2021 +0200 +++ b/src/X11Handler.h Thu Apr 01 17:54:46 2021 +0200 @@ -130,14 +130,20 @@ } attributeIndex++; + + bool debug = configuration.debug; + bool run = !configuration.dryRun; if (attributeIndex % attributes.size() == 0) { if (currentEvent.type == Event::Type::KEY) { - XTestFakeKeyEvent(display.display, currentEvent.key, currentEvent.state == Event::State::PRESSED, currentEvent.delay); + if (debug) std::wcerr << L"KEY: x = " << currentEvent.x << L" y = " << currentEvent.y << L" key = " << currentEvent.key << L" state = " << (currentEvent.state == Event::State::PRESSED ? L"pressed" : L"released") << std::endl; + if (run) XTestFakeKeyEvent(display.display, currentEvent.key, currentEvent.state == Event::State::PRESSED, currentEvent.delay); } else if (currentEvent.type == Event::Type::BUTTON) { - XTestFakeButtonEvent(display.display, currentEvent.button, currentEvent.state == Event::State::PRESSED, currentEvent.delay); + if (debug) std::wcerr << L"BUTTON: x = " << currentEvent.x << L" y = " << currentEvent.y << L" button = " << currentEvent.button << L" state = " << (currentEvent.state == Event::State::PRESSED ? L"pressed" : L"released") << std::endl; + if (run) XTestFakeButtonEvent(display.display, currentEvent.button, currentEvent.state == Event::State::PRESSED, currentEvent.delay); } else if (currentEvent.type == Event::Type::MOTION) { - XTestFakeMotionEvent(display.display, currentEvent.screen, currentEvent.x, currentEvent.y, currentEvent.delay); + if (debug) std::wcerr << L"MOTION: x = " << currentEvent.x << L" y = " << currentEvent.y << std::endl; + if (run) XTestFakeMotionEvent(display.display, currentEvent.screen, currentEvent.x, currentEvent.y, currentEvent.delay); } else { std::wcerr << L"Unsupported event" << std::endl; }