-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔧 Added class for parsing command line parameters #941
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you!
if (args.LastError() != SO_SUCCESS) | ||
{ | ||
LOG(LOG_ERROR) << GetLastErrorText(args.LastError()) << " " << args.OptionText(); | ||
success = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it return false immediately?
I think it is better not to write to the setting with cmd line parameters. |
It doesn't get written to the json file |
You have right. |
|
||
// ================================== | ||
// Command line options | ||
// ================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extend the comment, that these settings are special ones and will not be preserved in between runs?
src/Game.cxx
Outdated
|
||
if (SDL_VideoInit(videoDriver) != 0) | ||
if (SDL_VideoInit(vd) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vd is bad name for variable
// ================================== | ||
|
||
/// Sets a different video driver | ||
std::string videoDriver = "Default"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really need save it all game? it just option on start, dont pay for unused variables
{ | ||
videoDriver = argv[videoOpt + 1]; | ||
} | ||
ParseCli cli; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parser cli?
src/main.cxx
Outdated
return EXIT_FAILURE; | ||
|
||
if (!skipMenu) | ||
bool quitGame = Settings::instance().quitGame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again temporary variable moved to persistant class? did we really need hold this all game?
if (!skipMenu) | ||
bool quitGame = Settings::instance().quitGame; | ||
|
||
if (!Settings::instance().skipMenu) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again temp var in persisten place
#include "SimpleOpt.h" | ||
#include <string> | ||
|
||
class ParseCli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParserCli?
// option identifiers | ||
enum | ||
{ | ||
OPT_HELP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better user bane enum opt_id {
e_opt_help
....
}
OPT_HELP looks like macros
src/Game.cxx
Outdated
{ | ||
if (SDL_Init(0) != 0) | ||
{ | ||
LOG(LOG_ERROR) << "Failed to Init SDL"; | ||
LOG(LOG_ERROR) << "SDL Error: " << SDL_GetError(); | ||
return false; | ||
} | ||
const char *vd = nullptr; | ||
if(Settings::instance().videoDriver != "Default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after if
|
||
/** @brief begins the game | ||
* starts running the game | ||
* @param SkipMenu if the main menu should be skipped or not | ||
*/ | ||
virtual void run(bool SkipMenu = false); | ||
virtual void run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it virtual, we planed have same modes in game?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that was changed in this PR/commits.
} | ||
ParseCli cli; | ||
if (!cli.ProcessCommandLine(argc,argv)) | ||
return EXIT_FAILURE; | ||
|
||
LOG(LOG_DEBUG) << "Launching Cytopia"; | ||
|
||
Cytopia::Game game; | ||
|
||
LOG(LOG_DEBUG) << "Initializing Cytopia"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much words? debug () << text, debug( "%s", text )?
Kudos, SonarCloud Quality Gate passed! |
@AnotherFoxGuy pls fix conflicts and nits |
Kudos, SonarCloud Quality Gate passed! |
bool ProcessCommandLine(int argc, char **argv); | ||
|
||
private: | ||
std::string GetLastErrorText(int a_nError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because SonarCloud has infiltrated my head: I think this could be made const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had some questions about stuff like the video driver parameter, but I may have missed a discussion about that.
#include "Settings.hxx" | ||
|
||
// option identifiers | ||
enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this enum have a name?
// ================================== | ||
|
||
/// Sets a different video driver | ||
std::string videoDriver = "Default"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will video driver handling be added later in a different PR? I guess I'm also just wondering why this parameter is necessary, like I don't know how many people use different drivers for different programs. But then again, I don't normally run Cytopia from the command line.
Pls fix issues and will add this to repo |
Fixes #940