Skip to content

Commit

Permalink
context: Add print_error and print_output
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode authored and jan-kolarik committed Sep 2, 2024
1 parent b551420 commit 80064b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions dnf5-plugins/automatic_plugin/automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void AutomaticCommand::pre_configure() {
}

context.set_output_stream(output_stream);
context.set_error_stream(output_stream);
}

void AutomaticCommand::configure() {
Expand Down
17 changes: 13 additions & 4 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ class Context::Impl {
void set_load_available_repos(LoadAvailableRepos which) { load_available_repos = which; }
LoadAvailableRepos get_load_available_repos() const noexcept { return load_available_repos; }

void print_output(std::string_view msg) const;
void print_info(std::string_view msg) const;
void print_error(std::string_view msg) const;

void set_output_stream(std::ostream & new_output_stream) {
err_stream = new_output_stream;
out_stream = new_output_stream;
}
void set_output_stream(std::ostream & new_output_stream) { out_stream = new_output_stream; }
void set_error_stream(std::ostream & new_error_stream) { err_stream = new_error_stream; }

void set_transaction_store_path(std::filesystem::path path) { transaction_store_path = path; }
const std::filesystem::path & get_transaction_store_path() const { return transaction_store_path; }
Expand Down Expand Up @@ -511,11 +511,17 @@ libdnf5::Goal * Context::Impl::get_goal(bool new_if_not_exist) {
return goal.get();
}

void Context::Impl::print_output(std::string_view msg) const {
out_stream.get() << msg << std::endl;
}
void Context::Impl::print_info(std::string_view msg) const {
if (!quiet) {
err_stream.get() << msg << std::endl;
}
}
void Context::Impl::print_error(std::string_view msg) const {
err_stream.get() << msg << std::endl;
}


Context::Context(std::vector<std::unique_ptr<libdnf5::Logger>> && loggers)
Expand Down Expand Up @@ -655,6 +661,9 @@ void Context::print_info(std::string_view msg) const {
void Context::set_output_stream(std::ostream & new_output_stream) {
p_impl->set_output_stream(new_output_stream);
}
void Context::set_error_stream(std::ostream & new_error_stream) {
p_impl->set_error_stream(new_error_stream);
}

void Context::set_transaction_store_path(std::filesystem::path path) {
p_impl->set_transaction_store_path(path);
Expand Down
10 changes: 9 additions & 1 deletion dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,19 @@ class DNF_API Context : public libdnf5::cli::session::Session {
void set_load_available_repos(LoadAvailableRepos which);
LoadAvailableRepos get_load_available_repos() const noexcept;

/// If quiet mode is not active, it will print `msg` to standard output.
/// Print `msg` to the output stream, which by default is stdout.
void print_output(std::string_view msg) const;

/// If quiet mode is not active, it will print `msg` to the error stream, which by default is stderr.
void print_info(std::string_view msg) const;

/// Print `msg` to the error stream, which by default is stderr.
void print_error(std::string_view msg) const;

void set_output_stream(std::ostream & new_output_stream);

void set_error_stream(std::ostream & new_error_stream);

// When set current transaction is not executed but rather stored to the specified path.
void set_transaction_store_path(std::filesystem::path path);
const std::filesystem::path & get_transaction_store_path() const;
Expand Down

0 comments on commit 80064b3

Please sign in to comment.