diff --git a/cmd/pk/dbinit.go b/cmd/pk/dbinit.go index 62d9ba09c..5a1437726 100644 --- a/cmd/pk/dbinit.go +++ b/cmd/pk/dbinit.go @@ -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." } diff --git a/cmd/pk/debug.go b/cmd/pk/debug.go index 261d2e67a..678b0105a 100644 --- a/cmd/pk/debug.go +++ b/cmd/pk/debug.go @@ -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." } diff --git a/cmd/pk/disco.go b/cmd/pk/disco.go index e1b2fb7fd..678ddd5c4 100644 --- a/cmd/pk/disco.go +++ b/cmd/pk/disco.go @@ -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." } diff --git a/cmd/pk/dp_idx_rebuild.go b/cmd/pk/dp_idx_rebuild.go index 20ec019f5..372de0564 100644 --- a/cmd/pk/dp_idx_rebuild.go +++ b/cmd/pk/dp_idx_rebuild.go @@ -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" } diff --git a/cmd/pk/googinit.go b/cmd/pk/googinit.go index fa0d86b4c..bd9d398b4 100644 --- a/cmd/pk/googinit.go +++ b/cmd/pk/googinit.go @@ -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." } diff --git a/cmd/pk/index.go b/cmd/pk/index.go index 055350f25..30aa0b8eb 100644 --- a/cmd/pk/index.go +++ b/cmd/pk/index.go @@ -34,7 +34,9 @@ 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.") } @@ -42,8 +44,10 @@ func init() { }) } +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() { diff --git a/cmd/pk/packblobs.go b/cmd/pk/packblobs.go index bdf662648..0ade2f92d 100644 --- a/cmd/pk/packblobs.go +++ b/cmd/pk/packblobs.go @@ -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)" } diff --git a/cmd/pk/search.go b/cmd/pk/search.go index 2db681820..3891aaa24 100644 --- a/cmd/pk/search.go +++ b/cmd/pk/search.go @@ -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`, } } diff --git a/cmd/pk/sync.go b/cmd/pk/sync.go index 693a4f00c..32a82ee0b 100644 --- a/cmd/pk/sync.go +++ b/cmd/pk/sync.go @@ -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() { @@ -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) diff --git a/pkg/cmdmain/cmdmain.go b/pkg/cmdmain/cmdmain.go index 7ee169a2b..2c1d4c1f3 100644 --- a/pkg/cmdmain/cmdmain.go +++ b/pkg/cmdmain/cmdmain.go @@ -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 } @@ -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) { @@ -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] [commandopts] [commandargs] +Usage: `+cmdName+` [globalopts] [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())) } } @@ -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 { @@ -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 {