Skip to content

Commit

Permalink
fix(tool): add alias support to kythe command, add alias for "decor" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysachs committed May 19, 2021
1 parent 97c5505 commit 9fe7e8e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 12 deletions.
14 changes: 12 additions & 2 deletions kythe/go/services/cli/cli.go
Expand Up @@ -87,10 +87,13 @@ func Execute(ctx context.Context, api API) subcommands.ExitStatus {
// RegisterCommand adds a KytheCommand to the list of subcommands for the
// specified group.
func RegisterCommand(c KytheCommand, group string) {
subcommands.Register(&commandWrapper{c}, group)
cmd := &commandWrapper{c}
subcommands.Register(cmd, group)
for _, a := range c.Aliases() {
subcommands.Alias(a, cmd)
}
}

// TODO(schroederc): subcommand aliases
// TODO(schroederc): more documentation per command
// TODO(schroederc): split commands into separate packages

Expand All @@ -114,12 +117,19 @@ func (w *commandWrapper) Execute(ctx context.Context, f *flag.FlagSet, args ...i
// A KytheCommand is a type-safe version of the subcommands.Command interface.
type KytheCommand interface {
Name() string
Aliases() []string
Synopsis() string
Usage() string
SetFlags(*flag.FlagSet)
Run(context.Context, *flag.FlagSet, API) error
}

type baseKytheCommand struct{}

func (kc *baseKytheCommand) Aliases() []string { return nil }
func (kc *baseKytheCommand) Usage() string { return "" }
func (kc *baseKytheCommand) SetFlags(*flag.FlagSet) {}

// LogRequest should be passed all proto request messages for logging.
func LogRequest(req proto.Message) {
if *logRequests {
Expand Down
7 changes: 4 additions & 3 deletions kythe/go/services/cli/command_decor.go
Expand Up @@ -52,6 +52,7 @@ var (

// baseDecorCommand is a shared base for the source/decor/diagnostics commands
type baseDecorCommand struct {
baseKytheCommand
decorSpan string
corpus, root, pathPrefix string
buildConfigs flagutil.StringSet
Expand Down Expand Up @@ -124,9 +125,9 @@ type decorCommand struct {
semanticScopes bool
}

func (decorCommand) Name() string { return "decor" }
func (decorCommand) Synopsis() string { return "list a file's decorations" }
func (decorCommand) Usage() string { return "" }
func (decorCommand) Name() string { return "decor" }
func (decorCommand) Synopsis() string { return "list a file's decorations" }
func (decorCommand) Aliases() []string { return []string{"decors"} }
func (c *decorCommand) SetFlags(flag *flag.FlagSet) {
c.baseDecorCommand.SetFlags(flag)
// TODO(schroederc): add option to look for dirty files based on file-ticket path and a directory root
Expand Down
7 changes: 4 additions & 3 deletions kythe/go/services/cli/command_diagnostics.go
Expand Up @@ -30,9 +30,10 @@ type diagnosticsCommand struct {
baseDecorCommand
}

func (diagnosticsCommand) Name() string { return "diagnostics" }
func (diagnosticsCommand) Synopsis() string { return "list a file's diagnostics" }
func (diagnosticsCommand) Usage() string { return "" }
func (diagnosticsCommand) Name() string { return "diagnostics" }
func (diagnosticsCommand) Aliases() []string { return []string{"diags"} }
func (diagnosticsCommand) Synopsis() string { return "list a file's diagnostics" }
func (diagnosticsCommand) Usage() string { return "" }
func (c *diagnosticsCommand) SetFlags(flag *flag.FlagSet) {
c.baseDecorCommand.SetFlags(flag)
}
Expand Down
2 changes: 1 addition & 1 deletion kythe/go/services/cli/command_docs.go
Expand Up @@ -27,13 +27,13 @@ import (
)

type docsCommand struct {
baseKytheCommand
nodeFilters string
includeChildren bool
}

func (docsCommand) Name() string { return "docs" }
func (docsCommand) Synopsis() string { return "display documentation for a node" }
func (docsCommand) Usage() string { return "" }
func (c *docsCommand) SetFlags(flag *flag.FlagSet) {
flag.StringVar(&c.nodeFilters, "filters", "", "Comma-separated list of node fact filters (default returns all)")
flag.BoolVar(&c.includeChildren, "include_children", false, "Include documentation for children of the given node")
Expand Down
2 changes: 1 addition & 1 deletion kythe/go/services/cli/command_edges.go
Expand Up @@ -36,6 +36,7 @@ import (
)

type edgesCommand struct {
baseKytheCommand
dotGraph bool
countOnly bool
targetsOnly bool
Expand All @@ -46,7 +47,6 @@ type edgesCommand struct {

func (edgesCommand) Name() string { return "edges" }
func (edgesCommand) Synopsis() string { return "retrieve outward edges from a node" }
func (edgesCommand) Usage() string { return "" }
func (c *edgesCommand) SetFlags(flag *flag.FlagSet) {
flag.BoolVar(&c.dotGraph, "graphviz", false, "Print resulting edges as a dot graph")
flag.BoolVar(&c.countOnly, "count_only", false, "Only print counts per edge kind")
Expand Down
1 change: 1 addition & 0 deletions kythe/go/services/cli/command_identifiers.go
Expand Up @@ -27,6 +27,7 @@ import (
)

type identCommand struct {
baseKytheCommand
corpora, languages string
}

Expand Down
2 changes: 1 addition & 1 deletion kythe/go/services/cli/command_ls.go
Expand Up @@ -30,14 +30,14 @@ import (
)

type lsCommand struct {
baseKytheCommand
lsURIs bool
filesOnly bool
dirsOnly bool
}

func (lsCommand) Name() string { return "ls" }
func (lsCommand) Synopsis() string { return "list a directory's contents" }
func (lsCommand) Usage() string { return "" }
func (c *lsCommand) SetFlags(flag *flag.FlagSet) {
flag.BoolVar(&c.lsURIs, "uris", false, "Display files/directories as Kythe URIs")
flag.BoolVar(&c.filesOnly, "files", false, "Display only files")
Expand Down
2 changes: 1 addition & 1 deletion kythe/go/services/cli/command_nodes.go
Expand Up @@ -27,13 +27,13 @@ import (
)

type nodesCommand struct {
baseKytheCommand
nodeFilters string
factSizeThreshold int
}

func (nodesCommand) Name() string { return "nodes" }
func (nodesCommand) Synopsis() string { return "retrieve a node's facts" }
func (nodesCommand) Usage() string { return "" }
func (c *nodesCommand) SetFlags(flag *flag.FlagSet) {
flag.StringVar(&c.nodeFilters, "filters", "", "Comma-separated list of node fact filters (default returns all)")
flag.IntVar(&c.factSizeThreshold, "max_fact_size", 64,
Expand Down
1 change: 1 addition & 0 deletions kythe/go/services/cli/commands_xrefs.go
Expand Up @@ -34,6 +34,7 @@ import (
)

type xrefsCommand struct {
baseKytheCommand
nodeFilters flagutil.StringList
buildConfigs flagutil.StringSet

Expand Down

0 comments on commit 9fe7e8e

Please sign in to comment.