1
0
mirror of https://github.com/golang/go synced 2024-11-08 05:36:13 -07:00
go/src/cmd/dist/main.go
Brad Fitzpatrick 519474451a all: make copyright headers consistent with one space after period
This is a subset of https://golang.org/cl/20022 with only the copyright
header lines, so the next CL will be smaller and more reviewable.

Go policy has been single space after periods in comments for some time.

The copyright header template at:

    https://golang.org/doc/contribute.html#copyright

also uses a single space.

Make them all consistent.

Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0
Reviewed-on: https://go-review.googlesource.com/20111
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01 23:34:33 +00:00

88 lines
1.6 KiB
Go

// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"os"
"strconv"
)
// cmdtab records the available commands.
var cmdtab = []struct {
name string
f func()
}{
{"banner", cmdbanner},
{"bootstrap", cmdbootstrap},
{"clean", cmdclean},
{"env", cmdenv},
{"install", cmdinstall},
{"list", cmdlist},
{"test", cmdtest},
{"version", cmdversion},
}
// The OS-specific main calls into the portable code here.
func xmain() {
if len(os.Args) < 2 {
usage()
}
cmd := os.Args[1]
os.Args = os.Args[1:] // for flag parsing during cmd
for _, ct := range cmdtab {
if ct.name == cmd {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: go tool dist %s [options]\n", cmd)
flag.PrintDefaults()
os.Exit(2)
}
ct.f()
return
}
}
xprintf("unknown command %s\n", cmd)
usage()
}
func xflagparse(maxargs int) {
flag.Var((*count)(&vflag), "v", "verbosity")
flag.Parse()
if maxargs >= 0 && flag.NArg() > maxargs {
flag.Usage()
}
}
// count is a flag.Value that is like a flag.Bool and a flag.Int.
// If used as -name, it increments the count, but -name=x sets the count.
// Used for verbose flag -v.
type count int
func (c *count) String() string {
return fmt.Sprint(int(*c))
}
func (c *count) Set(s string) error {
switch s {
case "true":
*c++
case "false":
*c = 0
default:
n, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("invalid count %q", s)
}
*c = count(n)
}
return nil
}
func (c *count) IsBoolFlag() bool {
return true
}