Skip to content

Commit

Permalink
Updated to v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Aug 30, 2017
1 parent 4c7245d commit da25f2e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ $ ggsrun e1 -f foo -v 1 -j

``GoogleElapsedTime`` cannot output in this mode, because this mode doesn't use server.

<a name="DownloadFiles"></a>
## 6. Download Files
ggsrun can download files from Google Drive by file ID and file name. The files also include GAS projects and scripts.

Expand All @@ -858,7 +859,26 @@ $ ggsrun d -f filename -e pdf

You can convert only from Google Docs Files (spreadsheet, slide, documentation and so on). For example, you cannot convert image files and text data.

<u>Here, I could notice that the container-bound scripts can be downloaded!</u>
<a name="DownloadBoundScript"></a>
### How to Download Container-Bound Scripts
<u>Here, I could notice that the container-bound scripts can be downloaded! From version 1.3.0, the container-bound scripts could be downloaded.</u>

- In order to download container-bound scripts, the project ID of container-bound scripts is required. The project ID can be retrieved as follows.
- Open the project. And please operate follows using click.
- -> File
- -> Project properties
- -> Get Script ID (**This is the project ID.**)

You can download the project by the following command.

~~~bash
$ ggsrun d -pi project_id
~~~

**Limitation :**

- The file information of container-bound scripts cannot be retrieved by Drive API. So the filename cannot be retrieved from the project ID.
- Prefix of filename of the downloaded project is the project ID.

### Help
~~~
Expand All @@ -873,11 +893,12 @@ DESCRIPTION:
In this mode, an access token is required.
OPTIONS:
--fileid value, -i value File ID on Google Drive
--filename value, -f value File Name on Google Drive
--extension value, -e value Extension (File format of downloaded file)
--rawdata, -r Save a project with GAS scripts as raw data (JSON data).
--jsonparser, -j Display results by JSON parser
--fileid value, -i value File ID on Google Drive
--filename value, -f value File Name on Google Drive
--projectid value, --pi value Project ID of bound scripts of Google Sheets, Docs, or Forms file
--extension value, -e value Extension (File format of downloaded file)
--rawdata, -r Save a project with GAS scripts as raw data (JSON data).
--jsonparser, -j Display results by JSON parser
~~~

## 7. Upload Files
Expand Down Expand Up @@ -1549,6 +1570,16 @@ If you have any questions and commissions for me, feel free to tell me using e-m

I don't know when this workaround will not be able to be used. But if this could not be used, I would like to investigate of other method.

* v1.3.0 (August 30, 2017)

1. From this version, [container-bound scripts](https://developers.google.com/apps-script/guides/bound) can be downloaded. The container-bound script is the script created at the script editor on Google Sheets, Docs, or Forms file. The usage is [here](#DownloadBoundScript).
- In order to download container-bound scripts, the project ID of container-bound scripts is required. The project ID can be retrieved as follows.
- Open the project. And please operate follows using click.
- -> File
- -> Project properties
- -> Get Script ID (**This is the project ID.**)
1. When a project is downloaded, the filename of HTML file had become ``.gs``. This bug was modified.


## Server
* v1.0.0 (April 24, 2017)
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Will you want to develop GAS on your local PC? Generally, when we develop GAS, w
5. Creates, updates and backs up project with GAS.
6. Downloads files from Google Drive and Uploads files to Google Drive.
6. Downloads files from Google Drive and Uploads files to Google Drive. Also container-bound scripts can be downloaded.
7. Download revision files from Google Drive.
Expand Down
6 changes: 5 additions & 1 deletion ggsrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
app.Author = "tanaike [ https://github.com/tanaikech/ggsrun ] "
app.Email = "[email protected]"
app.Usage = "Executes Google Apps Script (GAS) on Google and Feeds Back Results."
app.Version = "1.2.2"
app.Version = "1.3.0"
app.Commands = []cli.Command{
{
Name: "exe1",
Expand Down Expand Up @@ -155,6 +155,10 @@ func main() {
Name: "filename, f",
Usage: "File Name on Google Drive",
},
cli.StringFlag{
Name: "projectid, pi",
Usage: "Project ID of bound scripts of Google Sheets, Docs, or Forms file",
},
cli.StringFlag{
Name: "extension, e",
Usage: "Extension (File format of downloaded file)",
Expand Down
11 changes: 9 additions & 2 deletions materials.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,15 @@ func (a *AuthContainer) defDownloadContainer(c *cli.Context) *utl.FileInf {
Workdir: a.InitVal.workdir,
PstartTime: a.InitVal.pstart,
FileID: c.String("fileid"),
WantExt: c.String("extension"),
WantName: c.String("filename"),
ProjectID: func(c *cli.Context) string {
id := c.String("projectid")
if c.String("fileid") != "" && c.String("projectid") != "" {
id = ""
}
return id
}(c),
WantExt: c.String("extension"),
WantName: c.String("filename"),
}
return p
}
Expand Down
27 changes: 20 additions & 7 deletions utl/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type FileInf struct {
SearchByName string `json:"-"`
SearchByID string `json:"-"`
FileID string `json:"id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
RevisionID string `json:"revisionid,omitempty"`
FileName string `json:"name,omitempty"`
SaveName string `json:"saved_file_name,omitempty"`
Expand Down Expand Up @@ -139,15 +140,20 @@ func (p *FileInf) saveScript(data []byte, c *cli.Context) *FileInf {
p.Msgar = append(p.Msgar, fmt.Sprintf("%s has %d scripts.", p.FileName, len(f.Files)))
}
for _, e := range f.Files {
saveName := p.FileName + "_" + e.Name + "." + func(ex string) string {
saveName := p.FileName + "_" + e.Name + "." + func(ex, ty string) string {
var eext string
if len(ex) > 0 {
eext = ex
} else {
eext = "gs"
switch ty {
case "server_js":
eext = "gs"
case "html":
eext = "html"
}
}
return eext
}(p.WantExt)
}(p.WantExt, e.Type)
src := fmt.Sprintf("// Script ID in Project = %s \n%s", e.ID, e.Source)
ioutil.WriteFile(filepath.Join(p.Workdir, saveName), []byte(src), 0777)
p.Msgar = append(p.Msgar, fmt.Sprintf("Script was downloaded as '%s'.", saveName))
Expand All @@ -164,7 +170,7 @@ func (p *FileInf) Downloader(c *cli.Context) *FileInf {
} else {
p.DlMime, ext = defFormat(p.MimeType)
}
if len(p.FileID) > 0 {
if len(p.FileID) > 0 || len(p.ProjectID) > 0 {
var body []byte
var gm map[string]interface{}
json.Unmarshal([]byte(googlemimetypes), &gm)
Expand All @@ -182,12 +188,19 @@ func (p *FileInf) Downloader(c *cli.Context) *FileInf {
if p.MimeType == "application/vnd.google-apps.script" {
p, body = p.writeFile(sdownloadurl + p.FileID + "&format=json")
p.saveScript(body, c)
} else {
} else if p.MimeType != "" {
p, _ = p.writeFile(driveapiurl + p.FileID + "/export?mimeType=" + p.DlMime)
}
} else {
p.SaveName = p.FileName
p, _ = p.writeFile(driveapiurl + p.FileID + "?alt=media")
if len(p.ProjectID) > 0 && p.MimeType == "" {
p.FileName = p.ProjectID
p.MimeType = "application/vnd.google-apps.script"
p, body = p.writeFile(sdownloadurl + p.ProjectID + "&format=json")
p.saveScript(body, c)
} else {
p.SaveName = p.FileName
p, _ = p.writeFile(driveapiurl + p.FileID + "?alt=media")
}
}
} else {
fmt.Fprintf(os.Stderr, "Error: Please input File Name or File ID. ")
Expand Down

0 comments on commit da25f2e

Please sign in to comment.