LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 456 forks source link

Passing ENV var via CLI does not work to modify app behavior #3475

Closed michielmulders closed 5 years ago

michielmulders commented 5 years ago

Expected behavior

Should accept ENV var to modify app behavior.

Actual behavior

Schema validation error:

[ { keyword: 'type',
       dataPath: '.modules.http_api.httpPort',
       schemaPath:
        '#/properties/modules/properties/http_api/properties/httpPort/type',
       params: [Object],
       message: 'should be integer' } ] }

--> Probably CLI passing args as string and not converting them to specified type.

Also, --http-port option does not work as this gets converted to --httpPort. Starting application with node lisk/src/index.js --httpPort 3000 | npx bunyan does work.

Which version(s) does this affect? (Environment, OS, etc...)

2.0.0

michielmulders commented 5 years ago

Yargs is converting --http-port to --httpPort and passes both options (creates an alias). Decided to go for quick fix and allow --httpPort, so modified regex to allow uppercase chars as well.

{ _: [],
  'http-port': 3000,
  httpPort: 3000,
  '$0': 'lisk/src/index.js' }
Invalid command line arguments specified:  http-port
Set {
  'log',
  'l',
  'database',
  'd',
  'redis',
  'r',
  'snapshot',
  's',
  'port',
  'p',
  'address',
  'a',
  'peers',
  'x',
  'httpPort',
  'h',
  'network',
  'n',
  'config',
  'c' }

At framework/src/controller/validator/keywords/arg/index.js

nazarhussain commented 5 years ago

@michaellightcurve Having camelcase naming for the command line arguments is against the Linux convention. We should match both formats while matching, but only allow - formats in the command line arguments.

nazarhussain commented 5 years ago

Replace the line below with the script and it will fix.

https://github.com/LiskHQ/lisk-sdk/blob/3492bd749b40e3c2c5d615bd1e5e633d7da2b811/framework/src/controller/configurator/configurator.js#L113

// Yarg is keeping two arguments in case passed in long format
// Example --http-port, will parse as "httpPort" and "http-port"
// So we also have to keep both values to check any invalid command line argument
this.listOfArgs.add(_.camelCase(arg));
this.listOfArgs.add(arg.replace(/(^--)(.*)/, '$2'));