Skip to content

issue-1060 Add scriptId argument to list-deployments and list-versions commands #1066

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wattry
Copy link

@wattry wattry commented May 30, 2025

Allow script ID as argument for list-deployments & list-versions

Add --json option to list-deployments & list-versions

Fixes #<issue_number_goes_here> (it's a good idea to open an issue first for discussion)

  • npm run test succeeds.
 128 passing (581ms)
  • npm run lint succeeds.
 λ npm run lint --fix

> @google/[email protected] lint
> npm run check


> @google/[email protected] check
> biome check src test && npm run compile

Checked 73 files in 24ms. No fixes applied.

> @google/[email protected] compile
> tspc
  • Appropriate changes to README are included in PR.
### Versions

List versions of a script.

#### Options

- `--json`: Output list in json format.

#### Examples

- `clasp list-versions`: List all versions for the current project
- `clasp list-versions --json`: List all versions for the current project and output in json
- `clasp list-versions [scriptId]`: List all versions for a script ID
- `clasp list-versions --json [scriptId]`: List all versions for a script ID and output in json


### Deployments

List deployments of a script.

#### Options

- `--json`: Output list in json format.

#### Examples

- `clasp list-deployments`: List all deployments for the current project
- `clasp list-deployments --json`: List all deployments for the current project and output in json
- `clasp list-deployments [scriptId]`: List all deployments for a script ID
- `clasp list-deployments [scriptId] --json`: List all deployments for a script ID and output in json

Copy link

google-cla bot commented May 30, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sqrrrl
Copy link
Member

sqrrrl commented Jul 23, 2025

Didn't mean to close the issue yet, but wanted the --json flag to be a global option so it's consistent throughout all the commands. If you can resolve the merge conflicts, happy to merge the parameter stuff (but similarly, would rather do this uniformly if there are additional commands that would benefit)

@wattry
Copy link
Author

wattry commented Jul 23, 2025

Ah okay I thought you were closing it because you were already implementing it globally as a broader change and this was unnecessary.

@sqrrrl
Copy link
Member

sqrrrl commented Jul 23, 2025

Also should be able to do this without modifying anything in src/core. There's a method on the clasp instance to set the script ID if it isn't already set:

const clasp = options.clasp;
if (scriptId) { 
  clasp.withScriptId(scriptId);
} 

Right now that withScriptId function will throw an error if the script is already known, so this would fail if the user is calling it in a dir with a valid clasp project, but we can probably remove/relax that check in src/core/clasp.ts

Allow script ID as argument for list-deployments & list-versions

Add --json option to list-deployments & list-versions

Updated commands
@wattry
Copy link
Author

wattry commented Jul 24, 2025

Also should be able to do this without modifying anything in src/core. There's a method on the clasp instance to set the script ID if it isn't already set:

const clasp = options.clasp;
if (scriptId) { 
  clasp.withScriptId(scriptId);
} 

Right now that withScriptId function will throw an error if the script is already known, so this would fail if the user is calling it in a dir with a valid clasp project, but we can probably remove/relax that check in src/core/clasp.ts

The intention behind that change was to be able to run it with the script id of library dependencies, not limited to the root package. When our users are trying to manage a package that has several libraries they have to navigate to the project and click on each package there.

Do you have any thoughts on that implementation or is it something that is out of scope for the project?

@wattry
Copy link
Author

wattry commented Jul 24, 2025

This is what I was thinking to relax the check.

  withScriptId(scriptId: string) {
    if (this.options.project) {
      debug('Project is already configured, overriding scriptId with %s', scriptId);
    }

    this.options.project = {
      scriptId,
    };
    return this;
  }

Relax the withScriptId to allow scriptId input inside a configured project

Use global --json instead of command level
@wattry wattry force-pushed the wattry/issue-1060 branch from 143f6d1 to 8d8f0d2 Compare July 24, 2025 15:12
@wattry wattry changed the title issue-1060 issue-1060 Add scriptId argument to list-deployments and list-versions commands Jul 24, 2025
Copy link
Member

@sqrrrl sqrrrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments, mostly just to simplify this further.

Also please add test cases

const description = d.deploymentConfig?.description ? `- ${d.deploymentConfig.description}` : '';
console.log(`- ${d.deploymentId} ${versionString} ${description}`);
});
if (options?.json) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary now. The --json output is already handled above (~ line 44) and it returns, so this code path should never run.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const deployments = await withSpinner(spinnerMsg, async () => {
const deployments = await withSpinner(spinnerMsg, () => {
// If a scriptId is provided, set it on the clasp instance.
if (scriptId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, suggest moving up to after const clasp...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

);
console.log(msg);
});
if (options?.json) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other file, this shouldn't be necessary or ever execute since the JSON flag is checked earlier

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

const versions = await withSpinner(spinnerMsg, async () => {
const versions = await withSpinner(spinnerMsg, () => {
// If a scriptId is provided, set it on the clasp instance.
if (scriptId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, same as before (move to after the const clasp... line)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

README.md Outdated
@@ -460,9 +461,16 @@ Clasp offers several commands to opens the current directory's `clasp` project a

List deployments of a script.

#### Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to document this as a global flag in the last change, so good reminder :)

Can you move this up to the global options section please? Same for list versions too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -531,9 +539,16 @@ Creates an immutable version of the script.

List versions of a script.

#### Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other, can/should be consolidated under global options

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Add test cases
@wattry wattry requested a review from sqrrrl July 28, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants