From 2cf97fd7c542d0a67103cb3a3197ba818c3b508e Mon Sep 17 00:00:00 2001 From: Samuel Corsi-House Date: Fri, 14 Jan 2022 10:41:34 -0500 Subject: [PATCH 1/3] feat: turbo bin --- cli/cmd/turbo/main.go | 4 +++ cli/internal/info/bin.go | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 cli/internal/info/bin.go diff --git a/cli/cmd/turbo/main.go b/cli/cmd/turbo/main.go index 80776d5f6ee66..aba60a65b0623 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" prune "turbo/internal/prune" "turbo/internal/run" @@ -83,6 +84,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..3e0501bc6bb54 --- /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 executable" +} + +// Help returns information about the `bin` command +func (c *BinCommand) Help() string { + helpText := ` +Usage: turbo bin + Get the path to the Turbo executable +` + 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))) +} + From 3e0023883e9be77167e166d8c9febeb3eee8d324 Mon Sep 17 00:00:00 2001 From: Samuel Corsi-House Date: Fri, 14 Jan 2022 10:48:26 -0500 Subject: [PATCH 2/3] fix: executable -> binary & edit description --- cli/internal/info/bin.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/internal/info/bin.go b/cli/internal/info/bin.go index 3e0501bc6bb54..82d06d7abc3b5 100644 --- a/cli/internal/info/bin.go +++ b/cli/internal/info/bin.go @@ -19,14 +19,15 @@ type BinCommand struct { // Synopsis of run command func (c *BinCommand) Synopsis() string { - return "Get the path to the Turbo executable" + 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 executable + + Get the path to the Turbo binary ` return strings.TrimSpace(helpText) } From 0aba690b98151c88179b0d3986ddba7198b64239 Mon Sep 17 00:00:00 2001 From: Samuel Corsi-House Date: Fri, 14 Jan 2022 11:16:24 -0500 Subject: [PATCH 3/3] docs: update docs --- cli/internal/context/context.go | 2 +- cli/internal/info/bin.go | 1 - cli/internal/login/logout.go | 4 ++-- cli/internal/util/backends.go | 21 +++++++++---------- .../docs/reference/command-line-reference.mdx | 12 +++++++++-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cli/internal/context/context.go b/cli/internal/context/context.go index 819833205c19c..923341f302857 100644 --- a/cli/internal/context/context.go +++ b/cli/internal/context/context.go @@ -284,7 +284,7 @@ func (c *Context) loadPackageDepsHash(pkg *fs.PackageJSON) error { return nil } -func (c *Context) ResolveWorkspaceRootDeps() (error) { +func (c *Context) ResolveWorkspaceRootDeps() error { seen := mapset.NewSet() var lockfileWg sync.WaitGroup pkg := c.RootPackageJSON diff --git a/cli/internal/info/bin.go b/cli/internal/info/bin.go index 82d06d7abc3b5..5dec1823a55ad 100644 --- a/cli/internal/info/bin.go +++ b/cli/internal/info/bin.go @@ -52,4 +52,3 @@ func (c *BinCommand) logError(log hclog.Logger, prefix string, err error) { 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/cli/internal/util/backends.go b/cli/internal/util/backends.go index 8dfa362a19410..14501c1a9c925 100644 --- a/cli/internal/util/backends.go +++ b/cli/internal/util/backends.go @@ -20,16 +20,16 @@ func IsYarn(backendName string) bool { } func IsBerry(cwd string, version string) (bool, error) { - v, err := semver.NewVersion(version) - if err != nil { - return false, fmt.Errorf("could not parse yarn version: %w", err) - } - c, err := semver.NewConstraint(">=2.0.0") - if err != nil { - return false, fmt.Errorf("could not create constraint: %w", err) - } - - return c.Check(v), nil + v, err := semver.NewVersion(version) + if err != nil { + return false, fmt.Errorf("could not parse yarn version: %w", err) + } + c, err := semver.NewConstraint(">=2.0.0") + if err != nil { + return false, fmt.Errorf("could not create constraint: %w", err) + } + + return c.Check(v), nil } func IsNMLinker(cwd string) (bool, error) { @@ -53,4 +53,3 @@ func GetPackageManagerAndVersion(packageManager string) (string, string) { return strings.Split(match, "@")[0], strings.Split(match, "@")[1] } - diff --git a/docs/pages/docs/reference/command-line-reference.mdx b/docs/pages/docs/reference/command-line-reference.mdx index 2030ca157ca46..2ab07a5a7e862 100644 --- a/docs/pages/docs/reference/command-line-reference.mdx +++ b/docs/pages/docs/reference/command-line-reference.mdx @@ -425,6 +425,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). @@ -438,6 +442,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.