-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Reference Selection): support reference selection
I think we should steal the concept of "USE" from database land to set the current dataset. From the CLI this'll dramatically cut down on typing, and abate the need for tab completions. We can also plumb this up into the API & frontend as needed. In coming commits lib methods can leverage the current Reference selection to return values when no reference is specified. I'm setting selections to be a slice of datasets instead of a single dataset b/c & think we should adapt the entire lib interface to support working with multiple datasets at once where possible. for example. "qri info me/dataset_a me/dataset_b" should return info on both datasets, supplying a third would return info on all three datasets. I think we can carry this pattern into a number of places for interesting results, like dataset comparison. This commit also removes the repo.SetPrivateKey() method. Instead users should set Private key through using repo.SetProfile with a private key specified.
- Loading branch information
Showing
14 changed files
with
189 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package lib | ||
|
||
import ( | ||
"fmt" | ||
"net/rpc" | ||
|
||
"github.com/qri-io/qri/repo" | ||
) | ||
|
||
// SelectionRequests encapsulates business logic for the qri search | ||
// command | ||
type SelectionRequests struct { | ||
cli *rpc.Client | ||
repo repo.Repo | ||
} | ||
|
||
// NewSelectionRequests creates a SelectionRequests pointer from either a repo | ||
// or an rpc.Client | ||
func NewSelectionRequests(r repo.Repo, cli *rpc.Client) *SelectionRequests { | ||
if r != nil && cli != nil { | ||
panic(fmt.Errorf("both repo and client supplied to NewSelectionRequests")) | ||
} | ||
return &SelectionRequests{ | ||
cli: cli, | ||
repo: r, | ||
} | ||
} | ||
|
||
// CoreRequestsName implements the requests | ||
func (r SelectionRequests) CoreRequestsName() string { return "selection" } | ||
|
||
// SetSelectedRefs sets the current set of selected references | ||
func (r *SelectionRequests) SetSelectedRefs(sel *[]repo.DatasetRef, done *bool) error { | ||
if r.cli != nil { | ||
return r.cli.Call("SelectionRequests.SetSelectedRefs", sel, done) | ||
} | ||
|
||
if rs, ok := r.repo.(repo.RefSelector); ok { | ||
return rs.SetSelectedRefs(*sel) | ||
} | ||
return fmt.Errorf("selection not supported") | ||
} | ||
|
||
// SelectedRefs gets the current set of selected references | ||
func (r *SelectionRequests) SelectedRefs(done *bool, sel *[]repo.DatasetRef) (err error) { | ||
if r.cli != nil { | ||
return r.cli.Call("SelectionRequests.SelectedRefs", done, sel) | ||
} | ||
|
||
if rs, ok := r.repo.(repo.RefSelector); ok { | ||
*sel, err = rs.SelectedRefs() | ||
return | ||
} | ||
return fmt.Errorf("selection not supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package lib | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/qri-io/qri/repo" | ||
testrepo "github.com/qri-io/qri/repo/test" | ||
) | ||
|
||
func TestSelectionRequestsSelectedRefs(t *testing.T) { | ||
mr, err := testrepo.NewTestRepo(nil) | ||
if err != nil { | ||
t.Fatalf("error allocating test repo: %s", err.Error()) | ||
} | ||
|
||
sr := NewSelectionRequests(mr, nil) | ||
var done bool | ||
a := []repo.DatasetRef{{Peername: "a"}} | ||
if err := sr.SetSelectedRefs(&a, &done); err != nil { | ||
t.Errorf("setting selected refs: %s", err.Error()) | ||
} | ||
|
||
b := []repo.DatasetRef{} | ||
if err := sr.SelectedRefs(&done, &b); err != nil { | ||
t.Errorf("selected refs: %s", err.Error()) | ||
} | ||
|
||
if len(a) != len(b) { | ||
t.Errorf("repsonse len mismatch. expected: %d. got: %d", len(a), len(b)) | ||
} | ||
for i, ar := range a { | ||
if err := repo.CompareDatasetRef(ar, b[i]); err != nil { | ||
t.Errorf("case selection %d error: %s", i, err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.