11package main
22
33import (
4+ "errors"
45 "fmt"
56 "io"
67 "os/exec"
@@ -13,6 +14,8 @@ import (
1314 "github.com/steveyegge/wasteland/internal/style"
1415)
1516
17+ const defaultUpstream = "hop/wl-commons"
18+
1619func newJoinCmd (stdout , stderr io.Writer ) * cobra.Command {
1720 var (
1821 handle string
@@ -24,40 +27,39 @@ func newJoinCmd(stdout, stderr io.Writer) *cobra.Command {
2427 )
2528
2629 cmd := & cobra.Command {
27- Use : "join < upstream> " ,
30+ Use : "join [ upstream] " ,
2831 Short : "Join a wasteland by forking its commons" ,
2932 Long : `Join a wasteland community by forking its shared commons database.
3033
3134This command:
32- 1. Forks the upstream commons to your org
35+ 1. Forks the upstream commons to your org (or checks that your fork exists)
3336 2. Clones the fork locally
3437 3. Registers your rig in the rigs table
3538 4. Pushes the registration to your fork
3639 5. Saves wasteland configuration locally
3740
38- The upstream argument is an org/database path like 'steveyegge/wl-commons'.
39- You can join multiple wastelands simultaneously.
40-
41- DoltHub mode (default):
42- Requires DOLTHUB_TOKEN and DOLTHUB_ORG (or --fork-org).
43- Forks and clones via DoltHub.
44-
45- Offline file mode (--remote-base):
46- Uses file:// dolt remotes. No DoltHub credentials needed.
47- Requires --fork-org (or DOLTHUB_ORG).
41+ The upstream argument defaults to 'hop/wl-commons' (the main wasteland).
42+ You can specify a different org/database path to join other wastelands.
4843
49- Git remote mode (--git-remote):
50- Uses bare git repos as dolt remotes. No DoltHub credentials needed.
51- Requires --fork-org (or DOLTHUB_ORG).
44+ Getting started:
45+ 1. Sign up at https://www.dolthub.com
46+ 2. Fork the commons: https://www.dolthub.com/repositories/hop/wl-commons
47+ 3. Create an API token at https://www.dolthub.com/settings/tokens
48+ 4. Set environment variables:
49+ export DOLTHUB_TOKEN=<your-api-token>
50+ export DOLTHUB_ORG=<your-dolthub-username>
51+ 5. Run: wl join
5252
5353Examples:
54- wl join steveyegge/wl-commons
55- wl join steveyegge/wl-commons --handle my-rig
56- wl join test-org/wl-commons --remote-base /tmp/remotes --fork-org my-fork
57- wl join test-org/wl-commons --git-remote /tmp/git-remotes --fork-org my-fork` ,
58- Args : cobra .ExactArgs (1 ),
54+ wl join
55+ wl join hop/wl-commons --handle my-rig` ,
56+ Args : cobra .MaximumNArgs (1 ),
5957 RunE : func (_ * cobra.Command , args []string ) error {
60- return runJoin (stdout , stderr , args [0 ], handle , displayName , email , forkOrg , remoteBase , gitRemote )
58+ upstream := defaultUpstream
59+ if len (args ) > 0 {
60+ upstream = args [0 ]
61+ }
62+ return runJoin (stdout , stderr , upstream , handle , displayName , email , forkOrg , remoteBase , gitRemote )
6163 },
6264 }
6365
@@ -150,6 +152,11 @@ func runJoin(stdout, stderr io.Writer, upstream, handle, displayName, email, for
150152 fmt .Fprintf (stdout , "Joining wasteland %s (fork to %s/%s)...\n " , upstream , forkOrg , dbName )
151153 cfg , err := svc .Join (upstream , forkOrg , handle , displayName , email , wlVersion )
152154 if err != nil {
155+ var forkErr * remote.ForkRequiredError
156+ if errors .As (err , & forkErr ) {
157+ printForkInstructions (stdout , forkErr )
158+ return errExit
159+ }
153160 fmt .Fprintf (stderr , "wl join: %v\n " , err )
154161 return errExit
155162 }
@@ -162,6 +169,15 @@ func runJoin(stdout, stderr io.Writer, upstream, handle, displayName, email, for
162169 return nil
163170}
164171
172+ func printForkInstructions (w io.Writer , err * remote.ForkRequiredError ) {
173+ fmt .Fprintf (w , "\n %s Fork required\n \n " , style .Bold .Render ("!" ))
174+ fmt .Fprintf (w , " To join this wasteland, fork the commons on DoltHub:\n \n " )
175+ fmt .Fprintf (w , " 1. Go to %s\n " , style .Bold .Render (err .ForkURL ()))
176+ fmt .Fprintf (w , " 2. Click %s (top right)\n " , style .Bold .Render ("Fork" ))
177+ fmt .Fprintf (w , " 3. Select your organization: %s\n " , style .Bold .Render (err .ForkOrg ))
178+ fmt .Fprintf (w , " 4. Rerun: %s\n " , style .Bold .Render ("wl join" ))
179+ }
180+
165181// gitConfigValue retrieves a value from git config. Returns empty string on error.
166182func gitConfigValue (key string ) string {
167183 cmd := exec .Command ("git" , "config" , key )
0 commit comments