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

Extends 'spo list get' command with support for retrieving any default list in a given site #6447

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions docs/docs/cmd/spo/list/list-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ m365 spo list get [options]
: URL of the site where the list to retrieve is located.

`-i, --id [id]`
: ID of the list to retrieve information for. Specify either `id`, `title`, or `url` but not multiple.
: ID of the list to retrieve information for. Specify either `id`, `title`,`url` or `default` but not multiple.

`-t, --title [title]`
: Title of the list to retrieve information for. Specify either `id`, `title`, or `url` but not multiple.
: Title of the list to retrieve information for. Specify either `id`, `title`,`url` or `default` but not multiple.

`--url [url]`
: Server- or site-relative URL of the list. Specify either `id`, `title`, or `url` but not multiple.
: Server- or site-relative URL of the list. Specify either `id`, `title`,`url` or `default` but not multiple.

`--default`
: Set if you want to return the default list from the site. Specify either `id`, `title`, `url` or `default` but not multiple.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
: Set if you want to return the default list from the site. Specify either `id`, `title`, `url` or `default` but not multiple.
: Set to retrieve the default list from the site. Specify either `id`, `title`, `url`, or `default` but not multiple.


`-p, --properties [properties]`
: Comma-separated list of properties to retrieve from the list. Will retrieve all properties possible from default response, if not specified.
Expand All @@ -42,6 +45,12 @@ When the `properties` option includes values with a `/`, for example: `ListItemA

## Examples

Get the default document library located in the specified site.

```sh
m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x
m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x --default

```

Get information about a list with specified ID located in the specified site.

```sh
Expand All @@ -66,6 +75,12 @@ Get information about a list with specified site-relative URL located in the spe
m365 spo list get --url 'Shared Documents' --webUrl https://contoso.sharepoint.com/sites/project-x
```

Get information about the default (document) located in the specified site.

```sh
m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x --default
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use the same example twice.

```

Get information about a list returning the specified list properties.

```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"Levert, Sebastien <[email protected]>",
"Lingstuyl, Martin <[email protected]>",
"Macháček, Martin <[email protected]>",
"Maestrini Tobias <tobias@bee365.ch>",
"Maestrini, Tobias <tobias[email protected]>",
"Maillot, Michaël <[email protected]>",
"Mastykarz, Waldek <[email protected]>",
"McDonnell, Kevin <[email protected]>",
Expand Down
44 changes: 43 additions & 1 deletion src/m365/spo/commands/list/list-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,46 @@ describe(commands.LIST_GET, () => {
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', id: '0CD891EF-AFCE-4E55-B836-FCE03286CCCF' } }, commandInfo);
assert(actual);
});
});

it('retrieves the default list in the specified site by providing a webUrl', async () => {
const webUrl = 'https://contoso.sharepoint.com';
const mockListResponse = {
AllowContentTypes: true,
BaseTemplate: 100,
BaseType: 1,
ContentTypesEnabled: false,
Created: "2023-07-02T00:03:51Z",
DefaultItemOpenUseListSetting: false,
Description: "",
EnableVersioning: true,
EntityTypeName: "Shared_x0020_Documents",
Id: "cf07fe11-8b85-424c-972f-5f84fba5157c",
ItemCount: 20,
ListItemEntityTypeFullName: "SP.Data.Shared_x0020_DocumentsItem",
MajorVersionLimit: 500,
ParentWebUrl: "/",
Title: "Documents",
VersionPolicies: {
DefaultTrimMode: 1,
MinorVersionLimit: 0,
MajorVersionLimit: 500
}
};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/DefaultDocumentLibrary`) {
return mockListResponse;
}
throw 'Invalid request';
});

await command.action(logger, {
options: {
webUrl: webUrl,
default: true
}
});

assert(loggerLogSpy.calledWith(mockListResponse));
});
});
14 changes: 11 additions & 3 deletions src/m365/spo/commands/list/list-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Options extends GlobalOptions {
url?: string;
properties?: string;
withPermissions?: boolean;
default?: boolean;
}

class SpoListGetCommand extends SpoCommand {
Expand All @@ -35,7 +36,7 @@ class SpoListGetCommand extends SpoCommand {
}

public get description(): string {
return 'Gets information about the specific list';
return 'Gets information about the specific list or returns information about the default list in a site';
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not modify the description.

}

constructor() {
Expand All @@ -54,7 +55,8 @@ class SpoListGetCommand extends SpoCommand {
title: (!(!args.options.title)).toString(),
url: (!(!args.options.url)).toString(),
properties: (!(!args.options.properties)).toString(),
withPermissions: typeof args.options.withPermissions !== 'undefined'
withPermissions: typeof args.options.withPermissions !== 'undefined',
default: typeof args.options.default !== 'undefined'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
default: typeof args.options.default !== 'undefined'
default: !!args.options.default

});
});
}
Expand All @@ -73,6 +75,9 @@ class SpoListGetCommand extends SpoCommand {
{
option: '--url [url]'
},
{
option: '--default'
},
{
option: '-p, --properties [properties]'
},
Expand Down Expand Up @@ -102,7 +107,7 @@ class SpoListGetCommand extends SpoCommand {
}

#initOptionSets(): void {
this.optionSets.push({ options: ['id', 'title', 'url'] });
this.optionSets.push({ options: ['id', 'title', 'url', 'default'] });
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
Expand All @@ -122,6 +127,9 @@ class SpoListGetCommand extends SpoCommand {
const listServerRelativeUrl: string = urlUtil.getServerRelativePath(args.options.webUrl, args.options.url);
requestUrl += `GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')`;
}
else if (args.options.default) {
requestUrl += `DefaultDocumentLibrary`;
}

const fieldsProperties: Properties = this.formatSelectProperties(args.options.properties, args.options.withPermissions);
const queryParams: string[] = [];
Expand Down