From b0614bb79c3604ab402b07aa994fe05f24e01c35 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 25 May 2024 22:44:02 +0200 Subject: [PATCH] [libcalamares] Add verbosity to CommandLine This is the data structure that stores a single command for execution by the shell. There is no back-end implementation for verbosity yet. --- src/libcalamares/utils/CommandList.cpp | 11 +++++++++++ src/libcalamares/utils/CommandList.h | 24 ++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/CommandList.cpp b/src/libcalamares/utils/CommandList.cpp index 0f5111eac..120cf5aa5 100644 --- a/src/libcalamares/utils/CommandList.cpp +++ b/src/libcalamares/utils/CommandList.cpp @@ -140,6 +140,11 @@ CommandLine::CommandLine( const QVariantMap& m ) m_command = command; m_timeout = timeout >= 0 ? std::chrono::seconds( timeout ) : CommandLine::TimeoutNotSet(); m_environment = Calamares::getStringList( m, "environment" ); + + if ( m.contains( "verbose" ) ) + { + m_verbose = Calamares::getBool( m, "verbose", false ); + } } else { @@ -289,4 +294,10 @@ CommandList::expand() const return expand( expander ); } +void +CommandList::updateVerbose( bool verbose ) +{ + std::for_each( begin(), end(), [ verbose ]( CommandLine& command ) { command.updateVerbose( verbose ); } ); +} + } // namespace Calamares diff --git a/src/libcalamares/utils/CommandList.h b/src/libcalamares/utils/CommandList.h index 331127c1e..b5b4fe7ad 100644 --- a/src/libcalamares/utils/CommandList.h +++ b/src/libcalamares/utils/CommandList.h @@ -18,6 +18,7 @@ #include #include +#include #include class KMacroExpanderBase; @@ -63,6 +64,7 @@ public: QString command() const { return m_command; } [[nodiscard]] QStringList environment() const { return m_environment; } std::chrono::seconds timeout() const { return m_timeout; } + bool isVerbose() const { return m_verbose.value_or( false ); } bool isValid() const { return !m_command.isEmpty(); } @@ -81,10 +83,20 @@ public: */ DLLEXPORT CommandLine expand() const; + /** @brief If nothing has set verbosity yet, update to @p verbose */ + void updateVerbose( bool verbose ) + { + if ( !m_verbose.has_value() ) + { + m_verbose = verbose; + } + } + private: QString m_command; QStringList m_environment; std::chrono::seconds m_timeout = TimeoutNotSet(); + std::optional< bool > m_verbose; }; /** @brief Abbreviation, used internally. */ @@ -103,6 +115,11 @@ class DLLEXPORT CommandList : protected CommandList_t public: /** @brief empty command-list with timeout to apply to entries. */ CommandList( bool doChroot = true, std::chrono::seconds timeout = std::chrono::seconds( 10 ) ); + /** @brief command-list constructed from script-entries in @p v + * + * The global settings @p doChroot and @p timeout can be overridden by + * the individual script-entries. + */ CommandList( const QVariant& v, bool doChroot = true, std::chrono::seconds timeout = std::chrono::seconds( 10 ) ); CommandList( int ) = delete; CommandList( const QVariant&, int ) = delete; @@ -126,14 +143,17 @@ public: * Each command-line in the list is expanded with the given @p expander. * @see CommandLine::expand() for details. */ - CommandList expand( KMacroExpanderBase& expander ) const; + DLLEXPORT CommandList expand( KMacroExpanderBase& expander ) const; /** @brief As above, with a default macro-expander. * * Each command-line in the list is expanded with that default macro-expander. * @see CommandLine::expand() for details. */ - CommandList expand() const; + DLLEXPORT CommandList expand() const; + + /** @brief Applies default-value @p verbose to each entry without an explicit setting. */ + DLLEXPORT void updateVerbose( bool verbose ); private: bool m_doChroot;