Skip to content

Commit

Permalink
feature(turbo): Porting turbo CLI to Rust (vercel#2382)
Browse files Browse the repository at this point in the history
Ported CLI parsing for link, unlink, login, and logout commands
  • Loading branch information
NicholasLYang authored Nov 15, 2022
1 parent 7fa8205 commit 658dcad
Show file tree
Hide file tree
Showing 31 changed files with 930 additions and 411 deletions.
51 changes: 48 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ INTEGRATION_TEST_FILES = $(shell find integration_tests -name "*.t")
integration-tests: $(CRAM_ENV)/bin/prysk turbo $(INTEGRATION_TEST_FILES) corepack shim
$(CRAM_ENV)/bin/prysk --shell=`which bash` $(INTEGRATION_TEST_FILES)

integration-tests-interactive: $(CRAM_ENV)/bin/prysk turbo $(INTEGRATION_TEST_FILES) corepack shim
$(CRAM_ENV)/bin/prysk --shell=`which bash` -i $(INTEGRATION_TEST_FILES)

# use target testbed-<some directory under integration_tests> to set up the testbed directory
.PHONY=testbed-%
testbed-%:
Expand Down
16 changes: 16 additions & 0 deletions cli/cmd/turbo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import "C"
import (
"encoding/json"
"fmt"
"os"
"unsafe"

"github.com/vercel/turbo/cli/internal/cmd"
"github.com/vercel/turbo/cli/internal/turbostate"
)

func main() {
Expand All @@ -19,6 +22,19 @@ func nativeRunWithArgs(argc C.int, argv **C.char) C.uint {
for i, arg := range unsafe.Slice(argv, arglen) {
args[i] = C.GoString(arg)
}

exitCode := cmd.RunWithArgs(args, turboVersion)
return C.uint(exitCode)
}

//export nativeRunWithTurboState
func nativeRunWithTurboState(turboStateString string) C.uint {
var turboState turbostate.CLIExecutionStateFromRust
err := json.Unmarshal([]byte(turboStateString), &turboState)
if err != nil {
fmt.Printf("Error unmarshalling turboState: %v\n Turbo state string: %v\n", err, turboStateString)
return 1
}
exitCode := cmd.RunWithTurboState(turboState, turboVersion)
return C.uint(exitCode)
}
6 changes: 6 additions & 0 deletions cli/integration_tests/link.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Setup
$ . ${TESTDIR}/setup.sh

Link Test Run
$ ${SHIM} link --__test-run
Link test run successful
6 changes: 6 additions & 0 deletions cli/integration_tests/login.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Setup
$ . ${TESTDIR}/setup.sh

Login Test Run
$ ${SHIM} login --__test-run
Login test run successful
4 changes: 2 additions & 2 deletions cli/integration_tests/logout.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Setup
$ . ${TESTDIR}/logged_in.sh

Logout while logged in
$ ${TURBO} logout
$ ${SHIM} logout
>>> Logged out

Logout while logged out
$ ${TURBO} logout
$ ${SHIM} logout
>>> Logged out

196 changes: 123 additions & 73 deletions cli/integration_tests/turbo_help.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ Test help flag
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching.
login Login to your Vercel account
logout Logout of your Vercel account
prune Prepare a subset of your monorepo.
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching

Flags:
--api string Override the endpoint for API calls
Expand Down Expand Up @@ -49,12 +45,8 @@ Test help flag
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching.
login Login to your Vercel account
logout Logout of your Vercel account
prune Prepare a subset of your monorepo.
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching

Flags:
--api string Override the endpoint for API calls
Expand All @@ -76,82 +68,140 @@ Test help flag

Test help flag for shim
$ ${SHIM} -h
turbo
The build system that makes ship happen

Usage: turbo [OPTIONS] [TASKS]... [COMMAND]

Commands:
bin Get the path to the Turbo binary
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching

Arguments:
[TASKS]...

Options:
-h, --help
--version
--api <API> Override the endpoint for API calls
--color Force color usage in the terminal
--cpuprofile <CPUPROFILE> Specify a file to save a cpu profile
--cwd <CWD> The directory in which to run turbo
--heap <HEAP> Specify a file to save a pprof heap profile
--login <LOGIN> Override the login endpoint
--no-color Suppress color usage in the terminal
--preflight When enabled, turbo will precede HTTP requests with an OPTIONS request for authorization
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v, --verbosity <VERBOSITY> verbosity
USAGE:
turbo [OPTIONS] [TASKS]... [SUBCOMMAND]

ARGS:
<TASKS>...

OPTIONS:
--api <API> Override the endpoint for API calls
--color Force color usage in the terminal
--cpu-profile <CPU_PROFILE> Specify a file to save a cpu profile
--cwd <CWD> The directory in which to run turbo
-h, --help
--heap <HEAP> Specify a file to save a pprof heap profile
--login <LOGIN> Override the login endpoint
--no-color Suppress color usage in the terminal
--preflight When enabled, turbo will precede HTTP requests with an
OPTIONS request for authorization
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v, --verbosity <VERBOSITY> verbosity
--version

SUBCOMMANDS:
bin Get the path to the Turbo binary
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote
Caching






$ ${SHIM} --help
turbo
The build system that makes ship happen

Usage: turbo [OPTIONS] [TASKS]... [COMMAND]

Commands:
bin Get the path to the Turbo binary
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote Caching

Arguments:
[TASKS]...

Options:
-h, --help
--version
--api <API> Override the endpoint for API calls
--color Force color usage in the terminal
--cpuprofile <CPUPROFILE> Specify a file to save a cpu profile
--cwd <CWD> The directory in which to run turbo
--heap <HEAP> Specify a file to save a pprof heap profile
--login <LOGIN> Override the login endpoint
--no-color Suppress color usage in the terminal
--preflight When enabled, turbo will precede HTTP requests with an OPTIONS request for authorization
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v, --verbosity <VERBOSITY> verbosity

USAGE:
turbo [OPTIONS] [TASKS]... [SUBCOMMAND]

ARGS:
<TASKS>...

OPTIONS:
--api <API> Override the endpoint for API calls
--color Force color usage in the terminal
--cpu-profile <CPU_PROFILE> Specify a file to save a cpu profile
--cwd <CWD> The directory in which to run turbo
-h, --help
--heap <HEAP> Specify a file to save a pprof heap profile
--login <LOGIN> Override the login endpoint
--no-color Suppress color usage in the terminal
--preflight When enabled, turbo will precede HTTP requests with an
OPTIONS request for authorization
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v, --verbosity <VERBOSITY> verbosity
--version

SUBCOMMANDS:
bin Get the path to the Turbo binary
completion Generate the autocompletion script for the specified shell
daemon Runs the Turborepo background daemon
help Help about any command
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
unlink Unlink the current directory from your Vercel organization and disable Remote
Caching

Test help flag for shim's link command
$ ${SHIM} link -h
link
Link your local directory to a Vercel organization and enable remote caching

USAGE:
link [OPTIONS]

OPTIONS:
-h, --help
help for link

--no-gitignore
Do not create or modify .gitignore (default false)

Test help flag for shim's unlink command
$ ${SHIM} unlink -h
unlink
Unlink the current directory from your Vercel organization and disable Remote Caching

USAGE:
unlink

OPTIONS:
-h, --help
Help flag

Test help flag for shim's login command
$ ${SHIM} login -h
login
Login to your Vercel account

USAGE:
login [OPTIONS]

OPTIONS:
-h, --help
Help flag

--sso-team <SSO_TEAM>


Test help flag for shim's logout command
$ ${SHIM} logout -h
logout
Logout to your Vercel account

USAGE:
logout

OPTIONS:
-h, --help
Help flag
Loading

0 comments on commit 658dcad

Please sign in to comment.