Skip to content

Commit

Permalink
Merge "cmdmain, cmd/pk: support for demoting prominence of some subco…
Browse files Browse the repository at this point in the history
…mmands"
  • Loading branch information
bradfitz authored and Gerrit Code Review committed May 2, 2018
2 parents 91c36ff + f483cba commit 0c28468
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmd/pk/dbinit.go
Expand Up @@ -69,6 +69,8 @@ func init() {
})
}

func (c *dbinitCmd) Demote() bool { return true }

func (c *dbinitCmd) Describe() string {
return "Set up the database for the indexer."
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/pk/debug.go
Expand Up @@ -53,6 +53,8 @@ func init() {
})
}

func (c *debugCmd) Demote() bool { return true }

func (c *debugCmd) Describe() string {
return "Show misc meta-info from the given file."
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/pk/disco.go
Expand Up @@ -39,6 +39,8 @@ func init() {
})
}

func (c *discoCmd) Demote() bool { return true }

func (c *discoCmd) Describe() string {
return "Perform configuration discovery against a server."
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/pk/dp_idx_rebuild.go
Expand Up @@ -44,6 +44,8 @@ func init() {
})
}

func (c *reindexdpCmd) Demote() bool { return true }

func (c *reindexdpCmd) Describe() string {
return "Rebuild the index of the diskpacked blob store"
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/pk/googinit.go
Expand Up @@ -44,6 +44,8 @@ func init() {
})
}

func (c *googinitCmd) Demote() bool { return true }

func (c *googinitCmd) Describe() string {
return "Init Google Drive or Google Cloud Storage."
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/pk/index.go
Expand Up @@ -34,16 +34,20 @@ type indexCmd struct {
func init() {
cmdmain.RegisterMode("index", func(flags *flag.FlagSet) cmdmain.CommandRunner {
cmd := new(indexCmd)
flags.BoolVar(&cmd.wipe, "wipe", false, "Erase and recreate all discovered indexes. NOOP for now.")

// TODO: add client-initiated wipe support?
// flags.BoolVar(&cmd.wipe, "wipe", false, "Erase and recreate all discovered indexes. NOOP for now.")
if debug, _ := strconv.ParseBool(os.Getenv("CAMLI_DEBUG")); debug {
flags.BoolVar(&cmd.insecureTLS, "insecure", false, "If set, when using TLS, the server's certificates verification is disabled, and they are not checked against the trustedCerts in the client configuration either.")
}
return cmd
})
}

func (c *indexCmd) Demote() bool { return true }

func (c *indexCmd) Describe() string {
return "Synchronize blobs for all discovered blobs storage - indexer pairs."
return "Synchronize blobs for all discovered blobs storage -> indexer sync pairs."
}

func (c *indexCmd) Usage() {
Expand Down
2 changes: 2 additions & 0 deletions cmd/pk/packblobs.go
Expand Up @@ -40,6 +40,8 @@ func init() {
})
}

func (c *packBlobsCmd) Demote() bool { return true }

func (c *packBlobsCmd) Describe() string {
return "Pack related blobs together (migration tool)"
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pk/search.go
Expand Up @@ -64,7 +64,7 @@ func (c *searchCmd) Usage() {
func (c *searchCmd) Examples() []string {
return []string{
`"loc:paris is:portrait" # expression`,
`'{"blobrefPrefix":"sha1-f00d"}' # SearchConstraint JSON`,
`'{"blobrefPrefix":"sha224-f00d"}' # SearchConstraint JSON`,
`- # piped from stdin`,
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/pk/sync.go
Expand Up @@ -77,7 +77,7 @@ func init() {
}

func (c *syncCmd) Describe() string {
return "Synchronize blobs from a source to a destination."
return "(Re)synchronize blobs from a source to a destination."
}

func (c *syncCmd) Usage() {
Expand Down Expand Up @@ -370,7 +370,7 @@ func (c *syncCmd) doPass(src, dest, thirdLeg blobserver.Storage) (stats SyncStat
if c.wipe {
// TODO(mpl): dest is a client. make it send a "wipe" request?
// upon reception its server then wipes itself if it is a wiper.
log.Print("Index wiping not yet supported.")
log.Fatal("Index wiping not yet supported.")
}

go enumerate(destErr, dest, destBlobs)
Expand Down
29 changes: 23 additions & 6 deletions pkg/cmdmain/cmdmain.go
Expand Up @@ -105,6 +105,14 @@ type ExecRunner interface {
LookPath() (string, error)
}

// Demoter is an interface that boring commands can implement to
// demote themselves in the tool listing, for boring or low-level
// subcommands. They only show up in --help mode.
type Demoter interface {
CommandRunner
Demote() bool
}

type exampler interface {
Examples() []string
}
Expand All @@ -113,6 +121,11 @@ type describer interface {
Describe() string
}

func demote(c CommandRunner) bool {
i, ok := c.(Demoter)
return ok && i.Demote()
}

// RegisterMode adds a mode to the list of modes for the main command.
// It is meant to be called in init() for each subcommand.
func RegisterMode(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner) {
Expand Down Expand Up @@ -151,15 +164,19 @@ func usage(msg string) {
if msg != "" {
Errorf("Error: %v\n", msg)
}
var modesQualifer string
if !*FlagHelp {
modesQualifer = " (use --help to see all modes)"
}
Errorf(`
Usage: ` + cmdName + ` [globalopts] <mode> [commandopts] [commandargs]
Usage: `+cmdName+` [globalopts] <mode> [commandopts] [commandargs]
Modes:
Modes:%s
`)
`, modesQualifer)
var modes []string
for mode, cmd := range modeCommand {
if des, ok := cmd.(describer); ok {
if des, ok := cmd.(describer); ok && (*FlagHelp || !demote(cmd)) {
modes = append(modes, fmt.Sprintf(" %s: %s\n", mode, des.Describe()))
}
}
Expand All @@ -171,7 +188,7 @@ Modes:
Errorf("\nExamples:\n")
modes = nil
for mode, cmd := range modeCommand {
if ex, ok := cmd.(exampler); ok {
if ex, ok := cmd.(exampler); ok && (*FlagHelp || !demote(cmd)) {
line := ""
exs := ex.Examples()
if len(exs) > 0 {
Expand Down Expand Up @@ -250,7 +267,7 @@ func Main() {

args := flag.Args()
if *FlagVersion {
fmt.Fprintf(Stderr, "%s version: %s\n", os.Args[0], buildinfo.Version())
fmt.Fprintf(Stderr, "%s version: %s\n", os.Args[0], buildinfo.Summary())
return
}
if *FlagHelp {
Expand Down

0 comments on commit 0c28468

Please sign in to comment.