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
command-line switch standards [CORE2535] #2945
Comments
Commented by: Jim Michaels (jmichae3) added #ifdefs, shuffled example code to work with ifdefs, added linux comment. |
Modified by: Jim Michaels (jmichae3)description: no arguments, unless it has special meaning, I usually delegate to help. for any given windows command-line program, I usually expect the following switches to be handled: you don't have to go with ver or with v. I like to use those in my programs for ease of use. I will include the following code:
=> no arguments, unless it has special meaning, I usually delegate to help. for any given windows command-line program, I usually expect the following switches to be handled: you don't have to go with ver or with v. I like to use those in my programs for ease of use. I will include the following code:
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DJGPP__) it is not proper in linux to use / as a switch like it is with windows (the norm with windows), so you can make that totally optional or kick it in with #ifdefs. |
Commented by: @mrotteveel I don't see a need to add that much different commandline switches for what is in essence the same function. I'd say it is better to standardise and use switches like (short) -h, -v and (long) --help, --version |
Commented by: Jim Michaels (jmichae3) added polite request to make change to command-line programs so they all have a minimum commonly-used standard for help and version switches. added help function section |
Modified by: Jim Michaels (jmichae3)description: no arguments, unless it has special meaning, I usually delegate to help. for any given windows command-line program, I usually expect the following switches to be handled: you don't have to go with ver or with v. I like to use those in my programs for ease of use. I will include the following code:
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DJGPP__) it is not proper in linux to use / as a switch like it is with windows (the norm with windows), so you can make that totally optional or kick it in with #ifdefs. => the current command-line switches don't seem to provide for help or version number. this is standard in the command-line world. please consider adding these switches to the command-line apps in basically the way I have outlined them. this way, the command-line apps have a commonly-used minimum command-line standard for help and version switches that people can use without trouble or extra thought. I have not tested the other applications, but I have tried using gsec and found it nonstandard. what I usually do is implement help as a function, and then call the help function wherever help is needed. note that I do not call exit() within help(). if I want to return 0; or exit(0) after help I will do it elsewhere within the app. I leave that up to the situation at hand - besides, it makes for a kind of coding standard throughout my command-line apps. C concatenates the strings together when you do it like this. no arguments, unless it has special meaning, I usually delegate to help. for any given windows command-line program, I usually expect the following switches to be handled: you don't have to go with ver or with v. I like to use those in my programs for ease of use. I will include the following code: int main(int argc, char * argv[]) {
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DJGPP__) it is not proper in linux to use / as a switch like it is with windows (the norm with windows), so you can make that totally optional or kick it in with #ifdefs. |
Commented by: Jim Michaels (jmichae3) I can agree with Mark's changes. It doesn't have to be a full set. I was simply thinking of the windows users who might be using common / switches. that's why I included the #ifdefs later on. no problem shortening the list. To be honest, more and more programs like databases and utilities that contain command-line utilities for windows today are the GNU kind being ported from *NIX and use -- or - switches anyway. |
Modified by: @AlexPeshkoffassignee: Alexander Peshkov [ alexpeshkoff ] |
Commented by: Claudio Valderrama C. (robocop) Duplicates CORE2540. |
Modified by: Claudio Valderrama C. (robocop)status: Open [ 1 ] => Resolved [ 5 ] resolution: Duplicate [ 3 ] |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Commented by: Jim Michaels (jmichae3) In the Windows and Unix world -v and /v has stood for version or verbose, either one, but --version always gives the version number and --verbose always gives verbosity. If -v conflicts with any of your switches, simply offer --version as an extra switch in addition to -Z. I am just hoping for a change for the better. I won't say any more. |
Submitted by: Jim Michaels (jmichae3)
the current command-line switches don't seem to provide for help or version number. this is standard in the command-line world. please consider adding these switches to the command-line apps in basically the way I have outlined them. this way, the command-line apps have a commonly-used minimum command-line standard for help and version switches that people can use without trouble or extra thought.
I have not tested the other applications, but I have tried using gsec and found it nonstandard.
what I usually do is implement help as a function, and then call the help function wherever help is needed. note that I do not call exit() within help(). if I want to return 0; or exit(0) after help I will do it elsewhere within the app. I leave that up to the situation at hand - besides, it makes for a kind of coding standard throughout my command-line apps. C concatenates the strings together when you do it like this.
void help(void) {
printf(
"blahblah...\n"
"blahblah...\n" /*strings concatenated*/
"moreblahblah...\n"
);
}
no arguments, unless it has special meaning, I usually delegate to help.
for any given windows command-line program, I usually expect the following switches to be handled:
if I want help, I will execute upper or lower-case combinations of the following: gsec [/?] [-[-]?] [-[-]h[elp]] [/h[elp]]
gsec /?
gsec /help
gsec /h
gsec -?
gsec --?
gsec -help
gsec --help
gsec -h
gsec --h
and I expect to get the version number if I do the following: gsec [/v[er[sion]]] [-[-]v[er[sion]]]
gsec /v
gsec /ver
gsec /version
gsec -v
gsec -ver
gsec -version
gsec --v
gsec --ver
gsec --version
you don't have to go with ver or with v. I like to use those in my programs for ease of use.
I will include the following code:
#define PROGRAM_VERSION "3.8"
int main(int argc, char * argv[]) {
argc--;argv++; /* skip past program executeable filename */
/*this if is optional*/
if (argc<1) {
help();
return 0;
}
if (argc>=1 && (
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DJGPP__)
0==strcmp(argv[0], "/H")||
0==strcmp(argv[0], "/HELP") ||
0==strcmp(argv[0], "/Help") ||
0==strcmp(argv[0], "/h") ||
0==strcmp(argv[0], "/help") ||
#endif
0==strcmp(argv[0], "--H") ||
0==strcmp(argv[0], "--HELP") ||
0==strcmp(argv[0], "--Help") ||
0==strcmp(argv[0], "--h") ||
0==strcmp(argv[0], "--help") ||
0==strcmp(argv[0], "-H") ||
0==strcmp(argv[0], "-HELP") ||
0==strcmp(argv[0], "-Help") ||
0==strcmp(argv[0], "-h") ||
0==strcmp(argv[0], "-help")
)) {
help();
return 0;
} else
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DJGPP__)
0==strcmp(argv[0], "/V")||
0==strcmp(argv[0], "/VER") ||
0==strcmp(argv[0], "/VERSION") ||
0==strcmp(argv[0], "/Ver") ||
0==strcmp(argv[0], "/Version") ||
0==strcmp(argv[0], "/v") ||
0==strcmp(argv[0], "/ver") ||
0==strcmp(argv[0], "/version") ||
#endif
0==strcmp(argv[0], "--V") ||
0==strcmp(argv[0], "--VER") ||
0==strcmp(argv[0], "--VERSION") ||
0==strcmp(argv[0], "--Version") ||
0==strcmp(argv[0], "--v") ||
0==strcmp(argv[0], "--ver") ||
0==strcmp(argv[0], "--version") ||
0==strcmp(argv[0], "-V") ||
0==strcmp(argv[0], "-VER") ||
0==strcmp(argv[0], "-VERSION") ||
0==strcmp(argv[0], "-Ver") ||
0==strcmp(argv[0], "-Version") ||
0==strcmp(argv[0], "-v") ||
0==strcmp(argv[0], "-ver") ||
0==strcmp(argv[0], "-version")
)) {
printf("Version %s\n", PROGRAM_VERSION);
return 0;
} else
...
return 0;
}
it is not proper in linux to use / as a switch like it is with windows (the norm with windows), so you can make that totally optional or kick it in with #ifdefs.
The text was updated successfully, but these errors were encountered: