google / clasp

🔗 Command Line Apps Script Projects
https://developers.google.com/apps-script/guides/clasp
Apache License 2.0
4.53k stars 423 forks source link

Clasp run functionName will only output the return statement of that function ? #925

Open freddieventura opened 2 years ago

freddieventura commented 2 years ago

If I have

## Code.gs
function main () {
   Logger.log("Hello World);
   return "Hello Moon";
}

And I do

clasp run main

It will ouput

Hello Moon

While I want it to output

Hello World

I guess it is only outputing the return statement, that's it. Is it?

Nu11u5 commented 2 years ago

The command clasp run calls the Apps Script API scripts.run method. The behavior of this method is not controlled by clasp.

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

As you see in the documentation, the only response from the API is going to be the return value of the function.

If you want to see log output using clasp, use console.log() instead of Logger.log() in your code, and run the clasp logs command or view the logs in a browser window.