Skip to content

Commit

Permalink
Track command version also
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafik committed Nov 28, 2018
1 parent 7914d77 commit 257ead9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions command_subcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ package main

import (
"os"
"strings"

"github.com/fatih/color"
"github.com/urfave/cli"
)

func cmdSubcommand(c *cli.Context) error {
cmd := c.Command.Name
commandName := strings.ToLower(c.Command.Name)

executable, err := findExec(cmd)
executable, err := findExec(commandName)
if err != nil {
return cli.NewExitError(color.RedString("Executable \"%s\" not found.", cmd), 1)
return cli.NewExitError(color.RedString("Executable \"%s\" not found.", commandName), 1)
}

var packageDir string
Expand All @@ -39,7 +40,7 @@ func cmdSubcommand(c *cli.Context) error {
cmdPackage, _ := readPackage(packageDir)

if cmdPackage.Requirements.Python != "" {
if err = migratePythonPackage(cmd, packageDir); err != nil {
if err = migratePythonPackage(commandName, packageDir); err != nil {
return err
}

Expand All @@ -49,7 +50,21 @@ func cmdSubcommand(c *cli.Context) error {
}
}

var currentCmd command
for _, cmd := range cmdPackage.Commands {
if strings.ToLower(cmd.Name) == commandName {
currentCmd = cmd
break
}

for _, alias := range cmd.Aliases {
if strings.ToLower(alias) == commandName {
currentCmd = cmd
}
}
}

executable = append(executable, os.Args[2:]...)
trackEvent("exec", "command", c.Command.Name)
trackEvent("exec", commandName, currentCmd.Version)
return passthruCommand(executable)
}
2 changes: 1 addition & 1 deletion stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func migrateStats(bannerShown bool) bool {
var newStats []string
switch currentVersion {
case "1.0":
newStats = []string{"command name executed (no arguments)"}
newStats = []string{"command name executed (no arguments)", "command version executed"}
}

anonymous := color.New(color.FgWhite, color.Bold).Sprint("anonymous")
Expand Down

0 comments on commit 257ead9

Please sign in to comment.