Skip to content

🔧 Added class for parsing command line parameters#941

Open
AnotherFoxGuy wants to merge 1 commit intoCytopiaTeam:masterfrom
AnotherFoxGuy:cli
Open

🔧 Added class for parsing command line parameters#941
AnotherFoxGuy wants to merge 1 commit intoCytopiaTeam:masterfrom
AnotherFoxGuy:cli

Conversation

@AnotherFoxGuy
Copy link
Copy Markdown
Member

Fixes #940

SimplyLiz
SimplyLiz previously approved these changes May 20, 2022
Copy link
Copy Markdown
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!

Comment thread src/util/ParseCli.cxx
if (args.LastError() != SO_SUCCESS)
{
LOG(LOG_ERROR) << GetLastErrorText(args.LastError()) << " " << args.OptionText();
success = false;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread src/Game.cxx Outdated
vd = Settings::instance().videoDriver.c_str();

if (SDL_VideoInit(videoDriver) != 0)
if (SDL_VideoInit(vd) != 0)
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/main.cxx
{
videoDriver = argv[videoOpt + 1];
}
ParseCli cli;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser cli?

Comment thread src/main.cxx Outdated
return EXIT_FAILURE;

if (!skipMenu)
bool quitGame = Settings::instance().quitGame;
Copy link
Copy Markdown
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?

Comment thread src/main.cxx
if (!skipMenu)
bool quitGame = Settings::instance().quitGame;

if (!Settings::instance().skipMenu)
Copy link
Copy Markdown
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

Comment thread src/util/ParseCli.hxx
#include "SimpleOpt.h"
#include <string>

class ParseCli
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParserCli?

Comment thread src/util/ParseCli.cxx
// option identifiers
enum
{
OPT_HELP,
Copy link
Copy Markdown
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

Comment thread src/Game.cxx Outdated
return false;
}
const char *vd = nullptr;
if(Settings::instance().videoDriver != "Default")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if

Comment thread src/Game.hxx
* @param SkipMenu if the main menu should be skipped or not
*/
virtual void run(bool SkipMenu = false);
virtual void run();
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/main.cxx

Cytopia::Game game;

LOG(LOG_DEBUG) << "Initializing Cytopia";
Copy link
Copy Markdown
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 )?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud 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
Copy Markdown
Contributor

dalerank commented Jul 4, 2022

@AnotherFoxGuy pls fix conflicts and nits

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud 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

Comment thread src/util/ParseCli.hxx
bool ProcessCommandLine(int argc, char **argv);

private:
std::string GetLastErrorText(int a_nError);
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/util/ParseCli.cxx
#include "Settings.hxx"

// option identifiers
enum
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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