Skip to content

Commit

Permalink
add help menu
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaceriani committed Apr 10, 2021
1 parent db2832b commit 8a30233
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"chalk": "^4.1.0",
"command-line-args": "^5.1.1",
"command-line-usage": "^6.1.1",
"fs-extra": "^9.1.0",
"inquirer": "^7.3.3",
"moment": "^2.29.1",
Expand Down
49 changes: 45 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,46 @@ const fs = require("fs-extra"); // per copiare tutta la cartella virtuale di nex
const moment = require("moment");
const po = require("./pretty-output");
const parseConfig = require("./config");

const commandLineArgs = require("command-line-args")
const commandLineUsage = require('command-line-usage')

const optionDefinitions = [
{ name: "backup", alias: "b", type: String },
{ name: "disco", alias: "d", type: String, },
{ name: "prova", alias: "p", type: Boolean, },
{
name: "backup",
alias: "b",
type: String,
description: "Il nome del task di backup da eseguire",
typeLabel: "{underline \"nome task\"}"
},
{
name: "disco",
alias: "d",
type: String,
description: "Il disco da utilizzare (con o senza i due punti) con la sinstassi ?: oppure ?ALL:",
typeLabel: "{underline disco}"

},
{
name: "prova",
alias: "p",
type: Boolean,
description: "Non effettua nessun backup, mostra invece il comando di rsync"
},
{
name: "help",
alias: "h",
type: Boolean,
description: "Mostra questa guida"
},
]

const helpMenu = [
{
header: "Opzioni",
optionList: optionDefinitions
}
]
/////////////////////////////////////////////////////////////////////


Expand All @@ -31,6 +63,11 @@ async function menu() {
throw ("Errore nei parametri\nOpzione sconoscuta: " + e.optionName)
}

if (options.help) {
po.log(commandLineUsage(helpMenu))
return "esci"
}

let cfg = parseConfig();

// se non sono a posto ritono (esco con attesa)
Expand Down Expand Up @@ -239,7 +276,11 @@ async function main() {
`)

try {
await menu();
let res = await menu();
if (res == "esci") {
po.key("\nPremere INVIO per uscire... ");
return;
}
} catch (err) {
po.err(err);
po.err("Errore imprevisto!");
Expand Down
48 changes: 48 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ array-back@^3.0.1:
resolved "https://registry.yarnpkg.com/array-back/-/array-back-3.1.0.tgz#b8859d7a508871c9a7b2cf42f99428f65e96bfb0"
integrity sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==

array-back@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/array-back/-/array-back-4.0.1.tgz#9b80312935a52062e1a233a9c7abeb5481b30e90"
integrity sha512-Z/JnaVEXv+A9xabHzN43FiiiWEE7gPCRXMrVmRm00tWbjZRul1iHm7ECzlyNq1p4a4ATXz+G9FJ3GqGOkOV3fg==

array-union@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
Expand Down Expand Up @@ -339,6 +344,16 @@ command-line-args@^5.1.1:
lodash.camelcase "^4.3.0"
typical "^4.0.0"

command-line-usage@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/command-line-usage/-/command-line-usage-6.1.1.tgz#c908e28686108917758a49f45efb4f02f76bc03f"
integrity sha512-F59pEuAR9o1SF/bD0dQBDluhpT4jJQNWUHEuVBqpDmCUo6gPjCi+m9fCWnWZVR/oG6cMTUms4h+3NPl74wGXvA==
dependencies:
array-back "^4.0.1"
chalk "^2.4.2"
table-layout "^1.0.1"
typical "^5.2.0"

commander@^2.19.0, commander@^2.8.1:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -441,6 +456,11 @@ decompress@^4.2.1:
pify "^2.3.0"
strip-dirs "^2.0.0"

deep-extend@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -1354,6 +1374,11 @@ readline-sync@^1.4.10:
resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.10.tgz#41df7fbb4b6312d673011594145705bf56d8873b"
integrity sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==

reduce-flatten@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/reduce-flatten/-/reduce-flatten-2.0.0.tgz#734fd84e65f375d7ca4465c69798c25c9d10ae27"
integrity sha512-EJ4UNY/U1t2P/2k6oqotuX2Cc3T6nxJwsM0N0asT7dhrtH1ltUxDn4NalSYmPE2rCkVpcf/X6R0wDwcFpzhd4w==

resolve-alpn@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.0.0.tgz#745ad60b3d6aff4b4a48e01b8c0bdc70959e0e8c"
Expand Down Expand Up @@ -1562,6 +1587,16 @@ supports-color@^7.1.0:
dependencies:
has-flag "^4.0.0"

table-layout@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-1.0.2.tgz#c4038a1853b0136d63365a734b6931cf4fad4a04"
integrity sha512-qd/R7n5rQTRFi+Zf2sk5XVVd9UQl6ZkduPFC3S7WEGJAmetDTjY3qPN50eSKzwuzEyQKy5TN2TiZdkIjos2L6A==
dependencies:
array-back "^4.0.1"
deep-extend "~0.6.0"
typical "^5.2.0"
wordwrapjs "^4.0.0"

tapable@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.0.tgz#5c373d281d9c672848213d0e037d1c4165ab426b"
Expand Down Expand Up @@ -1638,6 +1673,11 @@ typical@^4.0.0:
resolved "https://registry.yarnpkg.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4"
integrity sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==

typical@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/typical/-/typical-5.2.0.tgz#4daaac4f2b5315460804f0acf6cb69c52bb93066"
integrity sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==

unbzip2-stream@^1.0.9:
version "1.4.3"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7"
Expand Down Expand Up @@ -1675,6 +1715,14 @@ wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

wordwrapjs@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/wordwrapjs/-/wordwrapjs-4.0.1.tgz#d9790bccfb110a0fc7836b5ebce0937b37a8b98f"
integrity sha512-kKlNACbvHrkpIw6oPeYDSmdCTu2hdMHoyXLTcUKala++lx5Y+wjJ/e474Jqv5abnVmwxw08DiTuHmw69lJGksA==
dependencies:
reduce-flatten "^2.0.0"
typical "^5.2.0"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
Expand Down

0 comments on commit 8a30233

Please sign in to comment.