-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Coal
committed
Feb 19, 2022
1 parent
3563463
commit 1b5b701
Showing
10 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#pragma once | ||
#include <iostream> | ||
#include <string> | ||
#include <map> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <string> | ||
#include "lpm/types.h" | ||
#include "lpm/macros.h" | ||
#include "command.h" | ||
#include "errorhandling.h" | ||
|
||
bool Command::execute(Type command_type, args_t& args) { | ||
try { | ||
switch (command_type) { | ||
case Type::INSTALL: | ||
Handlers::install(args); | ||
break; | ||
default: | ||
LPM_PRINT_ERROR("Unsupported command: " << command_type); | ||
return false; | ||
} | ||
} catch (...) { | ||
LPM_PRINT_ERROR("Failed to execute command: " << command_type); | ||
LPM_PRINT_DEBUG("Exception: " << ErrorHandling::what()); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include <string> | ||
#include "lpm/types.h" | ||
#include "lpm/macros.h" | ||
|
||
namespace Command { | ||
enum Type { | ||
HELP, | ||
INIT, | ||
INSTALL, | ||
ADD, | ||
RUN, | ||
REMOVE, | ||
UPDATE, | ||
LIST, | ||
SEARCH, | ||
REPOSITORY, | ||
AUDIT, | ||
SHOW, | ||
PURGE | ||
}; | ||
|
||
// Pass a command to its respective handler. | ||
bool execute(Command::Type command_type, args_t& args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include <string> | ||
#include <exception> | ||
|
||
namespace ErrorHandling { | ||
std::string what(const std::exception_ptr &eptr = std::current_exception()) { | ||
if (!eptr) { throw std::bad_exception(); } | ||
|
||
try { std::rethrow_exception(eptr); } | ||
catch (const std::exception &e) { return e.what() ; } | ||
catch (const std::string &e) { return e ; } | ||
catch (const char *e) { return e ; } | ||
catch (...) { return "Unknown error"; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Its convenient to have all commands in separate compilation units | ||
// to improve compilation speed. | ||
|
||
#pragma once | ||
|
||
#include "install.h" | ||
|
||
namespace Handlers {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "install.h" | ||
#include "lpm/macros.h" | ||
|
||
void Handlers::install(args_t& args) { | ||
LPM_PRINT("Handlers::install()"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
#include "lpm/types.h" | ||
|
||
namespace Handlers { | ||
// Handler for lpm install. | ||
void install(args_t& args); | ||
} |
Submodule library
updated
6 files
+3 −0 | .gitmodules | |
+1 −1 | CMakeLists.txt | |
+2 −2 | README.md | |
+1 −0 | dependencies/toml11 | |
+24 −4 | lpm/macros.h | |
+40 −0 | lpm/packages.cpp |