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

applying accepted v3 filesEditOptions enhancements to v2 #2029

Merged
merged 5 commits into from
Jan 31, 2024
Merged
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
6 changes: 5 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

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

## Recent Changes

- Enhancement: Adding `--binary` and `--encoding` options to `zosfiles edit` to zowe V2

## `7.23.0`

- BugFix: Update zos-files copy dsclp system tests to include large mock files.
- BugFix: Update zos-files copy dsclp system tests to include large mock files.

## `7.22.0`

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

175 changes: 175 additions & 0 deletions packages/cli/__tests__/zosfiles/__unit__/edit/Edit.utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe("Files Edit Utilities", () => {
guiAvail: true,
zosResp: null,
encoding: null,
binary: null,
conflict: false
};

Expand All @@ -56,6 +57,7 @@ describe("Files Edit Utilities", () => {
guiAvail: true,
zosResp: null,
encoding: null,
binary: null,
conflict: false
};

Expand Down Expand Up @@ -224,6 +226,7 @@ describe("Files Edit Utilities", () => {
expect(response.zosResp?.apiResponse.etag).toContain('remote etag');
expect(EditUtilities.destroyTempFile).toHaveBeenCalledTimes(1);
});

it("should download etag and copy of remote - [fileType = 'ds', useStash = false]", async () => {
//TEST SETUP
//download (to temp) AND grab etag
Expand All @@ -240,6 +243,86 @@ describe("Files Edit Utilities", () => {
expect(response.zosResp?.apiResponse.etag).toContain('remote etag');
expect(EditUtilities.destroyTempFile).toHaveBeenCalledTimes(0);
});

it("localDownload should properly pass non-falsy binary option to Download.dataSet", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileDS);
localFile.binary = true;
downloadDataSetSpy.mockImplementation(jest.fn(async () => {
return zosResp;
}));

//TEST CONFIRMATION
//test that binary option is passed to downloadDS
await EditUtilities.localDownload(REAL_SESSION, localFile, false);
expect(downloadDataSetSpy).toHaveBeenCalledTimes(1);
expect(downloadDataSetSpy).toHaveBeenCalledWith(undefined, "TEST(DS)", {
"binary": true,
"encoding": null,
"file": null,
"returnEtag": true
});
});

it("localDownload should properly pass non-falsy encoding option to Download.dataSet", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileDS);
localFile.encoding = "1047";
downloadDataSetSpy.mockImplementation(jest.fn(async () => {
return zosResp;
}));

//TEST CONFIRMATION
//test that encoding option is passed to downloadDS
await EditUtilities.localDownload(REAL_SESSION, localFile, false);
expect(downloadDataSetSpy).toHaveBeenCalledTimes(1);
expect(downloadDataSetSpy).toHaveBeenCalledWith(undefined, "TEST(DS)", {
"binary": null,
"encoding": "1047",
"file": null,
"returnEtag": true
});
});

it("localDownload should properly pass non-falsy binary option to Download.ussFile", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileUSS);
localFile.binary = true;
downloadUssFileSpy.mockImplementation(jest.fn(async () => {
return zosResp;
}));

//TEST CONFIRMATION
//test that encoding option is passed to downloadDS
await EditUtilities.localDownload(REAL_SESSION, localFile, false);
expect(downloadUssFileSpy).toHaveBeenCalledTimes(1);
expect(downloadUssFileSpy).toHaveBeenCalledWith(undefined, "test_uss.jcl", {
"binary": true,
"encoding": null,
"file": null,
"returnEtag": true
});
});

it("localDownload should properly pass non-falsy encoding option to Download.ussFile", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileUSS);
localFile.encoding = "1047";
downloadUssFileSpy.mockImplementation(jest.fn(async () => {
return zosResp;
}));

//TEST CONFIRMATION
//test that encoding option is passed to downloadDS
await EditUtilities.localDownload(REAL_SESSION, localFile, false);
expect(downloadUssFileSpy).toHaveBeenCalledTimes(1);
expect(downloadUssFileSpy).toHaveBeenCalledWith(undefined, "test_uss.jcl", {
"binary": null,
"encoding": "1047",
"file": null,
"returnEtag": true
});
});
});
describe("fileComparison()", () => {
const guiAvailSpy = jest.spyOn(ProcessUtils, "isGuiAvailable");
Expand Down Expand Up @@ -354,6 +437,98 @@ describe("Files Edit Utilities", () => {
});
});
describe("uploadEdits()", () => {
it("should successfully pass binary option when uploading - ds", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileDS);
localFile.zosResp = zosResp;
localFile.zosResp.apiResponse.encoding = "matching etag";
localFile.binary = true;
const UploadSpy = jest.spyOn(Upload, "fileToDataset").mockImplementation(async() => {
return zosResp;
});
jest.spyOn(EditUtilities, "makeEdits").mockImplementation(async () => {
return true;
});
jest.spyOn(EditUtilities, "destroyTempFile").mockImplementation();

//TEST CONFIRMATION
await EditUtilities.uploadEdits(REAL_SESSION, commandParametersDs, localFile);
expect(UploadSpy).toHaveBeenCalledWith(
undefined,
null,
"TEST(DS)",
expect.objectContaining({ binary: true })
);
});
it("should successfully pass binary option when uploading - uss", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileUSS);
localFile.zosResp = zosResp;
localFile.zosResp.apiResponse.etag = "etag";
localFile.binary = true;
const UploadSpy = jest.spyOn(Upload, "fileToUssFile").mockImplementation(async() => {
return zosResp;
});
jest.spyOn(EditUtilities, "makeEdits").mockImplementation(async () => {
return true;
});
jest.spyOn(EditUtilities, "destroyTempFile").mockImplementation();

//TEST CONFIRMATION
await EditUtilities.uploadEdits(REAL_SESSION, commandParametersDs, localFile);
expect(UploadSpy).toHaveBeenCalledWith(
undefined,
null,
"test_uss.jcl",
expect.objectContaining({ binary: true })
);
});
it("should successfully pass encoding option when uploading - ds", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileDS);
localFile.zosResp = zosResp;
localFile.zosResp.apiResponse.encoding = "matching etag";
localFile.encoding = "1047";
jest.spyOn(Upload, "fileToDataset").mockImplementation(async() => {
return zosResp;
});
jest.spyOn(EditUtilities, "makeEdits").mockImplementation(async () => {
return true;
});
jest.spyOn(EditUtilities, "destroyTempFile").mockImplementation();

//TEST CONFIRMATION
await EditUtilities.uploadEdits(REAL_SESSION, commandParametersDs, localFile);
expect(Upload.fileToDataset).toHaveBeenCalledWith(
undefined,
null,
"TEST(DS)",
expect.objectContaining({ encoding: "1047" })
);
});
it("should successfully pass encoding option when uploading - uss", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileUSS);
localFile.zosResp = zosResp;
localFile.zosResp.apiResponse.etag = "etag";
localFile.encoding = "1047";
const UploadSpy = jest.spyOn(Upload, "fileToUssFile").mockImplementation(async() => {
return zosResp;
});
jest.spyOn(EditUtilities, "makeEdits").mockImplementation(async () => {
return true;
});
jest.spyOn(EditUtilities, "destroyTempFile").mockImplementation();

//TEST CONFIRMATION
await EditUtilities.uploadEdits(REAL_SESSION, commandParametersDs, localFile);
expect(UploadSpy).toHaveBeenCalledWith(
undefined,
null,
"test_uss.jcl",
expect.objectContaining({ encoding: "1047" })
);
});
it("should successfully upload when etags are matching, then destroy temp - uss", async () => {
//TEST SETUP
const localFile = cloneDeep(localFileUSS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Array [
"aliases": Array [
"ed",
],
"description": "Set the default editor that you wish to use for editing. Set the option to the editor's executable file location or the program's name: ie \\"--editor notepad\\"",
"description": "Editor that overrides the default editor for this file type. Set the option to the editor's executable file location or the program's name: ie \\"--editor notepad\\"",
"name": "editor",
"required": false,
"type": "string",
Expand All @@ -20,6 +20,25 @@ Array [
"required": false,
"type": "string",
},
Object {
"aliases": Array [
"b",
],
"description": "Transfer the file content in binary mode (no EBCDIC to ASCII conversion).",
"name": "binary",
"type": "boolean",
},
Object {
"aliases": Array [
"ec",
],
"conflictsWith": Array [
"binary",
],
"description": "Transfer the file content with encoding mode, which means that data conversion is performed using the file encoding specified.",
"name": "encoding",
"type": "string",
},
]
`;

Expand All @@ -34,8 +53,8 @@ Array [
"options": "ibmuser.cntl(iefbr14) --editor C:\\\\Windows\\\\System32\\\\Notepad.exe",
},
Object {
"description": "Edit the contents of the USS file \\"/a/ibmuser/my_jcl.jcl\\" in notepad and set extension as \\"jcl\\"",
"options": "ibmuser.jcl(iefbr14) --editor notepad --extension jcl",
"description": "Edit the contents of the data set member \\"ibmuser.jcl(iefbr14)\\" and set extension as \\"jcl\\"",
"options": "ibmuser.jcl(iefbr14) --binary",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@ Array [
"aliases": Array [
"ed",
],
"description": "Set the default editor that you wish to use for editing. Set the option to the editor's executable file location or the program's name: ie \\"--editor notepad\\"",
"description": "Editor that overrides the default editor for this file type. Set the option to the editor's executable file location or the program's name: ie \\"--editor notepad\\"",
"name": "editor",
"required": false,
"type": "string",
},
Object {
"aliases": Array [
"b",
],
"description": "Transfer the file content in binary mode (no EBCDIC to ASCII conversion).",
"name": "binary",
"type": "boolean",
},
Object {
"aliases": Array [
"ec",
],
"conflictsWith": Array [
"binary",
],
"description": "Transfer the file content with encoding mode, which means that data conversion is performed using the file encoding specified.",
"name": "encoding",
"type": "string",
},
]
`;

Expand All @@ -24,5 +43,9 @@ Array [
"description": "Edit the contents of the USS file \\"/a/ibmuser/my_text.txt\\" in notepad",
"options": "/a/ibmuser/my_text.txt --editor C:\\\\Windows\\\\System32\\\\Notepad.exe",
},
Object {
"description": "Edit the contents of the USS file \\"/a/ibmuser/my_jcl.jcl\\" with binary flag set",
"options": "/a/ibmuser/my_text.txt --binary",
},
]
`;
12 changes: 8 additions & 4 deletions packages/cli/src/zosfiles/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ export default {
},
EXAMPLES: {
EX1: `Edit the contents of the data set member "ibmuser.cntl(iefbr14)"`,
EX2: `Edit the contents of the USS file "ibmuser.jcl(iefbr14)" and set extension as "jcl"`,
EX2: `Edit the contents of the data set member "ibmuser.jcl(iefbr14)" and set extension as "jcl"`,
EX3: `Edit the contents of the data set member "ibmuser.jcl(iefbr14)" with binary flag set`,
}
},
USS_FILE: {
Expand All @@ -778,15 +779,18 @@ export default {
},
EXAMPLES: {
EX1: `Edit the contents of the USS file "/a/ibmuser/my_text.txt" in notepad`,
EX2: `Edit the contents of the USS file "/a/ibmuser/my_jcl.jcl" in notepad and set extension as "jcl"`,
EX2: `Edit the contents of the USS file "/a/ibmuser/my_jcl.jcl" with binary flag set`,
}
}
},
OPTIONS: {
EDITOR: `Set the default editor that you wish to use for editing. Set the option to the editor's executable file location ` +
EDITOR: `Editor that overrides the default editor for this file type. Set the option to the editor's executable file location ` +
`or the program's name: ie "--editor notepad"`,
EXTENSION: `Set the file extension of the file for editing to leverage an editor's file-type-specific formatting: ` +
`ie "--extension jcl"`
`ie "--extension jcl"`,
BINARY: "Transfer the file content in binary mode (no EBCDIC to ASCII conversion).",
ENCODING: "Transfer the file content with encoding mode, which means that data conversion is performed using the file encoding " +
"specified."
}
},
COMPARE: {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/zosfiles/edit/Edit.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default class EditHandler extends ZosFilesBaseHandler {
fileType: commandParameters.positionals[2].includes('d') ? "ds" : "uss",
guiAvail: ProcessUtils.isGuiAvailable() === GuiResult.GUI_AVAILABLE,
conflict: false,
encoding: commandParameters.arguments.encoding,
binary: commandParameters.arguments.binary,
zosResp: null
};
lfFile.tempPath = commandParameters.arguments.localFilePath = await Utils.buildTempPath(lfFile, commandParameters);
Expand Down
28 changes: 27 additions & 1 deletion packages/cli/src/zosfiles/edit/Edit.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,37 @@ export const EditOptions: { [key: string]: ICommandOptionDefinition } = {
type: "string",
required: false
},
/**
* The option to label your file's data type
* @type {ICommandOptionDefinition}
*/
extension: {
name: "extension",
aliases: ["ext"],
description: strings.EXTENSION,
type: "string",
required: false
},
};
/**
* The binary option
* @type {ICommandOptionDefinition}
*/
binary: {
name: "binary",
aliases: ["b"],
description: strings.BINARY,
type: "boolean"
},

/**
* The encoding option
* @type {ICommandOptionDefinition}
*/
encoding: {
name: "encoding",
aliases: ["ec"],
description: strings.ENCODING,
type: "string",
conflictsWith: ["binary"]
},
};
Loading
Loading