Skip to content

Commit

Permalink
Adds types to spo folder and spo file commands. Closes #5789
Browse files Browse the repository at this point in the history
  • Loading branch information
milanholemans authored and Jwaegebaert committed Jan 27, 2024
1 parent 8d6724f commit c30cc0e
Show file tree
Hide file tree
Showing 41 changed files with 231 additions and 16 deletions.
20 changes: 13 additions & 7 deletions src/m365/spo/commands/file/file-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class SpoFileAddCommand extends SpoCommand {
this.#initTelemetry();
this.#initOptions();
this.#initValidators();
this.#initTypes();
}

#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
contentType: (!(!args.options.contentType)).toString(),
checkOut: args.options.checkOut || false,
checkInComment: (!(!args.options.checkInComment)).toString(),
approve: args.options.approve || false,
approveComment: (!(!args.options.approveComment)).toString(),
publish: args.options.publish || false,
publishComment: (!(!args.options.publishComment)).toString()
contentType: typeof args.options.contentType !== 'undefined',
checkOut: !!args.options.checkOut,
checkInComment: typeof args.options.checkInComment !== 'undefined',
approve: !!args.options.approve,
approveComment: typeof args.options.approveComment !== 'undefined',
publish: !!args.options.publish,
publishComment: typeof args.options.publishComment !== 'undefined'
});
});
}
Expand Down Expand Up @@ -157,6 +158,11 @@ class SpoFileAddCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'folder', 'path', 'contentType', 'checkInComment', 'approveComment', 'publishComment');
this.types.boolean.push('checkOut', 'approve', 'publish');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const folderPath: string = urlUtil.getServerRelativePath(args.options.webUrl, args.options.folder);
const fullPath: string = path.resolve(args.options.path);
Expand Down
5 changes: 5 additions & 0 deletions src/m365/spo/commands/file/file-checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SpoFileCheckinCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -110,6 +111,10 @@ class SpoFileCheckinCommand extends SpoCommand {
this.optionSets.push({ options: ['url', 'id'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'url', 'id', 'type', 'comment');
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['url'];
}
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-checkout-undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SpoFileCheckoutUndoCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -85,6 +86,11 @@ class SpoFileCheckoutUndoCommand extends SpoCommand {
this.optionSets.push({ options: ['fileId', 'fileUrl'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId');
this.types.boolean.push('force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const undoCheckout = async (): Promise<void> => {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/m365/spo/commands/file/file-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SpoFileCheckoutCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -81,6 +82,10 @@ class SpoFileCheckoutCommand extends SpoCommand {
this.optionSets.push({ options: ['id', 'url'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'url', 'id',);
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['url'];
}
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SpoFileCopyCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -108,6 +109,11 @@ class SpoFileCopyCommand extends SpoCommand {
this.optionSets.push({ options: ['sourceUrl', 'sourceId'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'sourceUrl', 'sourceId', 'targetUrl', 'newName', 'nameConflictBehavior');
this.types.boolean.push('resetAuthorAndCreated', 'bypassSharedLock');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
const sourceServerRelativePath = await this.getSourcePath(logger, args.options);
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SpoFileGetCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -129,6 +130,11 @@ class SpoFileGetCommand extends SpoCommand {
this.optionSets.push({ options: ['id', 'url'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'url', 'id', 'path');
this.types.boolean.push('asString', 'asListItem', 'asFile', 'withPermissions');
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['url'];
}
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SpoFileListCommand extends SpoCommand {
this.#initTelemetry();
this.#initOptions();
this.#initValidators();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -80,6 +81,11 @@ class SpoFileListCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'folderUrl', 'fields', 'filter');
this.types.boolean.push('recursive');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Retrieving all files in folder '${args.options.folderUrl}' at site '${args.options.webUrl}'${args.options.recursive ? ' (recursive)' : ''}...`);
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SpoFileMoveCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -109,6 +110,11 @@ class SpoFileMoveCommand extends SpoCommand {
this.optionSets.push({ options: ['sourceUrl', 'sourceId'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'sourceUrl', 'sourceId', 'targetUrl', 'newName', 'nameConflictBehavior');
this.types.boolean.push('retainEditorAndModified', 'bypassSharedLock');
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['targetUrl', 'sourceUrl'];
}
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SpoFileRemoveCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -95,6 +96,11 @@ class SpoFileRemoveCommand extends SpoCommand {
this.optionSets.push({ options: ['id', 'url'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'id', 'url');
this.types.boolean.push('recycle', 'force');
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['url'];
}
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SpoFileRenameCommand extends SpoCommand {
this.#initTelemetry();
this.#initOptions();
this.#initValidators();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -83,6 +84,11 @@ class SpoFileRenameCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'sourceUrl', 'targetFileName');
this.types.boolean.push('force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const webUrl = args.options.webUrl;
const originalFileServerRelativePath: string = urlUtil.getServerRelativePath(args.options.webUrl, args.options.sourceUrl);
Expand Down
5 changes: 5 additions & 0 deletions src/m365/spo/commands/file/file-retentionlabel-ensure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SpoFileRetentionLabelEnsureCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -92,6 +93,10 @@ class SpoFileRetentionLabelEnsureCommand extends SpoCommand {
this.optionSets.push({ options: ['fileUrl', 'fileId'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'name', 'fileUrl', 'fileId', 'assetId');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
const fileProperties = await this.getFileProperties(logger, args);
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-retentionlabel-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SpoFileRetentionLabelRemoveCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -89,6 +90,11 @@ class SpoFileRetentionLabelRemoveCommand extends SpoCommand {
this.optionSets.push({ options: ['fileUrl', 'fileId'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId');
this.types.boolean.push('force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (args.options.force) {
await this.removeFileRetentionLabel(logger, args);
Expand Down
5 changes: 5 additions & 0 deletions src/m365/spo/commands/file/file-roleassignment-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SpoFileRoleAssignmentAddCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -123,6 +124,10 @@ class SpoFileRoleAssignmentAddCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName', 'roleDefinitionName');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Adding role assignment to file in site at ${args.options.webUrl}...`);
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-roleassignment-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SpoFileRoleAssignmentRemoveCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -111,6 +112,11 @@ class SpoFileRoleAssignmentRemoveCommand extends SpoCommand {
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName');
this.types.boolean.push('force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const removeRoleAssignment = async (): Promise<void> => {
if (this.verbose) {
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-roleinheritance-break.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SpoFileRoleInheritanceBreakCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -92,6 +93,11 @@ class SpoFileRoleInheritanceBreakCommand extends SpoCommand {
this.optionSets.push({ options: ['fileId', 'fileUrl'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId');
this.types.boolean.push('clearExistingPermissions', 'force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const breakFileRoleInheritance = async (): Promise<void> => {
if (this.verbose) {
Expand Down
6 changes: 6 additions & 0 deletions src/m365/spo/commands/file/file-roleinheritance-reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SpoFileRoleInheritanceResetCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -87,6 +88,11 @@ class SpoFileRoleInheritanceResetCommand extends SpoCommand {
this.optionSets.push({ options: ['fileId', 'fileUrl'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileUrl', 'fileId');
this.types.boolean.push('force');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
const resetFileRoleInheritance = async (): Promise<void> => {
if (this.verbose) {
Expand Down
9 changes: 7 additions & 2 deletions src/m365/spo/commands/file/file-sharinginfo-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ class SpoFileSharingInfoGetCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
fileId: (!(!args.options.fileId)).toString(),
fileUrl: (!(!args.options.fileUrl)).toString()
fileId: typeof args.options.fileId !== 'undefined',
fileUrl: typeof args.options.fileUrl !== 'undefined'
});
});
}
Expand Down Expand Up @@ -112,6 +113,10 @@ class SpoFileSharingInfoGetCommand extends SpoCommand {
this.optionSets.push({ options: ['fileId', 'fileUrl'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileId', 'fileUrl');
}

protected getExcludedOptionsWithUrls(): string[] | undefined {
return ['fileUrl'];
}
Expand Down
5 changes: 5 additions & 0 deletions src/m365/spo/commands/file/file-sharinglink-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SpoFileSharingLinkAddCommand extends SpoCommand {
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -114,6 +115,10 @@ class SpoFileSharingLinkAddCommand extends SpoCommand {
this.optionSets.push({ options: ['fileId', 'fileUrl'] });
}

#initTypes(): void {
this.types.string.push('webUrl', 'fileId', 'fileUrl', 'type', 'expirationDateTime', 'scope');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Creating a sharing link for file ${args.options.fileId || args.options.fileUrl}...`);
Expand Down
Loading

0 comments on commit c30cc0e

Please sign in to comment.