diff --git a/cli/cmd/turbo/main.go b/cli/cmd/turbo/main.go index 0169cc02d522d..58b04b0c70095 100644 --- a/cli/cmd/turbo/main.go +++ b/cli/cmd/turbo/main.go @@ -7,6 +7,7 @@ import ( "strings" "time" "turbo/internal/config" + "turbo/internal/info" "turbo/internal/login" "turbo/internal/process" prune "turbo/internal/prune" @@ -96,6 +97,9 @@ func main() { "logout": func() (cli.Command, error) { return &login.LogoutCommand{Config: cf, Ui: ui}, nil }, + "bin": func() (cli.Command, error) { + return &info.BinCommand{Config: cf, Ui: ui}, nil + }, } // Capture the defer statements below so the "done" message comes last diff --git a/cli/internal/info/bin.go b/cli/internal/info/bin.go new file mode 100644 index 0000000000000..5dec1823a55ad --- /dev/null +++ b/cli/internal/info/bin.go @@ -0,0 +1,54 @@ +package info + +import ( + "fmt" + "os" + "strings" + "turbo/internal/config" + "turbo/internal/ui" + + "github.com/fatih/color" + "github.com/hashicorp/go-hclog" + "github.com/mitchellh/cli" +) + +type BinCommand struct { + Config *config.Config + Ui *cli.ColoredUi +} + +// Synopsis of run command +func (c *BinCommand) Synopsis() string { + return "Get the path to the Turbo binary" +} + +// Help returns information about the `bin` command +func (c *BinCommand) Help() string { + helpText := ` +Usage: turbo bin + + Get the path to the Turbo binary +` + return strings.TrimSpace(helpText) +} + +func (c *BinCommand) Run(args []string) int { + path, err := os.Executable() + if err != nil { + c.logError(c.Config.Logger, "", fmt.Errorf("could not get path to turbo binary: %w", err)) + return 1 + } + c.Ui.Output(path) + return 0 +} + +// logError logs an error and outputs it to the UI. +func (c *BinCommand) logError(log hclog.Logger, prefix string, err error) { + log.Error(prefix, "error", err) + + if prefix != "" { + prefix += ": " + } + + c.Ui.Error(fmt.Sprintf("%s%s%s", ui.ERROR_PREFIX, prefix, color.RedString(" %v", err))) +} diff --git a/cli/internal/login/logout.go b/cli/internal/login/logout.go index 2531c24ebd642..c1948197dc99f 100644 --- a/cli/internal/login/logout.go +++ b/cli/internal/login/logout.go @@ -20,7 +20,7 @@ type LogoutCommand struct { // Synopsis of run command func (c *LogoutCommand) Synopsis() string { - return "Logout of your Turborepo account" + return "Logout of your Vercel account" } // Help returns information about the `run` command @@ -28,7 +28,7 @@ func (c *LogoutCommand) Help() string { helpText := ` Usage: turbo logout - Login of your Turborepo account + Logout of your Vercel account ` return strings.TrimSpace(helpText) } diff --git a/docs/pages/docs/reference/command-line-reference.mdx b/docs/pages/docs/reference/command-line-reference.mdx index 8997e7e8ac623..c71c170f6cee0 100644 --- a/docs/pages/docs/reference/command-line-reference.mdx +++ b/docs/pages/docs/reference/command-line-reference.mdx @@ -420,6 +420,10 @@ Defaults to `https://vercel.com`. Defaults to `https://api.vercel.com`. +## `turbo logout` + +Logs you out of your Vercel account. + ## `turbo link` Link the current directory to Remote Cache scope. The selected owner (either a user or and organization) will be able to share [cache artifacts](../features/caching) through [Remote Caching](../features/remote-caching). @@ -433,6 +437,10 @@ You should run this command from the root of your monorepo. Defaults to `https://api.vercel.com` -### `turbo unlink` +## `turbo unlink` + +Unlink the current directory from the Remote Cache. + +## `turbo bin` -Unlink the current directory from the Remote Cache +Get the path to the Turbo binary.