Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell functionality (clasp run) #11

Closed
rielzzapps opened this issue Jan 16, 2018 · 7 comments · Fixed by #321
Closed

Add shell functionality (clasp run) #11

rielzzapps opened this issue Jan 16, 2018 · 7 comments · Fixed by #321
Assignees
Labels
feature request new command A new command in `clasp`
Milestone

Comments

@rielzzapps
Copy link

Since clasp is running authorised, it would be nice if it could leverage the execution api to add a shell functionality.

Looking at firebase's Cloudfunctions where the shell is a powerfull tool.

@grant
Copy link
Contributor

grant commented Jan 16, 2018

Yup. This is definitely a wish I have! Something like:

clasp run sendEmail

@rielzzapps
Copy link
Author

If I find some time, I would like to get my hands dirty and do some POC and maybe it sticks ;)
Then the first question would be, would it be better to do a separate auth (because more scopes) for this?

@grant
Copy link
Contributor

grant commented Jan 16, 2018

I haven't played around much with the execution part of the API, but this would be my general plan. LMK if you need help with the POC.

V1

Execute functions that don't require credentials.

function getPi() {
  return 3.1415;
}
clasp run getPi
3.1415

V2

Execute functions that require Google Services (OAuth: like Gmail, Sheets...).

I think we'd have to request more specific scopes for clasp (Current scopes).

Store scopes in appsscript.json#oauthScopes.

(TODO: Document .clasp.json structure)

clasp run sendMail

function sendMail() {
  MailApp.sendEmail("email@example.com", "Test", "hi");
}

V3

Have the user re-login if they haven't auth'd the required credentials. (Requires that clasp store which credentials have been authorized per project)

Ref: https://developers.google.com/apps-script/api/reference/rest/v1/scripts/run

@rielzzapps
Copy link
Author

rielzzapps commented Jan 17, 2018

Clear.
Is V1 even possible?
"This method requires authorization with an OAuth 2.0 token that includes at least one of the scopes listed in the Authorization section"

Additionally I thought of logging.
Somewhere in between the V's, a console.log statement would be nice. I am not sure if stackdriver output can be fetched in the meantime but it will lag behind. I think realtime console logging like cloudfuctions shell does is not possible with GAS.

@grant
Copy link
Contributor

grant commented Jan 17, 2018

I think V1 is possible with script.run.

Logging is a fantastic idea. Let's add that as a different issue.
https://cloud.google.com/monitoring/api/v3/

@grant grant changed the title Feature request: Add shell functionality Add shell functionality Jan 17, 2018
@grant
Copy link
Contributor

grant commented Jan 28, 2018

In order to run a script, you need to use your own API key with clasp.

Next steps:

  • Enable a user to use their own API key
  • Develop clasp run command

@grant grant changed the title Add shell functionality Add shell functionality (clasp run) Mar 6, 2018
@grant
Copy link
Contributor

grant commented Mar 6, 2018

Specific next steps:

Enable a user to use their own API key

The first step would be to create a personal (rather than global) client ID/secret and store that in the .clasprc.json.

Develop clasp run

  • Add a new command clasp run [method] using script.run.
  • Give an error if someone tries to use the global API client ID.

Progress

I've just tested script.run successfully. We need to make the setup a bit easier though.

The steps to set it up are very complicated, but are complete and listed here:
https://developers.google.com/apps-script/api/how-tos/execute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request new command A new command in `clasp`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants