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

get --help and --version to write to stdout #569

Merged
merged 4 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*.pro.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
Makefile*
Expand Down
43 changes: 22 additions & 21 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ int main(int argc, char *argv[])
setenv("LC_CTYPE", "UTF-8", 1);
#endif

if (argc>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help"))) {
QTextStream cout(stdout, QIODevice::WriteOnly);
cout << "Usage: " << argv[0] << " [--default-settings] [--workdir <dir>] [--program <prog>] [-p|--profile <prof>] [--fullscreen] [-h|--help]" << endl;
cout << " --default-settings Run cool-retro-term with the default settings" << endl;
cout << " --workdir <dir> Change working directory to 'dir'" << endl;
cout << " -e <cmd> Command to execute. This option will catch all following arguments, so use it as the last option." << endl;
cout << " -T <title> Set window title to 'title'." << endl;
cout << " --fullscreen Run cool-retro-term in fullscreen." << endl;
cout << " -p|--profile <prof> Run cool-retro-term with the given profile." << endl;
cout << " -h|--help Print this help." << endl;
cout << " --verbose Print additional information such as profiles and settings." << endl;
return 0;
}

QString appVersion("1.1.1");

if (argc>1 && (!strcmp(argv[1],"-v") || !strcmp(argv[1],"--version"))) {
QTextStream cout(stdout, QIODevice::WriteOnly);
cout << "cool-retro-term " << appVersion << endl;
return 0;
}

QApplication app(argc, argv);
// set application attributes
// Has no effects, see https://bugreports.qt.io/browse/QTBUG-51293
Expand All @@ -59,27 +81,6 @@ int main(int argc, char *argv[])

// Manage command line arguments from the cpp side
QStringList args = app.arguments();
if (args.contains("-h") || args.contains("--help")) {
// BUG: This usage help text goes to stderr, should go to stdout.
// BUG: First line of output is surrounded by double quotes.
qDebug() << "Usage: " + args.at(0) + " [--default-settings] [--workdir <dir>] [--program <prog>] [-p|--profile <prof>] [--fullscreen] [-h|--help]";
qDebug() << " --default-settings Run cool-retro-term with the default settings";
qDebug() << " --workdir <dir> Change working directory to 'dir'";
qDebug() << " -e <cmd> Command to execute. This option will catch all following arguments, so use it as the last option.";
qDebug() << " -T <title> Set window title to 'title'.";
qDebug() << " --fullscreen Run cool-retro-term in fullscreen.";
qDebug() << " -p|--profile <prof> Run cool-retro-term with the given profile.";
qDebug() << " -h|--help Print this help.";
qDebug() << " --verbose Print additional information such as profiles and settings.";
return 0;
}

QString appVersion("1.1.1");

if (args.contains("-v") || args.contains("--version")) {
qDebug() << ("cool-retro-term " + appVersion).toStdString().c_str();
return 0;
}

// Manage default command
QStringList cmdList;
Expand Down