Skip to content

Commit

Permalink
removing second refactor from this pr into its own
Browse files Browse the repository at this point in the history
Signed-off-by: Amber <amber.torrise@broadcom.com>
  • Loading branch information
ATorrise committed Feb 18, 2025
1 parent ad22c4d commit 2e4809c
Showing 1 changed file with 1 addition and 50 deletions.
51 changes: 1 addition & 50 deletions packages/cli/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,12 @@
*
*/

import { ICommandOptionDefinition, IImperativeConfig } from "@zowe/imperative";
import { Arguments } from "yargs";
import { ZosFilesOptionDefinitions } from "./zosfiles/ZosFiles.options";
import { IImperativeConfig } from "@zowe/imperative";

/**
* Get the Imperative config object which defines properties of the CLI.
* This allows it to be accessed without calling Imperative.init.
*/
export function getImperativeConfig(): IImperativeConfig {
return require("./imperative");
}

/**
* Map command arguments to options based on a definition, applying defaults and type transformations.
* Consolidates processing originally done in generateDatasetOptions and generateZosmfOptions.
*
* @param args - The command arguments
* @param optionDefinitions - The options definitions (from ICommandDefinition)
* @returns A mapped options object
*/
export function mapArgumentsToOptions<T>(
args: Arguments,
optionDefinitions: ICommandOptionDefinition[]
): T {
const options = {} as T;

// Combine global options with command-specific options
const combinedDefinitions = [...optionDefinitions, ...ZosFilesOptionDefinitions];
combinedDefinitions.forEach((optionDef) => {
const { name, type, defaultValue } = optionDef;

// Check if the argument exists in the command input or use the default value
const value = args[name] !== undefined ? args[name] : defaultValue;

// If the value is still undefined, skip adding it to the options
if (value === undefined) {
return;
}

// Handle transformations for specific fields
if (name === "dirblk") {
const dsorg = args["dsorg"];
options[name as keyof T] = parseInt(
dsorg === "PO" || dsorg === "POE" ? "10" : "0"
) as unknown as T[keyof T];
return;
}

// Type-based transformations
if (type === "number") {
options[name as keyof T] = parseInt(value, 10) as unknown as T[keyof T];
} else {
options[name as keyof T] = value as T[keyof T];
}
});

return options as T;
}

0 comments on commit 2e4809c

Please sign in to comment.