Skip to content
代码片段 群组 项目
提交 828bdc6c 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Migrate args to common JS module.

上级 ec8b3aae
No related branches found
No related tags found
无相关合并请求
......@@ -19,8 +19,8 @@ const yargs = require('yargs')
const { logInfo } = require('../util/env.js')
// TODO how to handle relative pathing for things like properties file.
export var zclPropertiesFile = './test/zcl/zcl-test.properties'
export var httpPort = 9070
exports.zclPropertiesFile = './test/zcl/zcl-test.properties'
exports.httpPort = 9070
/**
* Process the command line arguments and resets the state in this file
......@@ -30,7 +30,7 @@ export var httpPort = 9070
* @param {*} argv
* @returns parsed argv object
*/
export function processCommandLineArguments(argv) {
function processCommandLineArguments(argv) {
var ret = yargs
.command('generate', 'Generate ZCL artifacts.', (yargs) => {
yargs.positional('outputDir', {
......@@ -44,13 +44,13 @@ export function processCommandLineArguments(argv) {
desc: 'Port used for the HTTP server',
alias: 'p',
type: 'number',
default: httpPort,
default: exports.httpPort,
})
.option('zclProperties', {
desc: 'zcl.properties file to read in.',
alias: 'zcl',
type: 'string',
default: zclPropertiesFile,
default: exports.zclPropertiesFile,
})
.option('noUi', {
desc: "Don't show the main window when starting.",
......@@ -75,8 +75,10 @@ export function processCommandLineArguments(argv) {
logInfo('Command line arguments:')
logInfo(ret)
zclPropertiesFile = ret.zclProperties
httpPort = ret.httpPort
exports.zclPropertiesFile = ret.zclProperties
exports.httpPort = ret.httpPort
return ret
}
exports.processCommandLineArguments = processCommandLineArguments
......@@ -21,7 +21,7 @@ import { version } from '../../package.json'
import { closeDatabase, initDatabase, loadSchema } from '../db/db-api.js'
import { initHttpServer, httpServerPort } from '../server/http-server.js'
import { loadZcl } from '../zcl/zcl-loader.js'
import * as Args from './args.js'
const Args = require('./args.js')
const {
logError,
logInfo,
......@@ -59,7 +59,7 @@ function startSelfCheck() {
initDatabase(sqliteFile())
.then((db) => attachToDb(db))
.then((db) => loadSchema(db, schemaFile(), version))
.then((db) => loadZcl(db, Args.zclPropertiesFile))
.then((db) => loadZcl(db, args.zclPropertiesFile))
.then(() => {
logInfo('Self-check done!')
})
......@@ -73,8 +73,8 @@ function startNormal(ui, showUrl) {
initDatabase(sqliteFile())
.then((db) => attachToDb(db))
.then((db) => loadSchema(db, schemaFile(), version))
.then((db) => loadZcl(db, Args.zclPropertiesFile))
.then((db) => initHttpServer(db, Args.httpPort))
.then((db) => loadZcl(db, args.zclPropertiesFile))
.then((db) => initHttpServer(db, args.httpPort))
.then(() => {
if (ui) {
initializeElectronUi(httpServerPort())
......@@ -111,7 +111,7 @@ function applyGenerationSettings(
.then((db) =>
loadZcl(
db,
zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile
zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile
)
)
.then((db) =>
......@@ -148,7 +148,7 @@ export function startSdkGeneration(
.then((db) =>
loadZcl(
db,
zclPropertiesFilePath ? zclPropertiesFilePath : Args.zclPropertiesFile
zclPropertiesFilePath ? zclPropertiesFilePath : args.zclPropertiesFile
)
)
.then((db) =>
......@@ -162,7 +162,7 @@ export function startSdkGeneration(
}
app.on('ready', () => {
var argv = Args.processCommandLineArguments(process.argv)
var argv = args.processCommandLineArguments(process.argv)
logInfo(argv)
......@@ -189,7 +189,7 @@ app.on('window-all-closed', () => {
app.on('activate', () => {
logInfo('Activate...')
windowCreateIfNotThere(Args.httpPort)
windowCreateIfNotThere(args.httpPort)
})
app.on('quit', () => {
......
......@@ -18,11 +18,11 @@
* @jest-environment node
*/
import { processCommandLineArguments } from '../src-electron/main-process/args'
import yargs from 'yargs'
const args = require('../src-electron/main-process/args')
const yargs = require('yargs')
test('Test basic command line processing', () => {
var args = processCommandLineArguments([
var a = args.processCommandLineArguments([
'node',
'test.js',
'--noUI',
......@@ -33,11 +33,11 @@ test('Test basic command line processing', () => {
'XmlRoot',
])
expect(args.noUI).toBeTruthy()
expect(args.httpPort).toBeTruthy()
expect(args.httpPort).toEqual(123)
expect(args.arglessArg).toBeTruthy()
expect(args.xmlRoot).toBe('XmlRoot')
expect(a.noUI).toBeTruthy()
expect(a.httpPort).toBeTruthy()
expect(a.httpPort).toEqual(123)
expect(a.arglessArg).toBeTruthy()
expect(a.xmlRoot).toBe('XmlRoot')
})
test('Verify how yargs works', () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册