github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_simplefs_symlink.go (about)

     1  // Copyright 2018 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package client
     5  
     6  import (
     7  	"errors"
     8  
     9  	"golang.org/x/net/context"
    10  
    11  	"github.com/keybase/cli"
    12  	"github.com/keybase/client/go/libcmdline"
    13  	"github.com/keybase/client/go/libkb"
    14  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    15  )
    16  
    17  // CmdSimpleFSSymlink is the 'fs ln' command.
    18  type CmdSimpleFSSymlink struct {
    19  	libkb.Contextified
    20  	target string
    21  	link   keybase1.Path
    22  }
    23  
    24  // NewCmdSimpleFSSymlink creates a new cli.Command.
    25  func NewCmdSimpleFSSymlink(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    26  	return cli.Command{
    27  		Name:         "ln",
    28  		ArgumentHelp: "<target> <link>",
    29  		Usage:        "create a symlink from link to target",
    30  		Action: func(c *cli.Context) {
    31  			cl.ChooseCommand(&CmdSimpleFSSymlink{Contextified: libkb.NewContextified(g)}, "ln", c)
    32  			cl.SetNoStandalone()
    33  		},
    34  	}
    35  }
    36  
    37  // Run runs the command in client/server mode.
    38  func (c *CmdSimpleFSSymlink) Run() error {
    39  	cli, err := GetSimpleFSClient(c.G())
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	ctx := context.TODO()
    45  	arg := keybase1.SimpleFSSymlinkArg{
    46  		Target: c.target,
    47  		Link:   c.link,
    48  	}
    49  
    50  	return cli.SimpleFSSymlink(ctx, arg)
    51  }
    52  
    53  // ParseArgv gets the required path argument for this command.
    54  func (c *CmdSimpleFSSymlink) ParseArgv(ctx *cli.Context) error {
    55  	nargs := len(ctx.Args())
    56  	if nargs != 2 {
    57  		return errors.New("ln requires exactly 2 arguments")
    58  	}
    59  	targetStr := ctx.Args()[0]
    60  	linkStr := ctx.Args()[1]
    61  
    62  	rev := int64(0)
    63  	timeString := ""
    64  	relTimeString := ""
    65  	linkPath, err := makeSimpleFSPathWithArchiveParams(
    66  		linkStr, rev, timeString, relTimeString)
    67  	if err != nil {
    68  		return err
    69  	}
    70  
    71  	linkPathType, err := linkPath.PathType()
    72  	if err != nil {
    73  		return err
    74  	}
    75  	if linkPathType != keybase1.PathType_KBFS {
    76  		return errors.New("keybase fs ln: link must be a KBFS path")
    77  	}
    78  	c.link = linkPath
    79  
    80  	c.target = targetStr
    81  
    82  	return err
    83  }
    84  
    85  // GetUsage says what this command needs to operate.
    86  func (c *CmdSimpleFSSymlink) GetUsage() libkb.Usage {
    87  	return libkb.Usage{
    88  		Config:    true,
    89  		KbKeyring: true,
    90  		API:       true,
    91  	}
    92  }