Skip to content

Pass arguments to executable sub-commands #1137

@gitoutthere

Description

@gitoutthere

I am implementing pass parameters by json file allowing users to provide -i and path to a json file which has options and their values. I have 10 sub-commands and I want this parameters from json file to be passed to sub-command file to be utilised.

I have currently achieved this by putting content of input file in process.env.inputFIle and within each sub-command file I unpack this var and shove it inside process.argv

funApp.js

program.version('2.1')
.command('add' [parameters], ' adding stuff')
.command('update' [parameters], ' update stuff')
.command('remove' [parameters], ' remove stuff')
[... etc]
.option('-i, --input <value>',' json param file')
[...]
program.on('option:input', function(inputFile) {
  const fileData = JSON.parse(fs.readFileSync(inputFile,'utf8'))
// Somehow pass these args to the funApp-add.js as args?!
})

That way my CLI could be funApp add -i params.json --overrideArg value --newArg value

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions