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"
|
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 {
|
func (c *Client) Remove(ctx context.Context, paths ...string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
ctx,
|
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 {
|
func (c *Client) Mkdir(ctx context.Context, paths ...string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -34,7 +34,12 @@ func fsMkdir(c *cli.Context) error {
|
|||||||
return cli.Exit("Command mkdir requires one or more arguments", 1)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -109,7 +114,12 @@ func fsRemove(c *cli.Context) error {
|
|||||||
return cli.Exit("Command remove requires one or more arguments", 1)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,13 @@ func main() {
|
|||||||
Action: fsList,
|
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",
|
Name: "mkdir",
|
||||||
ArgsUsage: "<paths...>",
|
ArgsUsage: "<paths...>",
|
||||||
Usage: "Create new directories",
|
Usage: "Create new directories",
|
||||||
@ -97,6 +104,13 @@ func main() {
|
|||||||
Action: fsRead,
|
Action: fsRead,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "recursive",
|
||||||
|
Aliases: []string{"r", "R"},
|
||||||
|
Usage: "Remove directories and their contents recursively",
|
||||||
|
},
|
||||||
|
},
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
ArgsUsage: "<paths...>",
|
ArgsUsage: "<paths...>",
|
||||||
Aliases: []string{"rm"},
|
Aliases: []string{"rm"},
|
||||||
|
22
socket.go
22
socket.go
@ -293,6 +293,17 @@ type FS struct {
|
|||||||
fs *blefs.FS
|
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 {
|
func (fs *FS) Remove(_ *server.Context, paths []string) error {
|
||||||
fs.updateFS()
|
fs.updateFS()
|
||||||
for _, path := range paths {
|
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])
|
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 {
|
func (fs *FS) Mkdir(_ *server.Context, paths []string) error {
|
||||||
fs.updateFS()
|
fs.updateFS()
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
|
Loading…
Reference in New Issue
Block a user