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

addEditOptions #2027

Merged
merged 11 commits into from
Jan 26, 2024
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

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

## `8.0.0-next.202401191954`

- LTS Breaking: Removed all 'profiles' commands, since they only worked with now-obsolete V1 profiles.
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -11,6 +11,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 @@ -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",
},
]
`;
10 changes: 7 additions & 3 deletions packages/cli/src/zosfiles/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,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 @@ -799,15 +800,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: `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
26 changes: 26 additions & 0 deletions 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"]
},
};
5 changes: 3 additions & 2 deletions packages/cli/src/zosfiles/edit/Edit.utils.ts
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface ILocalFile {
zosResp: IZosFilesResponse | null;
conflict: boolean;
encoding?: string | null;
binary?: boolean;
}

/**
Expand Down Expand Up @@ -158,8 +159,8 @@ export class EditUtilities {
lfFile.fileName,
{
returnEtag: true,
binary: null,
encoding: null,
binary: lfFile.binary,
encoding: lfFile.encoding,
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
file: tempPath
}
];
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/zosfiles/edit/ds/Dataset.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const DatasetDefinition: ICommandDefinition = {
],
options: [
EditOptions.editor,
EditOptions.extension
EditOptions.extension,
EditOptions.binary,
EditOptions.encoding,
],
examples: [
{
Expand All @@ -52,8 +54,8 @@ export const DatasetDefinition: ICommandDefinition = {
options: `ibmuser.cntl(iefbr14) --editor C:\\Windows\\System32\\Notepad.exe`
},
{
description: strings.ACTIONS.USS_FILE.EXAMPLES.EX2,
options: `ibmuser.jcl(iefbr14) --editor notepad --extension jcl`
description: strings.ACTIONS.DATA_SET.EXAMPLES.EX2,
options: `ibmuser.jcl(iefbr14) --binary`
}
]
};
10 changes: 8 additions & 2 deletions packages/cli/src/zosfiles/edit/uss/USSFile.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const USSFileDefinition: ICommandDefinition = {
},
],
options: [
EditOptions.editor
EditOptions.editor,
EditOptions.binary,
EditOptions.encoding
],
examples: [
{
Expand All @@ -49,6 +51,10 @@ export const USSFileDefinition: ICommandDefinition = {
{
description: strings.ACTIONS.USS_FILE.EXAMPLES.EX1,
options: `/a/ibmuser/my_text.txt --editor C:\\Windows\\System32\\Notepad.exe`
}
},
{
description: strings.ACTIONS.USS_FILE.EXAMPLES.EX2,
options: `/a/ibmuser/my_text.txt --binary`
},
]
};
Loading