Skip to content

Commit

Permalink
Updated to v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Jan 11, 2018
1 parent c6185ae commit 28a7a5a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ $ goodls -u [URL of shared file on Google Drive]
- In the case of except for Google Docs
- ``https://drive.google.com/file/d/#####/view?usp=sharing``


## File with URLs
If you have a file including URLs, you can input the URL data using standard input and pipe as follows. If wrong URL is included, the URL is skipped.

~~~bash
$ cat sample.txt | goodls
~~~

or

~~~bash
$ goodls < sample.txt
~~~

**sample.txt**

~~~
https://docs.google.com/spreadsheets/d/#####/edit?usp=sharing
https://docs.google.com/document/d/#####/edit?usp=sharing
https://docs.google.com/presentation/d/#####/edit?usp=sharing
~~~

**When you download shared files from Google Drive, please confirm whether the files are shared.**

# Q&A
Expand All @@ -84,5 +106,9 @@ If you have any questions and commissions for me, feel free to tell me.

1. Initial release.

* v1.0.1 (January 11, 2018)

1. In order to download several files, a datafile including URLs using Standard Input and Pipe have gotten to be able to be inputted.


[TOP](#TOP)
54 changes: 42 additions & 12 deletions goodls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package main

import (
"bufio"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -13,6 +14,9 @@ import (
"path/filepath"
"regexp"
"strings"
"syscall"

"golang.org/x/crypto/ssh/terminal"

"github.com/urfave/cli"
)
Expand Down Expand Up @@ -170,24 +174,50 @@ func (p *para) download(url string) error {

// handler : Initialize of "para".
func handler(c *cli.Context) {
if c.String("url") == "" {
createHelp().Run(os.Args)
return
}
var err error
workdir, err := filepath.Abs(".")
if err != nil {
log.Fatal(err)
}
p := &para{
Ext: c.String("extension"),
Filename: c.String("filename"),
WorkDir: workdir,
Ext: c.String("extension"),
WorkDir: workdir,
}
err = p.download(c.String("url"))
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
if terminal.IsTerminal(int(syscall.Stdin)) {
if c.String("url") == "" {
createHelp().Run(os.Args)
return
}
p.Filename = c.String("filename")
err = p.download(c.String("url"))
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
} else {
var urls []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if scanner.Text() == "end" {
break
}
urls = append(urls, scanner.Text())
}
if scanner.Err() != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", scanner.Err())
os.Exit(1)
}
if len(urls) == 0 {
fmt.Fprintf(os.Stderr, "Error: No URL data. Please check help.\n\n $ %s --help\n\n", appname)
os.Exit(1)
}
for _, url := range urls {
err = p.download(url)
if err != nil {
fmt.Printf("## Skipped: Error: %v", err)
}
p.Filename = ""
}
}
return
}
Expand All @@ -199,7 +229,7 @@ func createHelp() *cli.App {
a.Author = "tanaike [ https://github.com/tanaikech/" + appname + " ] "
a.Email = "[email protected]"
a.Usage = "Download shared files on Google Drive."
a.Version = "1.0.0"
a.Version = "1.0.1"
a.Flags = []cli.Flag{
cli.StringFlag{
Name: "url, u",
Expand Down

0 comments on commit 28a7a5a

Please sign in to comment.