How to implement Import.Handler #1589
-
At the moment the loading of a profile overwrites any existing one, but I would like to be able to import the new profile and check it with the existing one, check for changes and then keep existing info but add non-existing info. The main use would be for importing a "default profile", while there is already a profile in the directory. The missing info should be added, but existing (personal preferences perhaps) should stay. The problem that I have is that the const config in the below code stays undefined. I have been looking at Import.Handler.ts // Load the config and set the active layer according to user options
const config = ImperativeConfig.instance.config; As far as I understand the line of code shouldn't need any arguments. It should just return an empty Config variable. I have tried calling the Import.Handler in numerous different ways, which I've listed below. There is a lot of gibberish, because I tried different ways. const t : any = {
response: {
data: {
setMessage: null,
setObj: null
},
console: {
log: null,
error: null,
errorHeader: null
}
},
arguments: {
globalConfig: false,
userConfig: false
},
positionals: {
positio: null
},
profiles: {
profi: null
},
definition: {
defi: null
},
fullDefinition: {
fulld: null
},
stdin: {
stdi: null
}
};
t.arguments.location = defaultDafZoweConfigLocation;
await new ImportHandler().process(t); My question is: What is the correct way of using the Import.Handler and why is the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @MichaelSmoor, typically we don't recommend calling handlers directly, but for this use case I think it makes sense since we currently don't have an SDK method that exposes the I believe this code should work - it's mostly the same as the snippet you shared, with the addition of initializing the Config class: const imperative = require("./lib");
const ImportHandler = require("./lib/imperative/src/config/cmd/import/import.handler").default;
(async () => {
imperative.ImperativeConfig.instance.config = await imperative.Config.load("zowe");
await new ImportHandler().process({
arguments: {
location: "<insert url here>",
globalConfig: false,
userConfig: false
},
response: { console }
});
})(); Also if you are interested in contributing to Zowe CLI, feel free to open a pull request that extends the |
Beta Was this translation helpful? Give feedback.
Hello @MichaelSmoor, typically we don't recommend calling handlers directly, but for this use case I think it makes sense since we currently don't have an SDK method that exposes the
config import
functionality. As you have discovered, the command handlers only run in an environment where Zowe CLI has preloaded certain values like theICommandParameters
interface andImperativeConfig.instance
object.I believe this code should work - it's mostly the same as the snippet you shared, with the addition of initializing the Config class: