Skip to content

Commit

Permalink
feat(cmd publish): add publish command, publish-on-save flag
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Oct 29, 2018
1 parent 84019b7 commit 327f697
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
8 changes: 6 additions & 2 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ func TestCommandsIntegration(t *testing.T) {
"qri diff me/movies me/movies2 -d=detail",
fmt.Sprintf("qri export -o=%s me/movies", path),
fmt.Sprintf("qri export -o=%s --format=cbor --body-format=json me/movies", path),
"qri registry unpublish me/movies",
"qri registry publish me/movies",
"qri publish me/movies",
"qri ls -p",
"qri publish -u me/movies",
// TODO - currently removed, see TODO in cmd/registry.go
// "qri registry unpublish me/movies",
// "qri registry publish me/movies",
"qri rename me/movies me/movie",
"qri body --limit=1 --format=cbor me/movie",
"qri validate me/movie",
Expand Down
9 changes: 7 additions & 2 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ to a published dataset will be immideately visible to connected peers.
$ qri publish me/dataset me/other_dataset
# unpublish a dataset
$ qri publish -d me/dataset`,
$ qri publish -u me/dataset`,
Annotations: map[string]string{
"group": "network",
},
Expand All @@ -37,14 +37,17 @@ to a published dataset will be immideately visible to connected peers.
},
}

cmd.Flags().BoolVarP(&o.Unpublish, "unpublish", "u", false, "unpublish a dataset")

return cmd
}

// PublishOptions encapsulates state for the publish command
type PublishOptions struct {
ioes.IOStreams

Refs []string
Refs []string
Unpublish bool

DatasetRequests *lib.DatasetRequests
}
Expand All @@ -66,6 +69,8 @@ func (o *PublishOptions) Run() error {
return err
}

ref.Published = !o.Unpublish

if err = o.DatasetRequests.SetPublishStatus(&ref, &res); err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/qri.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ https://github.com/qri-io/qri/issues`,
NewInfoCommand(opt, ioStreams),
NewListCommand(opt, ioStreams),
NewLogCommand(opt, ioStreams),
NewPublishCommand(opt, ioStreams),
NewPeersCommand(opt, ioStreams),
NewRegistryCommand(opt, ioStreams),
// TODO - registry command is currently removed in favor of the newer "qri publish" command
// we should consider refactoring this code (espcially it's documentation) &
// use it for restistry-specific publication & search interaction
// NewRegistryCommand(opt, ioStreams),
NewRemoveCommand(opt, ioStreams),
NewRenameCommand(opt, ioStreams),
NewRenderCommand(opt, ioStreams),
Expand Down
3 changes: 3 additions & 0 deletions cmd/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

// NewRegistryCommand creates a `qri registry` subcommand for working with configured registries
// TODO - registry command is currently removed in favor of the newer "qri publish" command
// we should consider refactoring this code (espcially it's documentation) &
// use it for restistry-specific publication & search interaction
func NewRegistryCommand(f Factory, ioStreams ioes.IOStreams) *cobra.Command {
o := &RegistryOptions{IOStreams: ioStreams}
cmd := &cobra.Command{
Expand Down
5 changes: 2 additions & 3 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"io/ioutil"

"github.com/qri-io/dataset"
"github.com/qri-io/dataset/dsutil"
"github.com/qri-io/ioes"
Expand All @@ -23,7 +22,7 @@ func NewSaveCommand(f Factory, ioStreams ioes.IOStreams) *cobra.Command {
o := &SaveOptions{IOStreams: ioStreams}
cmd := &cobra.Command{
Use: "save",
Aliases: []string{"update", "commit"},
Aliases: []string{"commit"},
Short: "Save changes to a dataset",
Long: `
Save is how you change a dataset, updating one or more of data, metadata, and structure.
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var log = golog.Logger("lib")

// VersionNumber is the current version qri
const VersionNumber = "0.5.6"
const VersionNumber = "0.5.7-dev"

// Requests defines a set of library methods
type Requests interface {
Expand Down
15 changes: 9 additions & 6 deletions repo/fs/refstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ func (n Refstore) PutRef(p repo.DatasetRef) (err error) {
return err
}

for _, ref := range names {
if ref.Equal(p) {
return nil
} else if ref.Match(p) {
return repo.ErrNameTaken
matched := false
for i, ref := range names {
if ref.Match(p) {
matched = true
names[i] = p
}
}

names = append(names, p)
if !matched {
names = append(names, p)
}

if n.store != nil {
ds, err = dsfs.LoadDataset(n.store, datastore.NewKey(p.Path))
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion repo/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"github.com/qri-io/qri/repo/profile"
)

// Refstore keeps a collection of dataset references
// Refstore keeps a collection of dataset references, Refstores require complete
// references (with both alias and identifiers), and can carry only one of a
// given alias eg: putting peer/dataset@a/ipfs/b when a ref with alias peer/dataset
// is already in the store will overwrite the stored reference
type Refstore interface {
// PutRef adds a reference to the store. References must be complete with
// Peername, Name, and Path specified
Expand Down
15 changes: 14 additions & 1 deletion repo/test/test_refstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func testRefstoreMain(t *testing.T, rmf RepoMakerFunc) {
t.Errorf("repo.NameCount: %s", err.Error())
return
}
if count < len(refs) {
if count != len(refs) {
t.Errorf("repo.NameCount should have returned %d results", len(refs))
return
}
Expand Down Expand Up @@ -161,6 +161,19 @@ func testRefstoreMain(t *testing.T, rmf RepoMakerFunc) {
}
}

refs[0].Published = false
if err := r.PutRef(refs[0]); err != nil {
t.Errorf("updating existing ref err: %s", err)
}

unpublished, err := r.GetRef(refs[0])
if err != nil {
t.Error(err)
}
if unpublished.Published {
t.Error("expected setting published value to be retained")
}

for _, ref := range refs {
if err := r.Store().Delete(datastore.NewKey(ref.Path)); err != nil {
t.Errorf("error removing path from repo store: %s", err.Error())
Expand Down

0 comments on commit 327f697

Please sign in to comment.