Skip to content

Commit

Permalink
Added create dir for edit when it doesnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Persson committed Feb 16, 2016
1 parent 99e89d9 commit 9eeed3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/github.com/mickep76/etcdtool/command/edit_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"strings"

"github.com/codegangsta/cli"
"github.com/coreos/etcd/client"
"github.com/mickep76/iodatafmt"
"golang.org/x/net/context"
)

// NewEditCommand sets data from input.
Expand Down Expand Up @@ -75,6 +77,24 @@ func editCommandFunc(c *cli.Context) {
// Temporary file append file type to support syntax highlighting
tmpfile := c.String("tmp-file") + "." + strings.ToLower(c.String("format"))

// Check if dir exists and is a directory.
exists, err := dirExists(dir, c, ki)
if err != nil {
fatal(err.Error())
}

if !exists {
if askYesNo(fmt.Sprintf("Dir. doesn't exist: %s create it", dir)) {
// Create dir.
if _, err := ki.Set(context.TODO(), dir, "", &client.SetOptions{Dir: true}); err != nil {
fatal(err.Error())
}
exists = true
} else {
os.Exit(1)
}
}

// If file exist's resume editing?
if _, err := os.Stat(tmpfile); os.IsNotExist(err) {
// Export to file.
Expand Down
2 changes: 1 addition & 1 deletion src/github.com/mickep76/etcdtool/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

// Version for app.
const Version = "3.1"
const Version = "3.2"

0 comments on commit 9eeed3c

Please sign in to comment.