juk3n/fluffypublic Fork
⑂ 6c77d0e
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

50 pass output interface to commands (#51)Unverified

* added output to add command

* added output to play and show commands

---------

Co-authored-by: Adrian Duraj <adrian.duraj@onmail.com>
Adrian Duraj committed 2026-09-28T07:51:39+02:00 Browse files
6c77d0e parent: bed72a2
modified app/include/commands/addCommand.hpp +7 -2
@@ -5,19 +5,23 @@
55
66 #include <command.hpp>
77 #include <gameRepository.hpp>
8+#include <output.hpp>
89
910 class AddCommand: public Command {
1011 private:
1112 std::weak_ptr<GameRepositoryInterface> gameRepository;
13+ std::weak_ptr<Output> output;
1214 std::string gameName;
1315 std::string path;
1416 public:
1517 AddCommand(
1618 std::weak_ptr<GameRepositoryInterface> gameRepository,
19+ std::weak_ptr<Output> output,
1720 std::string gameName,
1821 std::string path
1922 ) {
2023 this->gameRepository = gameRepository;
24+ this->output = output;
2125 this->gameName = gameName;
2226 this->path = path;
2327 }
@@ -37,8 +41,9 @@ class AddCommand: public Command {
3741 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {
3842 Game currentGame = gr->getGameByName(gameName);
3943 if (currentGame.getName().length() != 0) {
40- std::cout << "Game already exist" << std::endl;
41- // output->printMessage("Game already exist");
44+ if (auto out = output.lock()) {
45+ out->printMessage("Game already exist");
46+ }
4247 }
4348 else {
4449 gr->addGame(gameName, temp);
@@ -5,19 +5,23 @@
5 5
6 #include <command.hpp>6 #include <command.hpp>
7 #include <gameRepository.hpp>7 #include <gameRepository.hpp>
8+#include <output.hpp>
8 9
9 class AddCommand: public Command {10 class AddCommand: public Command {
10 private:11 private:
11 std::weak_ptr<GameRepositoryInterface> gameRepository;12 std::weak_ptr<GameRepositoryInterface> gameRepository;
13+ std::weak_ptr<Output> output;
12 std::string gameName;14 std::string gameName;
13 std::string path;15 std::string path;
14 public:16 public:
15 AddCommand(17 AddCommand(
16 std::weak_ptr<GameRepositoryInterface> gameRepository,18 std::weak_ptr<GameRepositoryInterface> gameRepository,
19+ std::weak_ptr<Output> output,
17 std::string gameName,20 std::string gameName,
18 std::string path21 std::string path
19 ) {22 ) {
20 this->gameRepository = gameRepository;23 this->gameRepository = gameRepository;
24+ this->output = output;
21 this->gameName = gameName;25 this->gameName = gameName;
22 this->path = path;26 this->path = path;
23 }27 }
@@ -37,8 +41,9 @@ class AddCommand: public Command {
37 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {41 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {
38 Game currentGame = gr->getGameByName(gameName);42 Game currentGame = gr->getGameByName(gameName);
39 if (currentGame.getName().length() != 0) {43 if (currentGame.getName().length() != 0) {
40- std::cout << "Game already exist" << std::endl;44+ if (auto out = output.lock()) {
41- // output->printMessage("Game already exist");45+ out->printMessage("Game already exist");
46+ }
42 }47 }
43 else {48 else {
44 gr->addGame(gameName, temp);49 gr->addGame(gameName, temp);
modified app/include/commands/playCommand.hpp +7 -1
@@ -4,18 +4,22 @@
44
55 #include <command.hpp>
66 #include <gameRepository.hpp>
7+#include <output.hpp>
78
89 class PlayCommand: public Command {
910 private:
1011 std::weak_ptr<GameRepositoryInterface> gameRepository;
12+ std::weak_ptr<Output> output;
1113 std::string gameName;
1214
1315 public:
1416 PlayCommand(
1517 std::weak_ptr<GameRepositoryInterface> gameRepository,
18+ std::weak_ptr<Output> output,
1619 std::string gameName
1720 ) {
1821 this->gameRepository = gameRepository;
22+ this->output = output;
1923 this->gameName = gameName;
2024 }
2125
@@ -23,7 +27,9 @@ class PlayCommand: public Command {
2327 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {
2428 std::string pathToRun = gr->getGameByName(gameName).getPath();
2529 if(pathToRun.empty()) {
26- std::cout << "no application found" << std::endl;
30+ if (auto out = output.lock()) {
31+ out->printMessage("No application found");
32+ }
2733 }
2834 else {
2935 system(pathToRun.c_str());
@@ -4,18 +4,22 @@
4 4
5 #include <command.hpp>5 #include <command.hpp>
6 #include <gameRepository.hpp>6 #include <gameRepository.hpp>
7+#include <output.hpp>
7 8
8 class PlayCommand: public Command {9 class PlayCommand: public Command {
9 private:10 private:
10 std::weak_ptr<GameRepositoryInterface> gameRepository;11 std::weak_ptr<GameRepositoryInterface> gameRepository;
12+ std::weak_ptr<Output> output;
11 std::string gameName;13 std::string gameName;
12 14
13 public:15 public:
14 PlayCommand(16 PlayCommand(
15 std::weak_ptr<GameRepositoryInterface> gameRepository,17 std::weak_ptr<GameRepositoryInterface> gameRepository,
18+ std::weak_ptr<Output> output,
16 std::string gameName19 std::string gameName
17 ) {20 ) {
18 this->gameRepository = gameRepository;21 this->gameRepository = gameRepository;
22+ this->output = output;
19 this->gameName = gameName;23 this->gameName = gameName;
20 }24 }
21 25
@@ -23,7 +27,9 @@ class PlayCommand: public Command {
23 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {27 if (std::shared_ptr<GameRepositoryInterface> gr = gameRepository.lock()) {
24 std::string pathToRun = gr->getGameByName(gameName).getPath();28 std::string pathToRun = gr->getGameByName(gameName).getPath();
25 if(pathToRun.empty()) {29 if(pathToRun.empty()) {
26- std::cout << "no application found" << std::endl;30+ if (auto out = output.lock()) {
31+ out->printMessage("No application found");
32+ }
27 }33 }
28 else {34 else {
29 system(pathToRun.c_str());35 system(pathToRun.c_str());
modified app/include/commands/showCommand.hpp +10 -3
@@ -4,20 +4,27 @@
44 #include <iostream>
55
66 #include <command.hpp>
7-
7+#include <output.hpp>
88
99 class ShowCommand: public Command {
1010 private:
1111 std::weak_ptr<GameRepositoryInterface> gameRepository;
12+ std::weak_ptr<Output> output;
1213 public:
13- ShowCommand(std::weak_ptr<GameRepositoryInterface> gameRepository) {
14+ ShowCommand(
15+ std::weak_ptr<GameRepositoryInterface> gameRepository,
16+ std::weak_ptr<Output> output
17+ ) {
1418 this->gameRepository = gameRepository;
19+ this->output = output;
1520 }
1621
1722 void execute() override {
1823 if (std::shared_ptr<GameRepositoryInterface> repository = gameRepository.lock()) {
1924 for (auto &game : repository->getGames()) {
20- std::cout << game.getName() << ": " << game.getPath() << std::endl;
25+ if (auto out = output.lock()) {
26+ out->printMessage(game.getName() + ": " + game.getPath());
27+ }
2128 }
2229 }
2330 }
@@ -4,20 +4,27 @@
4 #include <iostream>4 #include <iostream>
5 5
6 #include <command.hpp>6 #include <command.hpp>
7-7+#include <output.hpp>
8 8
9 class ShowCommand: public Command {9 class ShowCommand: public Command {
10 private:10 private:
11 std::weak_ptr<GameRepositoryInterface> gameRepository;11 std::weak_ptr<GameRepositoryInterface> gameRepository;
12+ std::weak_ptr<Output> output;
12 public:13 public:
13- ShowCommand(std::weak_ptr<GameRepositoryInterface> gameRepository) {14+ ShowCommand(
15+ std::weak_ptr<GameRepositoryInterface> gameRepository,
16+ std::weak_ptr<Output> output
17+ ) {
14 this->gameRepository = gameRepository;18 this->gameRepository = gameRepository;
19+ this->output = output;
15 }20 }
16 21
17 void execute() override {22 void execute() override {
18 if (std::shared_ptr<GameRepositoryInterface> repository = gameRepository.lock()) {23 if (std::shared_ptr<GameRepositoryInterface> repository = gameRepository.lock()) {
19 for (auto &game : repository->getGames()) {24 for (auto &game : repository->getGames()) {
20- std::cout << game.getName() << ": " << game.getPath() << std::endl;25+ if (auto out = output.lock()) {
26+ out->printMessage(game.getName() + ": " + game.getPath());
27+ }
21 }28 }
22 }29 }
23 }30 }
modified app/src/fluffyApplication.cpp +8 -3
@@ -17,7 +17,7 @@ auto FluffyApplication::handleCommand(
1717 const std::vector<std::string>& arguments
1818 ) -> void {
1919 if (command == "show") {
20- ShowCommand showCommand = ShowCommand(gameRepository);
20+ ShowCommand showCommand = ShowCommand(gameRepository, output);
2121 showCommand.execute();
2222 }
2323 else if (command == "rm") {
@@ -28,14 +28,19 @@ auto FluffyApplication::handleCommand(
2828 else if (command == "add") {
2929 std::string gameName = arguments[0];
3030 std::string gamePath = arguments[1];
31- AddCommand addCommand = AddCommand(gameRepository, gameName, gamePath);
31+ AddCommand addCommand = AddCommand(gameRepository, output, gameName, gamePath);
3232 addCommand.execute();
3333 }
3434 else if (command == "play") {
3535 std::string gameName{arguments[0]};
36- PlayCommand playCommand = PlayCommand(gameRepository, gameName);
36+ PlayCommand playCommand = PlayCommand(gameRepository, output, gameName);
3737 playCommand.execute();
3838 }
39+ else if (command == "only-games") {
40+ for (auto &game : gameRepository->getGames()) {
41+ output->printMessage(game.getName());
42+ }
43+ }
3944 else if (command == "--version") {
4045 output->printMessage("fluffy " + version);
4146 }
@@ -17,7 +17,7 @@ auto FluffyApplication::handleCommand(
17 const std::vector<std::string>& arguments17 const std::vector<std::string>& arguments
18 ) -> void {18 ) -> void {
19 if (command == "show") {19 if (command == "show") {
20- ShowCommand showCommand = ShowCommand(gameRepository);20+ ShowCommand showCommand = ShowCommand(gameRepository, output);
21 showCommand.execute();21 showCommand.execute();
22 }22 }
23 else if (command == "rm") {23 else if (command == "rm") {
@@ -28,14 +28,19 @@ auto FluffyApplication::handleCommand(
28 else if (command == "add") {28 else if (command == "add") {
29 std::string gameName = arguments[0];29 std::string gameName = arguments[0];
30 std::string gamePath = arguments[1];30 std::string gamePath = arguments[1];
31- AddCommand addCommand = AddCommand(gameRepository, gameName, gamePath);31+ AddCommand addCommand = AddCommand(gameRepository, output, gameName, gamePath);
32 addCommand.execute();32 addCommand.execute();
33 }33 }
34 else if (command == "play") {34 else if (command == "play") {
35 std::string gameName{arguments[0]};35 std::string gameName{arguments[0]};
36- PlayCommand playCommand = PlayCommand(gameRepository, gameName);36+ PlayCommand playCommand = PlayCommand(gameRepository, output, gameName);
37 playCommand.execute();37 playCommand.execute();
38 }38 }
39+ else if (command == "only-games") {
40+ for (auto &game : gameRepository->getGames()) {
41+ output->printMessage(game.getName());
42+ }
43+ }
39 else if (command == "--version") {44 else if (command == "--version") {
40 output->printMessage("fluffy " + version);45 output->printMessage("fluffy " + version);
41 }46 }