1 /** 2 * \file textcliformatter.h 3 * CLI formatter for standard text input and output. 4 * 5 * \b Project: Kid3 6 * \author Urs Fleisch 7 * \date 28 Jul 2019 8 * 9 * Copyright (C) 2019 Urs Fleisch 10 * 11 * This file is part of Kid3. 12 * 13 * Kid3 is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * Kid3 is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program. If not, see <http://www.gnu.org/licenses/>. 25 */ 26 27 #pragma once 28 29 #include "abstractcliformatter.h" 30 31 /** 32 * CLI formatter for standard text input and output. 33 */ 34 class TextCliFormatter : public AbstractCliFormatter { 35 Q_OBJECT 36 public: 37 /** 38 * Constructor. 39 * @param io I/O handler 40 */ 41 explicit TextCliFormatter(AbstractCliIO* io); 42 43 /** 44 * Destructor. 45 */ 46 virtual ~TextCliFormatter() override; 47 48 /** 49 * Clear parser state. 50 */ 51 virtual void clear() override; 52 53 /** 54 * Get command and parameters from input line. 55 * @param line input line 56 * @return list of command and arguments, empty if not found or incomplete. 57 */ 58 virtual QStringList parseArguments(const QString& line) override; 59 60 /** 61 * Get error which occurred in previous method call. 62 * @return error message, null if no error. 63 */ 64 virtual QString getErrorMessage() const override; 65 66 /** 67 * Check if format was recognized and parsed, but input is will be continued 68 * in subsequent lines. 69 * @return true if input is incomplete. 70 */ 71 virtual bool isIncomplete() const override; 72 73 /** 74 * Check if format was recognized and parsed. 75 * @return true if format was recognized. 76 */ 77 virtual bool isFormatRecognized() const override; 78 79 /** 80 * Write error message. 81 * @param errorCode error code 82 */ 83 virtual void writeError(CliError errorCode) override; 84 85 /** 86 * Write error message. 87 * @param msg error message 88 */ 89 virtual void writeError(const QString& msg) override; 90 91 /** 92 * Write error message. 93 * @param msg error message 94 * @param errorCode error code 95 */ 96 virtual void writeError(const QString& msg, CliError errorCode) override; 97 98 /** 99 * Write result message. 100 * @param str result as string 101 */ 102 virtual void writeResult(const QString& str) override; 103 104 /** 105 * Write result message. 106 * @param strs result as string list 107 */ 108 virtual void writeResult(const QStringList& strs) override; 109 110 /** 111 * Write result message. 112 * @param map result as map 113 */ 114 virtual void writeResult(const QVariantMap& map) override; 115 116 /** 117 * Write result message. 118 * @param result result as boolean 119 */ 120 virtual void writeResult(bool result) override; 121 122 /** 123 * Called when a command is finished. 124 */ 125 virtual void finishWriting() override; 126 127 private: 128 QString m_errorMessage; 129 QStringList m_args; 130 }; 131