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

command-line switch standards [CORE2535] #2945

Closed
firebird-automations opened this issue Jul 3, 2009 · 11 comments
Closed

command-line switch standards [CORE2535] #2945

firebird-automations opened this issue Jul 3, 2009 · 11 comments

Comments

@firebird-automations
Copy link
Collaborator

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 \(argc\>=1 && \(

#⁠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.

@firebird-automations
Copy link
Collaborator Author

Commented by: Jim Michaels (jmichae3)

added #⁠ifdefs, shuffled example code to work with ifdefs, added linux comment.

@firebird-automations
Copy link
Collaborator Author

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:
if I want help, I will execute upper or lower-case combinations of the following: gsec [/?] [-[-]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"
if (argc>=1 && (
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") ||
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();
free(buf);
return 0;
} else

    if \(argc\>=1 && \(
        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"\) \|\|
        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\);
        free\(buf\);
        return 0;
    \} else

=>

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]]
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"
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();
free(buf);
return 0;
} else

    if \(argc\>=1 && \(

#⁠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);
free(buf);
return 0;
} else

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.

@firebird-automations
Copy link
Collaborator Author

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

@firebird-automations
Copy link
Collaborator Author

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

@firebird-automations
Copy link
Collaborator Author

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:
if I want help, I will execute upper or lower-case combinations of the following: gsec [/?] [-[-]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"
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();
free(buf);
return 0;
} else

    if \(argc\>=1 && \(

#⁠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);
free(buf);
return 0;
} else

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.
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 \(argc\>=1 && \(

#⁠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.

@firebird-automations
Copy link
Collaborator Author

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.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Claudio Valderrama C. (robocop)

Duplicates CORE2540.
Our utilities use -? for help and -Z for version. Since it's the way they have worked for 15 years or more, all the utilities are updated to ensure they recognize the same options.

@firebird-automations
Copy link
Collaborator Author

Modified by: Claudio Valderrama C. (robocop)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Duplicate [ 3 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

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.
the first things I am going to try for help is -? or -h or --help. since -h is host, you can probably leave that out. just about every command-line program out there supports all of these for help to ensure a 100% hit rate, and most SQL databases are tending to lean more toward unix-style command-lines, using whole-word and regular switches like --modify and -mo for short.

I am just hoping for a change for the better. I won't say any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment