OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "a.h" | 5 #include "a.h" |
6 | 6 |
| 7 int vflag; |
| 8 |
7 // cmdtab records the available commands. | 9 // cmdtab records the available commands. |
8 static struct { | 10 static struct { |
9 char *name; | 11 char *name; |
10 void (*f)(int, char**); | 12 void (*f)(int, char**); |
11 } cmdtab[] = { | 13 } cmdtab[] = { |
12 {"bootstrap", cmdbootstrap}, | 14 {"bootstrap", cmdbootstrap}, |
| 15 {"clean", cmdclean}, |
13 {"env", cmdenv}, | 16 {"env", cmdenv}, |
14 {"install", cmdinstall}, | 17 {"install", cmdinstall}, |
15 }; | 18 }; |
16 | 19 |
17 // The OS-specific main calls into the portable code here. | 20 // The OS-specific main calls into the portable code here. |
18 void | 21 void |
19 xmain(int argc, char **argv) | 22 xmain(int argc, char **argv) |
20 { | 23 { |
21 int i; | 24 int i; |
22 | 25 |
23 if(argc <= 1) { | 26 if(argc <= 1) { |
24 xprintf("go tool dist commands:\n"); | 27 xprintf("go tool dist commands:\n"); |
25 for(i=0; i<nelem(cmdtab); i++) | 28 for(i=0; i<nelem(cmdtab); i++) |
26 xprintf("\t%s\n", cmdtab[i].name); | 29 xprintf("\t%s\n", cmdtab[i].name); |
27 xexit(1); | 30 xexit(1); |
28 } | 31 } |
29 ········ | 32 ········ |
30 for(i=0; i<nelem(cmdtab); i++) { | 33 for(i=0; i<nelem(cmdtab); i++) { |
31 if(streq(cmdtab[i].name, argv[1])) { | 34 if(streq(cmdtab[i].name, argv[1])) { |
32 » » » cmdtab[i].f(argc-1, argv+1); | 35 » » » argc--; |
| 36 » » » argv++; |
| 37 » » » // Parse -v options. |
| 38 » » » while(argc > 1 && hasprefix(argv[1], "-v")) { |
| 39 » » » » vflag += xstrlen(argv[1]) - 1; |
| 40 » » » » argc--; |
| 41 » » » » argv++; |
| 42 » » » } |
| 43 » » » argv[0] = cmdtab[i].name; |
| 44 » » » cmdtab[i].f(argc, argv); |
33 return; | 45 return; |
34 } | 46 } |
35 } | 47 } |
36 | 48 |
37 fatal("unknown command %s", argv[1]); | 49 fatal("unknown command %s", argv[1]); |
38 } | 50 } |
OLD | NEW |