diff --git a/cmd/cmd.go b/cmd/cmd.go index 095174f75..3e1b31eb3 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "path/filepath" "runtime" "github.com/spf13/viper" @@ -49,3 +50,17 @@ func userHomeDir() string { } return os.Getenv("HOME") } + +func loadFileIfPath(path string, f *os.File) (err error) { + if path == "" { + return nil + } + + filepath, err := filepath.Abs(path) + if err != nil { + return err + } + + f, err = os.Open(filepath) + return +} diff --git a/cmd/config.go b/cmd/config.go index 67abeb5c1..8fd68c46b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( @@ -24,8 +10,7 @@ import ( ) type Config struct { - // Remotes []*Remote `json:"remotes"` - // Folders []*Folder `json:"folders"` + Bootstrap []string } // configCmd represents the config command diff --git a/cmd/dataset.go b/cmd/dataset.go index 437a3efdc..41d9f6fb7 100644 --- a/cmd/dataset.go +++ b/cmd/dataset.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( @@ -54,8 +40,7 @@ var datasetInfoCmd = &cobra.Command{ if len(args) != 1 { ErrExit(fmt.Errorf("wrong number of arguments. expected qri info [dataset_name]")) } - ds, err := GetIpfsFilestore(true) - ExitIfErr(err) + ds := GetIpfsFilestore(true) path, err := GetRepo(true).GetPath(args[0]) ExitIfErr(err) @@ -83,8 +68,7 @@ var datasetAddCmd = &cobra.Command{ } r := GetRepo(false) - fs, err := GetIpfsFilestore(false) - ExitIfErr(err) + fs := GetIpfsFilestore(false) name := cmd.Flag("name").Value.String() if name == "" { @@ -94,7 +78,7 @@ var datasetAddCmd = &cobra.Command{ root := strings.TrimSuffix(args[0], "/"+dsfs.PackageFileDataset.String()) PrintInfo("downloading %s...", root) - _, err = fs.Fetch(cafs.SourceAny, datastore.NewKey(root)) + _, err := fs.Fetch(cafs.SourceAny, datastore.NewKey(root)) ExitIfErr(err) err = fs.Pin(datastore.NewKey(root), true) @@ -118,8 +102,7 @@ var datasetRemoveCmd = &cobra.Command{ } name := args[0] - fs, err := GetIpfsFilestore(false) - ExitIfErr(err) + fs := GetIpfsFilestore(false) r := GetRepo(false) path, err := r.GetPath(name) diff --git a/cmd/export.go b/cmd/export.go index 8f5dae887..90957c830 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -1,26 +1,15 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( "fmt" - "github.com/qri-io/dataset/dsfs" - "github.com/qri-io/dataset/dsutil" + "github.com/ipfs/go-datastore" "io" "os" + "github.com/qri-io/dataset/dsfs" + "github.com/qri-io/dataset/dsutil" + "github.com/qri-io/qri/core" + "github.com/qri-io/qri/repo" "github.com/spf13/cobra" ) @@ -41,12 +30,22 @@ var exportCmd = &cobra.Command{ } r := GetRepo(false) - store, err := GetIpfsFilestore(false) - ExitIfErr(err) + store := GetIpfsFilestore(false) + + req := core.NewDatasetRequests(store, r) - ds, err := FindDataset(r, store, args[0]) + p := &core.GetDatasetParams{ + Name: args[0], + Path: datastore.NewKey(args[0]), + } + res := &repo.DatasetRef{} + err := req.Get(p, res) ExitIfErr(err) + ds := res.Dataset + + // ds, err := FindDataset(r, store, args[0]) + if cmd.Flag("data-only").Value.String() == "true" { src, err := dsfs.LoadData(store, ds) ExitIfErr(err) diff --git a/cmd/info.go b/cmd/info.go index 6aff85dca..7138a462d 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/init-ipfs.go b/cmd/init-ipfs.go index fad725e73..1cbc9d3e2 100644 --- a/cmd/init-ipfs.go +++ b/cmd/init-ipfs.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/init.go b/cmd/init.go index b12faa587..43022cb73 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( @@ -43,29 +29,17 @@ var initCmd = &cobra.Command{ if initFile == "" && initUrl == "" { ErrExit(fmt.Errorf("please provide either a file or a url argument")) - } - - if initName == "" { + } else if initName == "" { ErrExit(fmt.Errorf("please provide a --name")) } - if initFile != "" { - filepath, err := filepath.Abs(initFile) - ExitIfErr(err) - dataFile, err = os.Open(filepath) - ExitIfErr(err) - } - - if initMetaFile != "" { - filepath, err := filepath.Abs(initMetaFile) - ExitIfErr(err) - metaFile, err = os.Open(filepath) - ExitIfErr(err) - } + err := loadFileIfPath(initFile, dataFile) + ExitIfErr(err) + err = loadFileIfPath(initMetaFile, metaFile) + ExitIfErr(err) r := GetRepo(false) - store, err := GetIpfsFilestore(false) - ExitIfErr(err) + store := GetIpfsFilestore(false) req := core.NewDatasetRequests(store, r) p := &core.InitDatasetParams{ @@ -74,7 +48,8 @@ var initCmd = &cobra.Command{ DataFilename: filepath.Base(initFile), } - // this is because passing nil to interfaces is bad: https://golang.org/doc/faq#nil_error + // this is because passing nil to interfaces is bad + // see: https://golang.org/doc/faq#nil_error if dataFile != nil { p.Data = dataFile } diff --git a/cmd/input.go b/cmd/input.go deleted file mode 100644 index a8d7f25f7..000000000 --- a/cmd/input.go +++ /dev/null @@ -1,22 +0,0 @@ -package cmd - -import ( - "fmt" - "strings" -) - -func prompt(msg string) string { - var input string - printPrompt(msg) - fmt.Scanln(&input) - return strings.TrimSpace(input) -} - -func InputText(message, defaultText string) string { - if message == "" { - message = "enter text:" - } - input := prompt(fmt.Sprintf("%s [%s]: ", message, defaultText)) - - return input -} diff --git a/cmd/ipfs.go b/cmd/ipfs.go deleted file mode 100644 index 9f92689da..000000000 --- a/cmd/ipfs.go +++ /dev/null @@ -1,13 +0,0 @@ -package cmd - -import ( - ipfs "github.com/qri-io/cafs/ipfs" - "github.com/spf13/viper" -) - -func GetIpfsFilestore(online bool) (*ipfs.Filestore, error) { - return ipfs.NewFilestore(func(cfg *ipfs.StoreCfg) { - cfg.FsRepoPath = viper.GetString(IpfsFsPath) - cfg.Online = online - }) -} diff --git a/cmd/peer.go b/cmd/peer.go index 7ec77cf84..d7ccfd5be 100644 --- a/cmd/peer.go +++ b/cmd/peer.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/print.go b/cmd/print.go index f4379c51e..9a1030db1 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/qri-io/qri/repo" "os" + "strings" "time" sp "github.com/briandowns/spinner" @@ -158,3 +159,19 @@ func PrintResults(r *dataset.Structure, data []byte, format dataset.DataFormat) // } // } // } + +func prompt(msg string) string { + var input string + printPrompt(msg) + fmt.Scanln(&input) + return strings.TrimSpace(input) +} + +func InputText(message, defaultText string) string { + if message == "" { + message = "enter text:" + } + input := prompt(fmt.Sprintf("%s [%s]: ", message, defaultText)) + + return input +} diff --git a/cmd/queries.go b/cmd/queries.go index 45321e141..6382f678c 100644 --- a/cmd/queries.go +++ b/cmd/queries.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/repo.go b/cmd/repo.go index 51286b7cf..3cc1f6620 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -1,9 +1,7 @@ package cmd import ( - "github.com/qri-io/cafs" - "github.com/qri-io/dataset" - "github.com/qri-io/dataset/dsfs" + ipfs "github.com/qri-io/cafs/ipfs" "github.com/qri-io/qri/repo" "github.com/qri-io/qri/repo/fs" "github.com/spf13/viper" @@ -16,9 +14,7 @@ func GetRepo(online bool) repo.Repo { return r } - fs, err := GetIpfsFilestore(online) - ExitIfErr(err) - + fs := GetIpfsFilestore(online) id := "" if fs.Node().PeerHost != nil { id = fs.Node().PeerHost.ID().Pretty() @@ -29,35 +25,44 @@ func GetRepo(online bool) repo.Repo { return r } -func FindDataset(r repo.Repo, store cafs.Filestore, arg string) (*dataset.Dataset, error) { - path, err := r.GetPath(arg) - if err == nil { - return dsfs.LoadDataset(store, path) - } - // TODO - add lookups by hashes & stuff - return nil, cafs.ErrNotFound +func GetIpfsFilestore(online bool) *ipfs.Filestore { + fs, err := ipfs.NewFilestore(func(cfg *ipfs.StoreCfg) { + cfg.FsRepoPath = viper.GetString(IpfsFsPath) + cfg.Online = online + }) + ExitIfErr(err) + return fs } -func DatasetRef(r repo.Repo, store cafs.Filestore, arg string) (*repo.DatasetRef, error) { - path, err := r.GetPath(arg) - if err != nil { - return nil, err - } +// func FindDataset(r repo.Repo, store cafs.Filestore, arg string) (*dataset.Dataset, error) { +// path, err := r.GetPath(arg) +// if err == nil { +// return dsfs.LoadDataset(store, path) +// } +// // TODO - add lookups by hashes & stuff +// return nil, cafs.ErrNotFound +// } - ds, err := dsfs.LoadDataset(store, path) - if err != nil { - return nil, err - } - // TODO - add hash lookup +// func DatasetRef(r repo.Repo, store cafs.Filestore, arg string) (*repo.DatasetRef, error) { +// path, err := r.GetPath(arg) +// if err != nil { +// return nil, err +// } - name, err := r.GetName(path) - if err != nil { - return nil, err - } +// ds, err := dsfs.LoadDataset(store, path) +// if err != nil { +// return nil, err +// } +// // TODO - add hash lookup - return &repo.DatasetRef{ - Path: path, - Name: name, - Dataset: ds, - }, nil -} +// name, err := r.GetName(path) +// if err != nil { +// return nil, err +// } + +// return &repo.DatasetRef{ +// Path: path, +// Name: name, +// Dataset: ds, +// }, nil +// } diff --git a/cmd/root.go b/cmd/root.go index cec5ab297..f5049e40a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,17 +1,3 @@ -// Copyright © 2016 qri.io -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( @@ -34,10 +20,8 @@ const ( var RootCmd = &cobra.Command{ Use: "qri", Short: "qri.io command line client", - Long: `this is a very early (like 0.0.0.0.0.1.alpha) tool for working with datasets. + Long: `this is a very early tool for working with datasets on the distributed web. At the moment it's a bit an experiment. - A nice web introduction is available at: - http://docs.qri.io Email brendan with any questions: sparkle_pony_2000@qri.io`, @@ -55,7 +39,7 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.qri.json)") + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $QRI_PATH/config.json)") RootCmd.PersistentFlags().BoolVarP(&noColor, "no-color", "c", false, "disable colorized output") } @@ -64,24 +48,28 @@ func initConfig() { home := userHomeDir() SetNoColor() - if cfgFile != "" { // enable ability to specify config file via flag + // if cfgFile is specified, override + if cfgFile != "" { viper.SetConfigFile(cfgFile) + err := viper.ReadInConfig() + ExitIfErr(err) + return } // if err := os.Mkdir(filepath.Join(userHomeDir(), ".qri"), os.ModePerm); err != nil { // fmt.Errorf("error creating home dir: %s\n", err.Error()) // } - - // viper.SetConfigName("config") // name of config file (without extension) - // // viper.AddConfigPath("$QRI_PATH") // add QRI_PATH env var - // viper.AddConfigPath("$HOME/.qri") // adding home directory as first search path - // viper.AddConfigPath(".") // adding home directory as first search path - // viper.AutomaticEnv() // read in environment variables that match - qriPath := os.Getenv("QRI_PATH") if qriPath == "" { qriPath = filepath.Join(home, "qri") } + + viper.SetConfigName("config") // name of config file (without extension) + viper.AddConfigPath(qriPath) // add QRI_PATH env var + // viper.AddConfigPath("$HOME/.qri/config") // adding home directory as first search path + // viper.AddConfigPath(".") // adding home directory as first search path + viper.AutomaticEnv() // read in environment variables that match + // TODO - this is stupid qriPath = strings.Replace(qriPath, "~", home, 1) viper.SetDefault(QriRepoPath, qriPath) @@ -94,7 +82,7 @@ func initConfig() { viper.SetDefault(IpfsFsPath, ipfsFsPath) // If a config file is found, read it in. - // if err := viper.ReadInConfig(); err == nil { - // // fmt.Println("Using config file:", viper.ConfigFileUsed()) - // } + if err := viper.ReadInConfig(); err == nil { + // fmt.Println("Using config file:", viper.ConfigFileUsed()) + } } diff --git a/cmd/run.go b/cmd/run.go index 7e53d9748..0c860c19a 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( @@ -19,14 +5,18 @@ import ( "io/ioutil" "time" - "github.com/qri-io/cafs/memfs" "github.com/qri-io/dataset" "github.com/qri-io/dataset/dsfs" sql "github.com/qri-io/dataset_sql" + "github.com/qri-io/qri/core" "github.com/qri-io/qri/repo" "github.com/spf13/cobra" ) +var ( + runCmdName string +) + // runCmd represents the run command var runCmd = &cobra.Command{ Use: "run", @@ -37,82 +27,38 @@ var runCmd = &cobra.Command{ ErrExit(fmt.Errorf("Please provide a query string to execute")) } - var ( - structure *dataset.Structure - results []byte - ) - r := GetRepo(false) - - store, err := GetIpfsFilestore(false) - ExitIfErr(err) - - ds := &dataset.Dataset{ - Timestamp: time.Now().In(time.UTC), - QuerySyntax: "sql", - QueryString: args[0], - // TODO - set query schema - } + store := GetIpfsFilestore(false) + req := core.NewQueryRequests(store, r) format, err := dataset.ParseDataFormatString(cmd.Flag("format").Value.String()) if err != nil { ErrExit(fmt.Errorf("invalid data format: %s", cmd.Flag("format").Value.String())) } - structure, results, err = sql.Exec(store, ds, func(o *sql.ExecOpt) { - o.Format = format - }) - ExitIfErr(err) - // TODO - move this into setting on the dataset outparam - ds.Structure = structure - ds.Length = len(results) - ds.Data, err = store.Put(memfs.NewMemfileBytes("data", results), false) - ExitIfErr(err) + p := &core.RunParams{ + ExecOpt: sql.ExecOpt{ + Format: format, + }, + SaveName: runCmdName, + Dataset: &dataset.Dataset{ + Timestamp: time.Now().In(time.UTC), + QuerySyntax: "sql", + QueryString: args[0], + }, + } - name, err := cmd.Flags().GetString("name") + res := &repo.DatasetRef{} + err = req.Run(p, res) ExitIfErr(err) - pin := name != "" - - dspath, err := dsfs.SaveDataset(store, ds, pin) + f, err := dsfs.LoadData(store, res.Dataset) ExitIfErr(err) - // err = r.PutDataset(dspath, ds) - // ExitIfErr(err) - - if name != "" { - err = r.PutName(name, dspath) - ExitIfErr(err) - } - - err = r.LogQuery(&repo.DatasetRef{Name: name, Path: dspath, Dataset: ds}) + results, err := ioutil.ReadAll(f) ExitIfErr(err) - // rgraph.AddResult(dspath, dspath) - // err = SaveQueryResultsGraph(rgraph) - // ExitIfErr(err) - - // TODO - restore - // rqgraph, err := r.repo.ResourceQueries() - // if err != nil { - // return err - // } - - // for _, key := range ds.Resources { - // rqgraph.AddQuery(key, dspath) - // } - // err = r.repo.SaveResourceQueries(rqgraph) - // if err != nil { - // return err - // } - - o := cmd.Flag("output").Value.String() - if o != "" { - ioutil.WriteFile(o, results, 0666) - return - } - - PrintResults(structure, results, format) + PrintResults(res.Dataset.Structure, results, res.Dataset.Structure.Format) }, } @@ -121,5 +67,5 @@ func init() { // runCmd.Flags().StringP("save", "s", "", "save the resulting dataset to a given address") runCmd.Flags().StringP("output", "o", "", "file to write to") runCmd.Flags().StringP("format", "f", "csv", "set output format [csv,json]") - runCmd.Flags().StringP("name", "n", "", "save output to local repository with given name") + runCmd.Flags().StringVarP(&runCmdName, "name", "n", "", "save output to name") } diff --git a/cmd/search.go b/cmd/search.go index 5adf34ee3..04318f023 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -1,22 +1,9 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( "fmt" + "github.com/qri-io/qri/core" "github.com/qri-io/qri/repo" "github.com/qri-io/qri/repo/fs" "github.com/spf13/cobra" @@ -28,57 +15,48 @@ var searchCmd = &cobra.Command{ Short: "Search for datasets", Long: `Search looks through all of your namespaces for terms that match your query`, Run: func(cmd *cobra.Command, args []string) { - if len(args) != 1 { - ErrExit(fmt.Errorf("wrong number of arguments. expected qri search [query]")) - } - - PrintWarning("CLI search only supports searching local datasets for now") - - fs, err := GetIpfsFilestore(false) + reindex, err := cmd.Flags().GetBool("reindex") if err != nil { fmt.Printf("error: %s", err.Error()) } ExitIfErr(err) - r := GetRepo(false) - - reindex, err := cmd.Flags().GetBool("reindex") - if err != nil { - fmt.Printf("error: %s", err.Error()) + if len(args) != 1 && !reindex { + ErrExit(fmt.Errorf("wrong number of arguments. expected qri search [query]")) } - ExitIfErr(err) + + r := GetRepo(false) + store := GetIpfsFilestore(false) + req := core.NewSearchRequests(store, r) if reindex { if fsr, ok := r.(*fs_repo.Repo); ok { PrintInfo("building index...") - err = fsr.UpdateSearchIndex(fs) + err = fsr.UpdateSearchIndex(store) if err != nil { fmt.Printf("error: %s", err.Error()) } ExitIfErr(err) } + PrintSuccess("reindex complete") + if len(args) == 0 { + return + } } - if s, ok := r.(repo.Searchable); ok { - results, err := s.Search(repo.SearchParams{ - Q: args[0], - }) - ExitIfErr(err) + p := &repo.SearchParams{ + Q: args[0], + Limit: 30, + Offset: 0, + } - // results, err := search.Search(GetRepo(), fs, search.NewDatasetQuery(args[0], 30, 0)) - // ExitIfErr(err) + res := []*repo.DatasetRef{} + err = req.Search(p, &res) + ExitIfErr(err) - if len(results) > 0 { - for i, ds := range results { - PrintDatasetRefInfo(i+1, ds) - } - } else { - PrintWarning("no results") - } - } else { - ErrExit(fmt.Errorf("this repository doesn't support search")) + for i, ref := range res { + PrintDatasetRefInfo(i, ref) } - }, } diff --git a/cmd/server.go b/cmd/server.go index 258f55d32..3d0123d45 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/update.go b/cmd/update.go index 1ffa7b056..c9d39e108 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -1,23 +1,8 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( "flag" "fmt" - "github.com/qri-io/dataset/dsfs" "io/ioutil" "os" "path/filepath" @@ -25,6 +10,9 @@ import ( "github.com/ipfs/go-datastore" "github.com/qri-io/dataset" + "github.com/qri-io/dataset/dsfs" + "github.com/qri-io/qri/core" + "github.com/qri-io/qri/repo" "github.com/spf13/cobra" ) @@ -43,12 +31,19 @@ var updateCmd = &cobra.Command{ Long: ``, Run: func(cmd *cobra.Command, args []string) { r := GetRepo(false) - store, err := GetIpfsFilestore(false) - ExitIfErr(err) + store := GetIpfsFilestore(false) + req := core.NewDatasetRequests(store, r) - ref, err := DatasetRef(r, store, args[0]) + p := &core.GetDatasetParams{ + Name: args[0], + Path: datastore.NewKey(args[0]), + } + ref := &repo.DatasetRef{} + err := req.Get(p, ref) ExitIfErr(err) + // ref, err := DatasetRef(r, store, args[0]) + var datapath string if updateFile != "" { datapath, err = filepath.Abs(updateFile) diff --git a/cmd/validate.go b/cmd/validate.go index 1d8cbe57c..e3e4e9c0c 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import ( diff --git a/cmd/version.go b/cmd/version.go index 9291793b1..66dec2e76 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,30 +1,15 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package cmd import "github.com/spf13/cobra" -const VERSION_NUMBER = "0.1.0alpha" +const VERSION_NUMBER = "0.1.0-alpha" // versionCmd represents the version command var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", Long: `qri uses semantic versioning. - - For updates & further information check qri.io`, + For updates & further information check https://github.com/qri-io/qri/releases`, Run: func(cmd *cobra.Command, args []string) { PrintInfo(VERSION_NUMBER) }, diff --git a/main.go b/main.go index 3095c8038..694f767be 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,3 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main import ( @@ -42,15 +28,15 @@ func init() { func main() { // Catch errors & pretty-print. // comment this out to get stack traces back. - defer func() { - if r := recover(); r != nil { - if err, ok := r.(error); ok { - cmd.PrintErr(err) - } else { - log.Info(r) - } - } - }() + // defer func() { + // if r := recover(); r != nil { + // if err, ok := r.(error); ok { + // cmd.PrintErr(err) + // } else { + // log.Info(r) + // } + // } + // }() cmd.Execute() } diff --git a/vendor/vendor.json b/vendor/vendor.json index 8e6b5bf31..dcb5e18c1 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -962,66 +962,6 @@ "revision": "a885446210d10e50d901672520fbfdbdacd41fdf", "revisionTime": "2017-10-31T18:12:39Z" }, - { - "checksumSHA1": "rDMytOmBUpsS1/vfS8jAVMM+DjI=", - "path": "github.com/qri-io/qri/api", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "5ySiPYQEiRttjA02fWKgCnNpeIk=", - "path": "github.com/qri-io/qri/api/handlers", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "gyuug3+3taK70my8PPyDi9c+3I0=", - "path": "github.com/qri-io/qri/cmd", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "HHuvTrDEji8v3GqRmSyRNwoXaRM=", - "path": "github.com/qri-io/qri/core", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "4hV963qWaQl+ydpwCwEVgnTdYzw=", - "path": "github.com/qri-io/qri/logging", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "fOqortX6B6uvSCrtd1Neba9ni80=", - "path": "github.com/qri-io/qri/p2p", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "8EVL2pkdOQ5mgEnChugXn4OKxbQ=", - "path": "github.com/qri-io/qri/repo", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "/GwpnK6uTT89Wgrm+mSSTdZcMoE=", - "path": "github.com/qri-io/qri/repo/fs", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "utIKcraiQEQaLegWTMlFGwVo6T0=", - "path": "github.com/qri-io/qri/repo/profile", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, - { - "checksumSHA1": "pXkBUWj9RIjEfx2N++STkiCxj00=", - "path": "github.com/qri-io/qri/repo/search", - "revision": "1dfdff852108a87c6442dd607fc2c081ece65a4b", - "revisionTime": "2017-11-08T22:30:10Z" - }, { "checksumSHA1": "uH0XygBiVvVrdTW1Uj593huX35U=", "path": "github.com/satori/go.uuid",