Skip to content

Commit

Permalink
feat(cmd.Add): added a verbose flag to list specific validaton errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Osterbind committed Feb 7, 2018
1 parent 92bd873 commit 6b3de72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/qri-io/qri/core"
"github.com/qri-io/qri/repo"
"github.com/spf13/cobra"
"io/ioutil"
)

var (
Expand All @@ -17,6 +18,7 @@ var (
addDsName string
addDsURL string
addDsPassive bool
addDsVerbose bool
)

var datasetAddCmd = &cobra.Command{
Expand Down Expand Up @@ -117,6 +119,15 @@ 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 {
printWarning("Validation Error Detail:")
data, err := ioutil.ReadAll(dataFile)
ExitIfErr(err)
errorList := ref.Dataset.Structure.Schema.ValidateBytes(data)
for i, validationErr := range errorList {
printWarning(fmt.Sprintf("\t%d. %s", i+1, validationErr.Error()))
}
}
}

ref.Peername = "me"
Expand All @@ -128,5 +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")
RootCmd.AddCommand(datasetAddCmd)
}
2 changes: 1 addition & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestCommandsIntegration(t *testing.T) {
{"profile", "set", "-f" + profileDataFilepath},
{"config", "get"},
{"info"},
{"add", "--data=" + moviesFilePath, "me/movies"},
{"add", "-v", "--data=" + moviesFilePath, "me/movies"},
{"add", "--data=" + movies2FilePath, "me/movies2"},
{"list"},
{"save", "--data=" + movies2FilePath, "-t" + "commit_1", "me/movies"},
Expand Down

0 comments on commit 6b3de72

Please sign in to comment.