Add -r for rm and -p for mkdir
This commit is contained in:
parent
6f87980d4b
commit
4efa4380c4
20
api/fs.go
20
api/fs.go
@ -2,6 +2,16 @@ package api
|
||||
|
||||
import "context"
|
||||
|
||||
func (c *Client) RemoveAll(ctx context.Context, paths ...string) error {
|
||||
return c.client.Call(
|
||||
ctx,
|
||||
"FS",
|
||||
"RemoveAll",
|
||||
paths,
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) Remove(ctx context.Context, paths ...string) error {
|
||||
return c.client.Call(
|
||||
ctx,
|
||||
@ -22,6 +32,16 @@ func (c *Client) Rename(ctx context.Context, old, new string) error {
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) MkdirAll(ctx context.Context, paths ...string) error {
|
||||
return c.client.Call(
|
||||
ctx,
|
||||
"FS",
|
||||
"MkdirAll",
|
||||
paths,
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) Mkdir(ctx context.Context, paths ...string) error {
|
||||
return c.client.Call(
|
||||
ctx,
|
||||
|
@ -34,7 +34,12 @@ func fsMkdir(c *cli.Context) error {
|
||||
return cli.Exit("Command mkdir requires one or more arguments", 1)
|
||||
}
|
||||
|
||||
err := client.Mkdir(c.Context, c.Args().Slice()...)
|
||||
var err error
|
||||
if c.Bool("parents") {
|
||||
err = client.MkdirAll(c.Context, c.Args().Slice()...)
|
||||
} else {
|
||||
err = client.Mkdir(c.Context, c.Args().Slice()...)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -109,7 +114,12 @@ func fsRemove(c *cli.Context) error {
|
||||
return cli.Exit("Command remove requires one or more arguments", 1)
|
||||
}
|
||||
|
||||
err := client.Remove(c.Context, c.Args().Slice()...)
|
||||
var err error
|
||||
if c.Bool("recursive") {
|
||||
err = client.RemoveAll(c.Context, c.Args().Slice()...)
|
||||
} else {
|
||||
err = client.Remove(c.Context, c.Args().Slice()...)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -77,6 +77,13 @@ func main() {
|
||||
Action: fsList,
|
||||
},
|
||||
{
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "parents",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "Make parent directories if needed, no error if already existing",
|
||||
},
|
||||
},
|
||||
Name: "mkdir",
|
||||
ArgsUsage: "<paths...>",
|
||||
Usage: "Create new directories",
|
||||
@ -97,6 +104,13 @@ func main() {
|
||||
Action: fsRead,
|
||||
},
|
||||
{
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "recursive",
|
||||
Aliases: []string{"r", "R"},
|
||||
Usage: "Remove directories and their contents recursively",
|
||||
},
|
||||
},
|
||||
Name: "remove",
|
||||
ArgsUsage: "<paths...>",
|
||||
Aliases: []string{"rm"},
|
||||
|
22
socket.go
22
socket.go
@ -293,6 +293,17 @@ type FS struct {
|
||||
fs *blefs.FS
|
||||
}
|
||||
|
||||
func (fs *FS) RemoveAll(_ *server.Context, paths []string) error {
|
||||
fs.updateFS()
|
||||
for _, path := range paths {
|
||||
err := fs.fs.RemoveAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *FS) Remove(_ *server.Context, paths []string) error {
|
||||
fs.updateFS()
|
||||
for _, path := range paths {
|
||||
@ -309,6 +320,17 @@ func (fs *FS) Rename(_ *server.Context, paths [2]string) error {
|
||||
return fs.fs.Rename(paths[0], paths[1])
|
||||
}
|
||||
|
||||
func (fs *FS) MkdirAll(_ *server.Context, paths []string) error {
|
||||
fs.updateFS()
|
||||
for _, path := range paths {
|
||||
err := fs.fs.MkdirAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *FS) Mkdir(_ *server.Context, paths []string) error {
|
||||
fs.updateFS()
|
||||
for _, path := range paths {
|
||||
|
Loading…
Reference in New Issue
Block a user