Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Add functionality to disable population of default values in profiles #401

Merged
merged 12 commits into from
May 20, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the Imperative package will be documented in this file.

## Recent Changes

- Add the --dd flag to profile creation to allow the profile to be created without the default values specified for that profile.
- Use a token for authentication if a token is present in the underlying REST session object.
- Add a new CredsForSessCfg.addCredsOrPrompt function that places credentials (including a possible token) into a session configuration object.
- Credentials are obtained from the command line, environment variables, or a profile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ then
fi

# Next create a kiwi profile
cmd-cli profiles create kiwi-profile "test_kiwi" --amount $kiwiAmount
cmd-cli profiles create kiwi-profile "test_kiwi" --amount $kiwiAmount --dd
CMDRC=$?
if [ $CMDRC -gt 0 ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ exports[`cmd-cli profiles create banana should create profiles and only list the
name: test_kiwi (default)
contents:
amount: 1000
price: 1
"
`;
3 changes: 1 addition & 2 deletions __tests__/__integration__/cmd/src/imperative/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export const config: IImperativeConfig = {
aliases: ["p"],
description: "The price of one kiwi.",
type: "number",
// TODO Add default value here after merging no-defaults branch
// defaultValue: 1
defaultValue: 1
},
},
kiwiSecret: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Object {
"name": "overwrite",
"type": "boolean",
},
Object {
"aliases": Array [
"dd",
],
"description": "Disable populating profile values of undefined properties with default values.",
"name": "disable-defaults",
"type": "boolean",
},
],
"positionals": Array [
Object {
Expand Down Expand Up @@ -68,6 +76,14 @@ Object {
"name": "overwrite",
"type": "boolean",
},
Object {
"aliases": Array [
"dd",
],
"description": "Disable populating profile values of undefined properties with default values.",
"name": "disable-defaults",
"type": "boolean",
},
],
"positionals": Array [
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Object {
"name": "overwrite",
"type": "boolean",
},
Object {
"aliases": Array [
"dd",
],
"description": "Disable populating profile values of undefined properties with default values.",
"name": "disable-defaults",
"type": "boolean",
},
],
"positionals": Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion packages/cmd/src/CommandProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export class CommandProcessor {
// Set the default value for all options if defaultValue was specified on the command
// definition and the option was not specified
for (const option of allOpts) {
if (option.defaultValue != null && args[option.name] == null) {
if (option.defaultValue != null && args[option.name] == null && !args[Constants.DISABLE_DEFAULTS_OPTION] ) {
const defaultedArgs = CliUtils.setOptionValue(option.name,
("aliases" in option) ? option.aliases : [],
option.defaultValue
Expand Down
1 change: 1 addition & 0 deletions packages/constants/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class Constants {
public static readonly PROFILE_NAME_OPTION = "profileName";
public static readonly PROFILE_NAME_OPTION_ALIAS = "pn";
public static readonly OVERWRITE_OPTION = "overwrite";
public static readonly DISABLE_DEFAULTS_OPTION = "disable-defaults";
public static readonly DELETE_ACTION = "delete";
public static readonly DETAILS_ACTION = "detail";
public static readonly SHOW_DEPS_ACTION = "show-dependencies";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { ProfilesCommandBuilder } from "./ProfilesCommandBuilder";
import { ICommandDefinition, ICommandProfileTypeConfiguration } from "../../../../cmd";
import { createProfileCommandDesc, createProfileOptionDesc, createProfileOptionOverwriteDesc } from "../../../../messages";
import { createProfileCommandDesc, createProfileOptionDesc, createProfileOptionOverwriteDesc, createProfileDisableDefaultsDesc } from "../../../../messages";
import { Constants } from "../../../../constants";
import { TextUtils } from "../../../../utilities";
import { Logger } from "../../../../logger/index";
Expand Down Expand Up @@ -82,6 +82,12 @@ export class ProfilesCreateCommandBuilder extends ProfilesCommandBuilder {
{type: this.mProfileType}),
type: "boolean"
});
profileCommand.options.push({
name: Constants.DISABLE_DEFAULTS_OPTION, aliases: ["dd"],
description: TextUtils.formatMessage(createProfileDisableDefaultsDesc.message,
{type: this.mProfileType}),
type: "boolean"
});

if (this.mProfileConfig.createProfileExamples != null) {
profileCommand.examples = this.mProfileConfig.createProfileExamples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class CreateProfilesHandler implements ICommandHandler {
type: profileType,
args: commandParameters.arguments,
overwrite: commandParameters.arguments.overwrite,
disableDefaults: commandParameters.arguments.disableDefaults,
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved
profile: {}
};
/**
Expand Down
4 changes: 4 additions & 0 deletions packages/messages/src/CoreMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export const createProfileOptionOverwriteDesc: IMessageDefinition = {
message: `Overwrite the {{type}} profile when a profile of the same name exists.`
};

export const createProfileDisableDefaultsDesc: IMessageDefinition = {
message: `Disable populating profile values of undefined properties with default values.`
};

export const deleteProfilesCommandSummary: IMessageDefinition = {
message: `Delete existing profiles`
};
Expand Down
7 changes: 7 additions & 0 deletions packages/profiles/src/doc/parms/ISaveProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ export interface ISaveProfile {
* @memberof ISaveProfile
*/
overwrite?: boolean;

/**
* The argument to disable populating defaults
* @type {Arguments}
* @memberof ISaveProfileFromCliArgs
*/
disableDefaults?: boolean;
}