Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 114ebf8

Browse files
authored
Merge pull request #217 from secrethub/feature/mkdir-recursive
Add --parents flag to mkdir to recursively create directories
2 parents 5748439 + 56977a1 commit 114ebf8

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
7272
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
7373
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
7474
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
75+
github.com/secrethub/secrethub-go v0.23.0 h1:6NzVGcAJDXeORUc2uZyuaYRCXCawmOKYvhNPP3ASNSM=
76+
github.com/secrethub/secrethub-go v0.23.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
77+
github.com/secrethub/secrethub-go v0.23.1-0.20191114120141-797aba99690c h1:PJMNIc0Bq02IeCyZKMTxT8TaUDISwX0IAdbgOsfbdWQ=
78+
github.com/secrethub/secrethub-go v0.23.1-0.20191114120141-797aba99690c/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
7579
github.com/secrethub/secrethub-go v0.23.1-0.20191202112815-8e4536fffb73 h1:TChbs2D26POGnhQ87QWCg17b3PQukTHPaxgGxAxxTgU=
7680
github.com/secrethub/secrethub-go v0.23.1-0.20191202112815-8e4536fffb73/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
7781
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=

internals/secrethub/mkdir.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
type MkDirCommand struct {
1919
io ui.IO
2020
path api.DirPath
21+
parents bool
2122
newClient newClientFunc
2223
}
2324

@@ -33,6 +34,7 @@ func NewMkDirCommand(io ui.IO, newClient newClientFunc) *MkDirCommand {
3334
func (cmd *MkDirCommand) Register(r command.Registerer) {
3435
clause := r.Command("mkdir", "Create a new directory.")
3536
clause.Arg("dir-path", "The path to the directory").Required().PlaceHolder(dirPathPlaceHolder).SetValue(&cmd.path)
37+
clause.Flag("parents", "Create parent directories if needed. Does not error when directories already exist.").BoolVar(&cmd.parents)
3638

3739
command.BindAction(clause, cmd.Run)
3840
}
@@ -48,9 +50,16 @@ func (cmd *MkDirCommand) Run() error {
4850
return err
4951
}
5052

51-
_, err = client.Dirs().Create(cmd.path.Value())
52-
if err != nil {
53-
return err
53+
if cmd.parents {
54+
err = client.Dirs().CreateAll(cmd.path.Value())
55+
if err != nil {
56+
return err
57+
}
58+
} else {
59+
_, err = client.Dirs().Create(cmd.path.Value())
60+
if err != nil {
61+
return err
62+
}
5463
}
5564

5665
fmt.Fprintf(cmd.io.Stdout(), "Created a new directory at %s\n", cmd.path)

0 commit comments

Comments
 (0)