Fossil SCM

Rework -help implementation so -help can be added to any command line even if it already contained an option that the help command would have interpreted. For example, "fossil clean -x -help" now prints help about the clean command, whereas before it was did the same as "fossil help -x", i.e. list auxiliary commands without mentioning clean. Make sure to fall back on the current implementation so "fossil -help -x" and such still work correctly.

andygoth 2015-06-19 16:19 UTC trunk
Commit 3a9017f9d1d8b1862a94ae13bfc9bb2d22e6740e
1 file changed +19 -6
+19 -6
--- src/main.c
+++ src/main.c
@@ -683,19 +683,32 @@
683683
if( find_option("localtime",0,0) ) g.fTimeFormat = 2;
684684
if( zChdir && file_chdir(zChdir, 0) ){
685685
fossil_fatal("unable to change directories to %s", zChdir);
686686
}
687687
if( find_option("help",0,0)!=0 ){
688
- /* --help anywhere on the command line is translated into
689
- ** "fossil help argv[1] argv[2]..." */
690
- int i;
688
+ /* If --help is found anywhere on the command line, translate the command
689
+ * to "fossil help cmdname" where "cmdname" is the first argument that
690
+ * does not begin with a "-" character. If all arguments start with "-",
691
+ * translate to "fossil help argv[1] argv[2]...". */
692
+ int i, nNewArgc;
691693
char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
692
- for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i];
693
- zNewArgv[i+1] = 0;
694694
zNewArgv[0] = g.argv[0];
695695
zNewArgv[1] = "help";
696
- g.argc++;
696
+ for(i=1; i<g.argc; i++){
697
+ if( g.argv[i][0]!='-' ){
698
+ nNewArgc = 3;
699
+ zNewArgv[2] = g.argv[i];
700
+ zNewArgv[3] = 0;
701
+ break;
702
+ }
703
+ }
704
+ if( i==g.argc ){
705
+ for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i];
706
+ nNewArgc = g.argc+1;
707
+ zNewArgv[i+1] = 0;
708
+ }
709
+ g.argc = nNewArgc;
697710
g.argv = zNewArgv;
698711
}
699712
zCmdName = g.argv[1];
700713
}
701714
#ifndef _WIN32
702715
--- src/main.c
+++ src/main.c
@@ -683,19 +683,32 @@
683 if( find_option("localtime",0,0) ) g.fTimeFormat = 2;
684 if( zChdir && file_chdir(zChdir, 0) ){
685 fossil_fatal("unable to change directories to %s", zChdir);
686 }
687 if( find_option("help",0,0)!=0 ){
688 /* --help anywhere on the command line is translated into
689 ** "fossil help argv[1] argv[2]..." */
690 int i;
 
 
691 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
692 for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i];
693 zNewArgv[i+1] = 0;
694 zNewArgv[0] = g.argv[0];
695 zNewArgv[1] = "help";
696 g.argc++;
 
 
 
 
 
 
 
 
 
 
 
 
 
697 g.argv = zNewArgv;
698 }
699 zCmdName = g.argv[1];
700 }
701 #ifndef _WIN32
702
--- src/main.c
+++ src/main.c
@@ -683,19 +683,32 @@
683 if( find_option("localtime",0,0) ) g.fTimeFormat = 2;
684 if( zChdir && file_chdir(zChdir, 0) ){
685 fossil_fatal("unable to change directories to %s", zChdir);
686 }
687 if( find_option("help",0,0)!=0 ){
688 /* If --help is found anywhere on the command line, translate the command
689 * to "fossil help cmdname" where "cmdname" is the first argument that
690 * does not begin with a "-" character. If all arguments start with "-",
691 * translate to "fossil help argv[1] argv[2]...". */
692 int i, nNewArgc;
693 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
 
 
694 zNewArgv[0] = g.argv[0];
695 zNewArgv[1] = "help";
696 for(i=1; i<g.argc; i++){
697 if( g.argv[i][0]!='-' ){
698 nNewArgc = 3;
699 zNewArgv[2] = g.argv[i];
700 zNewArgv[3] = 0;
701 break;
702 }
703 }
704 if( i==g.argc ){
705 for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i];
706 nNewArgc = g.argc+1;
707 zNewArgv[i+1] = 0;
708 }
709 g.argc = nNewArgc;
710 g.argv = zNewArgv;
711 }
712 zCmdName = g.argv[1];
713 }
714 #ifndef _WIN32
715

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button