Skip to content

Commit

Permalink
feat(cmd.Save): added validation warnings/options to match cmd.Add
Browse files Browse the repository at this point in the history
also updated `--verbose` flag to `--show-validation` to reserve
'verbose' for broader use
  • Loading branch information
Thomas Osterbind committed Feb 7, 2018
1 parent 6b3de72 commit e77176a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
addDsName string
addDsURL string
addDsPassive bool
addDsVerbose bool
addDsShowValidation bool
)

var datasetAddCmd = &cobra.Command{
Expand Down Expand Up @@ -119,7 +119,7 @@ func initDataset(name *repo.DatasetRef) {
ExitIfErr(err)
if ref.Dataset.Structure.ErrCount > 0 {
printWarning(fmt.Sprintf("this dataset has %d validation errors", ref.Dataset.Structure.ErrCount))
if addDsVerbose {
if addDsShowValidation {
printWarning("Validation Error Detail:")
data, err := ioutil.ReadAll(dataFile)
ExitIfErr(err)
Expand All @@ -139,6 +139,6 @@ func init() {
datasetAddCmd.Flags().StringVarP(&addDsFilepath, "data", "", "", "data file to initialize from")
datasetAddCmd.Flags().StringVarP(&addDsStructureFilepath, "structure", "", "", "dataset structure JSON file")
datasetAddCmd.Flags().StringVarP(&addDsMetaFilepath, "meta", "", "", "dataset metadata JSON file")
datasetAddCmd.Flags().BoolVarP(&addDsVerbose, "verbose", "v", false, "display verbose validation error listing")
datasetAddCmd.Flags().BoolVarP(&addDsShowValidation, "show-validation", "s", false, "display a list of validation errors upon adding")
RootCmd.AddCommand(datasetAddCmd)
}
4 changes: 2 additions & 2 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func TestCommandsIntegration(t *testing.T) {
{"profile", "set", "-f" + profileDataFilepath},
{"config", "get"},
{"info"},
{"add", "-v", "--data=" + moviesFilePath, "me/movies"},
{"add", "-s", "--data=" + moviesFilePath, "me/movies"},
{"add", "--data=" + movies2FilePath, "me/movies2"},
{"list"},
{"save", "--data=" + movies2FilePath, "-t" + "commit_1", "me/movies"},
{"save", "-s", "--data=" + movies2FilePath, "-t" + "commit_1", "me/movies"},
{"log", "me/movies"},
{"diff", "me/movies", "me/movies2", "-d", "detail"},
{"export", "--dataset", "me/movies", "-o" + path},
Expand Down
30 changes: 22 additions & 8 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import (
"github.com/qri-io/qri/core"
"github.com/qri-io/qri/repo"
"github.com/spf13/cobra"
"io/ioutil"
)

var (
saveDataFile string
saveMetaFile string
saveStructureFile string
saveTitle string
saveMessage string
savePassive bool
saveRescursive bool
saveDataFile string
saveMetaFile string
saveStructureFile string
saveTitle string
saveMessage string
savePassive bool
saveRescursive bool
saveShowValidation bool
)

// saveCmd represents the save command
Expand Down Expand Up @@ -115,6 +117,18 @@ collaboration are in the works. Sit tight sportsfans.`,
err = req.Save(save, res)
ExitIfErr(err)
printSuccess("dataset saved: %s", res)
if res.Dataset.Structure.ErrCount > 0 {
printWarning(fmt.Sprintf("this dataset has %d validation errors", res.Dataset.Structure.ErrCount))
if saveShowValidation {
printWarning("Validation Error Detail:")
data, err := ioutil.ReadAll(dataFile)
ExitIfErr(err)
errorList := res.Dataset.Structure.Schema.ValidateBytes(data)
for i, validationErr := range errorList {
printWarning(fmt.Sprintf("\t%d. %s", i+1, validationErr.Error()))
}
}
}
},
}

Expand All @@ -124,6 +138,6 @@ func init() {
saveCmd.Flags().StringVarP(&saveStructureFile, "structure", "", "", "structure.json file")
saveCmd.Flags().StringVarP(&saveTitle, "title", "t", "", "title of commit message for save")
saveCmd.Flags().StringVarP(&saveMessage, "message", "m", "", "commit message for save")

saveCmd.Flags().BoolVarP(&saveShowValidation, "show-validation", "s", false, "display a list of validation errors upon adding")
RootCmd.AddCommand(saveCmd)
}

0 comments on commit e77176a

Please sign in to comment.