Skip to content

Commit

Permalink
unpublish implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Odeke committed Dec 15, 2014
1 parent bccefe4 commit 1590766
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Use `drive help` for further reference.
$ drive push [-r -no-prompt path] # pushes to the remote
$ drive push [-r -hidden path] # pushes also hidden directories and paths to the remote
$ drive diff [path] # outputs a diff of local and remote
$ drive publish [path] # publishes a file, outputs URL
$ drive pub [path] # publishes a file, outputs URL
$ drive unpub [path] # revokes public access to the file

## Configuration

Expand Down
24 changes: 19 additions & 5 deletions cmd/drive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import (
var context *config.Context

const (
descInit = "inits a directory and authenticates user"
descPull = "pulls remote changes from google drive"
descPush = "push local changes to google drive"
descDiff = "compares a local file with remote"
descPublish = "publishes a file and prints its publicly available url"
descInit = "inits a directory and authenticates user"
descPull = "pulls remote changes from google drive"
descPush = "push local changes to google drive"
descDiff = "compares a local file with remote"
descPublish = "publishes a file and prints its publicly available url"
descUnpublish = "revokes public access to a file"
)

func main() {
Expand All @@ -42,6 +43,7 @@ func main() {
command.On("push", descPush, &pushCmd{}, []string{})
command.On("diff", descDiff, &diffCmd{}, []string{})
command.On("pub", descPublish, &publishCmd{}, []string{})
command.On("unpub", descUnpublish, &unpublishCmd{}, []string{})
command.ParseAndRun()
}

Expand Down Expand Up @@ -112,6 +114,18 @@ func (cmd *diffCmd) Run(args []string) {
}

type publishCmd struct{}
type unpublishCmd struct{}

func (cmd *unpublishCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
return fs
}

func (cmd *unpublishCmd) Run(args []string) {
context, path := discoverContext(args)
exitWithError(drive.New(context, &drive.Options{
Path: path,
}).Unpublish())
}

func (cmd *publishCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
return fs
Expand Down
8 changes: 8 additions & 0 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ func (c *Commands) Publish() (err error) {
fmt.Println("Published on", link)
return
}

func (c *Commands) Unpublish() error {
file, err := c.rem.FindByPath(c.opts.Path)
if err != nil {
return err
}
return c.rem.Unpublish(file.Id)
}
4 changes: 4 additions & 0 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (r *Remote) Trash(id string) error {
return err
}

func (r *Remote) Unpublish(id string) error {
return r.service.Permissions.Delete(id, "anyone").Do()
}

func (r *Remote) Publish(id string) (string, error) {
perm := &drive.Permission{Type: "anyone", Role: "reader"}
_, err := r.service.Permissions.Insert(id, perm).Do()
Expand Down

0 comments on commit 1590766

Please sign in to comment.