cmd/tailscale/cli: rename share command to drive

Updates tailscale/corp#16827

Signed-off-by: Percy Wegmann <percy@tailscale.com>
pull/11364/head
Percy Wegmann 2 months ago committed by Percy Wegmann
parent b4ba492701
commit 1e0ebc6c6d

@ -149,8 +149,8 @@ change in the future.
switch { switch {
case slices.Contains(args, "debug"): case slices.Contains(args, "debug"):
rootCmd.Subcommands = append(rootCmd.Subcommands, debugCmd) rootCmd.Subcommands = append(rootCmd.Subcommands, debugCmd)
case slices.Contains(args, "share"): case slices.Contains(args, "drive"):
rootCmd.Subcommands = append(rootCmd.Subcommands, shareCmd) rootCmd.Subcommands = append(rootCmd.Subcommands, driveCmd)
} }
if runtime.GOOS == "linux" && distro.Get() == distro.Synology { if runtime.GOOS == "linux" && distro.Get() == distro.Synology {
rootCmd.Subcommands = append(rootCmd.Subcommands, configureHostCmd) rootCmd.Subcommands = append(rootCmd.Subcommands, configureHostCmd)

@ -14,57 +14,58 @@ import (
) )
const ( const (
shareSetUsage = "share set <name> <path>" driveShareUsage = "drive share <name> <path>"
shareRenameUsage = "share rename <oldname> <newname>" driveRenameUsage = "drive rename <oldname> <newname>"
shareRemoveUsage = "share remove <name>" driveUnshareUsage = "drive unshare <name>"
shareListUsage = "share list" driveListUsage = "drive list"
) )
var shareCmd = &ffcli.Command{ var driveCmd = &ffcli.Command{
Name: "share", Name: "drive",
ShortHelp: "Share a directory with your tailnet", ShortHelp: "Share a directory with your tailnet",
ShortUsage: strings.Join([]string{ ShortUsage: strings.Join([]string{
shareSetUsage, driveShareUsage,
shareRemoveUsage, driveRenameUsage,
shareListUsage, driveUnshareUsage,
driveListUsage,
}, "\n "), }, "\n "),
LongHelp: buildShareLongHelp(), LongHelp: buildShareLongHelp(),
UsageFunc: usageFuncNoDefaultValues, UsageFunc: usageFuncNoDefaultValues,
Subcommands: []*ffcli.Command{ Subcommands: []*ffcli.Command{
{ {
Name: "set", Name: "share",
Exec: runShareSet, Exec: runDriveShare,
ShortHelp: "[ALPHA] set a share", ShortHelp: "[ALPHA] create or modify a share",
UsageFunc: usageFunc, UsageFunc: usageFunc,
}, },
{ {
Name: "rename", Name: "rename",
ShortHelp: "[ALPHA] rename a share", ShortHelp: "[ALPHA] rename a share",
Exec: runShareRename, Exec: runDriveRename,
UsageFunc: usageFunc, UsageFunc: usageFunc,
}, },
{ {
Name: "remove", Name: "unshare",
ShortHelp: "[ALPHA] remove a share", ShortHelp: "[ALPHA] remove a share",
Exec: runShareRemove, Exec: runDriveUnshare,
UsageFunc: usageFunc, UsageFunc: usageFunc,
}, },
{ {
Name: "list", Name: "list",
ShortHelp: "[ALPHA] list current shares", ShortHelp: "[ALPHA] list current shares",
Exec: runShareList, Exec: runDriveList,
UsageFunc: usageFunc, UsageFunc: usageFunc,
}, },
}, },
Exec: func(context.Context, []string) error { Exec: func(context.Context, []string) error {
return errors.New("share subcommand required; run 'tailscale share -h' for details") return errors.New("drive subcommand required; run 'tailscale drive -h' for details")
}, },
} }
// runShareSet is the entry point for the "tailscale share set" command. // runDriveShare is the entry point for the "tailscale drive share" command.
func runShareSet(ctx context.Context, args []string) error { func runDriveShare(ctx context.Context, args []string) error {
if len(args) != 2 { if len(args) != 2 {
return fmt.Errorf("usage: tailscale %v", shareSetUsage) return fmt.Errorf("usage: tailscale %v", driveShareUsage)
} }
name, path := args[0], args[1] name, path := args[0], args[1]
@ -74,29 +75,29 @@ func runShareSet(ctx context.Context, args []string) error {
Path: path, Path: path,
}) })
if err == nil { if err == nil {
fmt.Printf("Set share %q at %q\n", name, path) fmt.Printf("Sharing %q as %q\n", path, name)
} }
return err return err
} }
// runShareRemove is the entry point for the "tailscale share remove" command. // runDriveUnshare is the entry point for the "tailscale drive unshare" command.
func runShareRemove(ctx context.Context, args []string) error { func runDriveUnshare(ctx context.Context, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return fmt.Errorf("usage: tailscale %v", shareRemoveUsage) return fmt.Errorf("usage: tailscale %v", driveUnshareUsage)
} }
name := args[0] name := args[0]
err := localClient.DriveShareRemove(ctx, name) err := localClient.DriveShareRemove(ctx, name)
if err == nil { if err == nil {
fmt.Printf("Removed share %q\n", name) fmt.Printf("No longer sharing %q\n", name)
} }
return err return err
} }
// runShareRename is the entry point for the "tailscale share rename" command. // runDriveRename is the entry point for the "tailscale drive rename" command.
func runShareRename(ctx context.Context, args []string) error { func runDriveRename(ctx context.Context, args []string) error {
if len(args) != 2 { if len(args) != 2 {
return fmt.Errorf("usage: tailscale %v", shareRenameUsage) return fmt.Errorf("usage: tailscale %v", driveRenameUsage)
} }
oldName := args[0] oldName := args[0]
newName := args[1] newName := args[1]
@ -108,10 +109,10 @@ func runShareRename(ctx context.Context, args []string) error {
return err return err
} }
// runShareList is the entry point for the "tailscale share list" command. // runDriveList is the entry point for the "tailscale drive list" command.
func runShareList(ctx context.Context, args []string) error { func runDriveList(ctx context.Context, args []string) error {
if len(args) != 0 { if len(args) != 0 {
return fmt.Errorf("usage: tailscale %v", shareListUsage) return fmt.Errorf("usage: tailscale %v", driveListUsage)
} }
shares, err := localClient.DriveShareList(ctx) shares, err := localClient.DriveShareList(ctx)
@ -151,7 +152,7 @@ func buildShareLongHelp() string {
return fmt.Sprintf(shareLongHelpBase, longHelpAs) return fmt.Sprintf(shareLongHelpBase, longHelpAs)
} }
var shareLongHelpBase = `Tailscale share allows you to share directories with other machines on your tailnet. var shareLongHelpBase = `Taildrive allows you to share directories with other machines on your tailnet.
In order to share folders, your node needs to have the node attribute "drive:share". In order to share folders, your node needs to have the node attribute "drive:share".
@ -170,7 +171,7 @@ For example, to enable sharing and accessing shares for all member nodes:
Each share is identified by a name and points to a directory at a specific path. For example, to share the path /Users/me/Documents under the name "docs", you would run: Each share is identified by a name and points to a directory at a specific path. For example, to share the path /Users/me/Documents under the name "docs", you would run:
$ tailscale share set docs /Users/me/Documents $ tailscale drive share docs /Users/me/Documents
Note that the system forces share names to lowercase to avoid problems with clients that don't support case-sensitive filenames. Note that the system forces share names to lowercase to avoid problems with clients that don't support case-sensitive filenames.
@ -226,18 +227,18 @@ Whenever either you or anyone in the group "home" connects to the share, they co
You can rename shares, for example you could rename the above share by running: You can rename shares, for example you could rename the above share by running:
$ tailscale share rename docs newdocs $ tailscale drive rename docs newdocs
You can remove shares by name, for example you could remove the above share by running: You can remove shares by name, for example you could remove the above share by running:
$ tailscale share remove newdocs $ tailscale drive unshare newdocs
You can get a list of currently published shares by running: You can get a list of currently published shares by running:
$ tailscale share list` $ tailscale drive list`
var shareLongHelpAs = ` var shareLongHelpAs = `
If you want a share to be accessed as a different user, you can use sudo to accomplish this. For example, to create the aforementioned share as "theuser", you could run: If you want a share to be accessed as a different user, you can use sudo to accomplish this. For example, to create the aforementioned share as "theuser", you could run:
$ sudo -u theuser tailscale share set docs /Users/theuser/Documents` $ sudo -u theuser tailscale drive share docs /Users/theuser/Documents`

Loading…
Cancel
Save