Skip to content

Commit

Permalink
basic CLI args parser for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Crow committed Dec 3, 2021
1 parent 040e7b2 commit 1c864e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The `-d` flag tells the program to create the database tables and indexes it
needs.

# Command Line Options
- `-h`: displays command line options
- `-d`: create database tables and indexes that are missing. Does not delete or
modify existing tables, so you needn't worry if you run it when tables are
already set up.
- `-t`: runs the contents of `src/test.js`
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
extractMySqlConfig,
DatabaseConnection
} = require("./src/model/database.js");
const {testDatabase} = require("./src/test.js");



Expand All @@ -43,7 +42,7 @@ app.use(session({

const db = new DatabaseConnection(get("dbPrefix"), mysqlOptions);
parseCommandLineArguments(db);
//testDatabase(db);



const services = createServices(db);
Expand Down
12 changes: 12 additions & 0 deletions src/commandLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ real CLI library as the program grows more complicated.


const {createRequiredTablesIn} = require("./model/database.js");
const {testDatabase} = require("./test.js");



async function parseCommandLineArguments(databaseConnection){
const args = process.argv;

if(args.includes("-h")){
console.log(`
Options:
* -h : display this help message
* -d : create database schema
* -t : run tests
`);
}
if(args.includes("-d")){
await createRequiredTablesIn(databaseConnection);
}
if(args.includes("-t")){
await testDatabase(databaseConnection);
}
}
exports.parseCommandLineArguments = parseCommandLineArguments;

0 comments on commit 1c864e0

Please sign in to comment.