Skip to content

Commit

Permalink
Merge pull request #1977 from zowe/deprecate-getDataSet
Browse files Browse the repository at this point in the history
Deprecate old getDataSet in v2 LTS, move to zosfiles SDK
  • Loading branch information
zFernand0 authored Nov 28, 2023
2 parents 5549c8e + 84ead1b commit 5f4c989
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ Don't see what you're looking for? Browse questions from the community or ask yo
Zowe CLI is a component of the Zowe Open Mainframe Project, part of the Linux Foundation.
To learn more about how Zowe is structured and governed, see the [Technical Steering Committee Strucutre and Governance documentation](https://github.com/zowe/community/blob/master/Technical-Steering-Committee/tsc-governance.md).
To learn more about how Zowe is structured and governed, see the [Technical Steering Committee Structure and Governance documentation](https://github.com/zowe/community/blob/master/Technical-Steering-Committee/tsc-governance.md).
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- Deprecated: `getDataSet` in the `zosfiles` command group utility functions, use `zosfiles` SDK's `ZosFilesUtils.getDataSetFromName` instead. [#1696](https://github.com/zowe/zowe-cli/issues/1696)

## `7.18.10`

- BugFix: Added missing z/OSMF connection options to the z/OS Logs command group.
Expand Down
15 changes: 3 additions & 12 deletions packages/cli/src/zosfiles/ZosFiles.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,13 @@

// We are using arguments as an expected input to the function. Thus there is no generated code
// so we can ignore this linting error.
import { IDataSet } from "@zowe/zos-files-for-zowe-sdk";
import { IDataSet, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk";

/**
* @deprecated - use @zowe/zos-files-for-zowe-sdk's ZosFilesUtils.getDataSetFromName instead
* Converts the name of a data set to an IDataSet
* @param {string} name - the name in the form USER.DATA.SET | USER.DATA.SET(mem1)
*/
export function getDataSet(name: string): IDataSet {
const parts = name.replace(')', '').split('(');
if (parts.length > 1) {
return {
dsn: parts[0],
member: parts[1]
};
} else {
return {
dsn: name
};
}
return ZosFilesUtils.getDataSetFromName(name);
}
7 changes: 3 additions & 4 deletions packages/cli/src/zosfiles/copy/ds/Ds.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
*/

import { AbstractSession, IHandlerParameters } from "@zowe/imperative";
import { Copy, IZosFilesResponse, IDataSet, ICopyDatasetOptions } from "@zowe/zos-files-for-zowe-sdk";
import { Copy, IZosFilesResponse, IDataSet, ICopyDatasetOptions, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk";
import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";
import { getDataSet } from "../../ZosFiles.utils";

/**
* Handler to copy a data set.
*/
export default class DsHandler extends ZosFilesBaseHandler {
public async processWithSession(commandParameters: IHandlerParameters, session: AbstractSession): Promise<IZosFilesResponse> {
const fromDataSet: IDataSet = getDataSet(commandParameters.arguments.fromDataSetName);
const toDataSet: IDataSet = getDataSet(commandParameters.arguments.toDataSetName);
const fromDataSet: IDataSet = ZosFilesUtils.getDataSetFromName(commandParameters.arguments.fromDataSetName);
const toDataSet: IDataSet = ZosFilesUtils.getDataSetFromName(commandParameters.arguments.toDataSetName);
const options: ICopyDatasetOptions = {
"from-dataset": fromDataSet,
enq: commandParameters.arguments.enq,
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/zosfiles/copy/dsclp/Dsclp.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
*/

import { AbstractSession, IHandlerParameters, IHandlerResponseConsoleApi, Session } from "@zowe/imperative";
import { Copy, ICrossLparCopyDatasetOptions, IDataSet, IGetOptions, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk";
import { Copy, ICrossLparCopyDatasetOptions, IDataSet, IGetOptions, IZosFilesResponse, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk";
import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";
import { getDataSet } from "../../ZosFiles.utils";

/**
* Handler to copy a data set.
*/

export default class DsclpHandler extends ZosFilesBaseHandler {
public async processWithSession(commandParameters: IHandlerParameters, session: AbstractSession): Promise<IZosFilesResponse> {
const sourceDataset: IDataSet = getDataSet(commandParameters.arguments.fromDataSetName);
const targetDataset: IDataSet = getDataSet(commandParameters.arguments.toDataSetName);
const sourceDataset: IDataSet = ZosFilesUtils.getDataSetFromName(commandParameters.arguments.fromDataSetName);
const targetDataset: IDataSet = ZosFilesUtils.getDataSetFromName(commandParameters.arguments.toDataSetName);

const options: ICrossLparCopyDatasetOptions = {
"from-dataset": sourceDataset,
Expand Down
4 changes: 4 additions & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe z/OS files SDK package will be documented in this file.

## Recent Changes

- Enhancement: Adds `ZosFilesUtils.getDataSetFromName` to create an IDataSet from a dataset name [#1696](https://github.com/zowe/zowe-cli/issues/1696)

## `7.18.9`

- BugFix: Fix behavior where a specified directory was being lowercased on non-PDS datasets when downloading all datasets [#1722](https://github.com/zowe/zowe-cli/issues/1722)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IO } from "@zowe/imperative";
import { ZosFilesUtils } from "../../../src/utils/ZosFilesUtils";
import { ZosFilesConstants } from "../../../src/constants/ZosFiles.constants";
import { ZosFilesMessages } from "../../../src/constants/ZosFiles.messages";
import { IDataSet } from "../../../src/doc/IDataSet";

jest.mock("fs");

Expand Down Expand Up @@ -210,4 +211,26 @@ describe("ZosFilesUtils", () => {
});
});

describe("getDataSetFromName", () => {
it("should generate an IDataSet for a dataset", () => {
const dataSetName = "SYS1.PARMLIB";
const expectedResult: IDataSet = {
dsn: "SYS1.PARMLIB",
member: undefined
};

expect(ZosFilesUtils.getDataSetFromName(dataSetName)).toEqual(expectedResult);
});

it("should generate an IDataSet for a partitioned dataset", () => {
const dataSetName = "SYS1.PARMLIB(SOMEMEM)";
const expectedResult: IDataSet = {
dsn: "SYS1.PARMLIB",
member: "SOMEMEM"
};

expect(ZosFilesUtils.getDataSetFromName(dataSetName)).toEqual(expectedResult);
});
});

});
19 changes: 19 additions & 0 deletions packages/zosfiles/src/utils/ZosFilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IZosFilesResponse } from "../doc/IZosFilesResponse";
import { ZosmfRestClient, ZosmfHeaders } from "@zowe/core-for-zowe-sdk";
import { IDeleteOptions } from "../methods/hDelete";
import { IOptions } from "../doc/IOptions";
import { IDataSet } from "../doc/IDataSet";

/**
* Common IO utilities
Expand Down Expand Up @@ -275,4 +276,22 @@ export class ZosFilesUtils {
throw error;
}
}

/**
* Converts the name of a data set to an IDataSet
* @param {string} name - the name in the form USER.DATA.SET | USER.DATA.SET(mem1)
*/
public static getDataSetFromName(name: string): IDataSet {
const parts = name.replace(')', '').split('(');
if (parts.length > 1) {
return {
dsn: parts[0],
member: parts[1]
};
} else {
return {
dsn: name
};
}
}
}

0 comments on commit 5f4c989

Please sign in to comment.