Issue Details (XML | Word | Printable)

Key: CORE-2535
Type: New Feature New Feature
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Alexander Peshkov
Reporter: Jim Michaels
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Firebird Core

command-line switch standards

Created: 03/Jul/09 06:10 AM   Updated: 27/Jul/09 01:27 AM
Component/s: GBAK, GFIX, GPRE, GSEC, GSTAT, ISQL, NBACKUP, QLI
Affects Version/s: 2.1.3
Fix Version/s: None

Environment: windows, possibly linux too


 Description  « Hide
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.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jim Michaels added a comment - 03/Jul/09 06:34 AM
added #ifdefs, shuffled example code to work with ifdefs, added linux comment.

Mark Rotteveel added a comment - 03/Jul/09 07:23 AM
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

Jim Michaels added a comment - 03/Jul/09 07:48 AM
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

Jim Michaels added a comment - 03/Jul/09 08:08 AM
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.

Claudio Valderrama C. added a comment - 26/Jul/09 06:29 AM
Duplicates CORE-2540.
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.

Jim Michaels added a comment - 27/Jul/09 01:27 AM
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.