Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AnotherFoxGuy
Copy link
Member

Fixes #940

SimplyLiz
SimplyLiz previously approved these changes May 20, 2022
Copy link
Contributor

@SimplyLiz SimplyLiz left a 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;
Copy link
Member

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?

@Bogi79
Copy link
Member

Bogi79 commented May 20, 2022

I think it is better not to write to the setting with cmd line parameters.
I would expect it only override current settings but preserve them.

@AnotherFoxGuy
Copy link
Member Author

I think it is better not to write to the setting with cmd line parameters.

It doesn't get written to the json file

@Bogi79
Copy link
Member

Bogi79 commented Jun 1, 2022

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
// ==================================
Copy link
Member

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)
Copy link
Contributor

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";
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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")
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Collaborator

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";
Copy link
Contributor

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 )?

@sonarcloud
Copy link

sonarcloud bot commented Jun 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@dalerank
Copy link
Contributor

dalerank commented Jul 4, 2022

@AnotherFoxGuy pls fix conflicts and nits

@sonarcloud
Copy link

sonarcloud bot commented Jul 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

bool ProcessCommandLine(int argc, char **argv);

private:
std::string GetLastErrorText(int a_nError);
Copy link
Collaborator

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.

Copy link
Collaborator

@lizzyd710 lizzyd710 left a 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
Copy link
Collaborator

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";
Copy link
Collaborator

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.

@dalerank
Copy link
Contributor

Pls fix issues and will add this to repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command line parameters
5 participants