Skip to content

Commit

Permalink
fix: use yargs instead of optimist (fixes #65)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Sep 14, 2021
1 parent c9551c7 commit d311d00
Show file tree
Hide file tree
Showing 3 changed files with 4,090 additions and 9,560 deletions.
56 changes: 34 additions & 22 deletions hads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs-extra');
const path = require('path');
const optimist = require('optimist');
const express = require('express');
const multer = require('multer');
const bodyParser = require('body-parser');
Expand All @@ -16,30 +15,43 @@ const Renderer = require('./lib/renderer.js');
const Helpers = require('./lib/helpers.js');
const Indexer = require('./lib/indexer.js');

const args = optimist
const yargs = require('yargs/yargs')(process.argv.slice(2))
.usage(`\n${pkg.name} ${pkg.version}\nUsage: $0 [root dir] [options]`)
.alias('p', 'port')
.describe('p', 'Port number to listen on')
.default('p', 4040)
.alias('h', 'host')
.describe('h', 'Host address to bind to')
.default('h', 'localhost')
.alias('i', 'images-dir')
.describe('i', 'Directory to store images')
.default('i', 'images')
.alias('o', 'open')
.boolean('o')
.describe('o', 'Open default browser on start')
.alias('r', 'readonly')
.boolean('r')
.describe('r', 'Read-only mode (no add or edit feature)')
.alias('e', 'export')
.describe('e', 'Export static html')
.describe('help', 'Show this help')
.argv;
.version(false)
.option('port', {
alias: 'p',
describe: 'Port number to listen on',
default: 4040
})
.option('host', {
alias: 'h',
describe: 'Host address to bind to',
default: 'localhost'
})
.option('images-dir', {
alias: 'i',
describe: 'Directory to store images',
default: 'images'
})
.option('open', {
alias: 'o',
describe: 'Open default browser on start'
})
.option('readonly', {
alias: 'r',
describe: 'Read-only mode (no add or edit feature)'
})
.option('export', {
alias: 'e',
describe: 'Export static html'
})
.help(false) // Needed to avoid extra [boolean] type
.option('help', {describe: 'Show this help'});

const args = yargs.argv;

if (args.help || args._.length > 1) {
optimist.showHelp(console.log);
yargs.showHelp(console.log);
process.exit();
}

Expand Down
Loading

0 comments on commit d311d00

Please sign in to comment.