Skip to content

Commit 66aed68

Browse files
committed
Add CLI - WIP
1 parent ecea141 commit 66aed68

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

bin/advent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
const cli = require('../src/cli');
3+
4+
cli();

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"lint": "eslint .",
66
"test": "jest"
77
},
8+
"bin": {
9+
"advent": "./bin/advent.js"
10+
},
811
"main": "index.js",
912
"author": "Hank",
1013
"license": "MIT",
@@ -16,6 +19,7 @@
1619
"jest": "^23.6.0"
1720
},
1821
"dependencies": {
22+
"commander": "^2.19.0",
1923
"dotenv": "^6.1.0",
2024
"find-config": "^1.0.0",
2125
"node-fetch": "^2.3.0",

src/cli.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require('path');
2+
const { Command } = require('commander');
3+
4+
const init = require('./init');
5+
6+
7+
const main = (args = process.argv, program = new Command()) => {
8+
const defaultNameTemplate = 'solve.js';
9+
const defaultTemplateFile = path.resolve(__dirname, 'templates', 'day.js');
10+
11+
program.on(
12+
'--help', () => {
13+
console.log('hej');
14+
},
15+
);
16+
17+
let action;
18+
19+
program
20+
.command('init <day>')
21+
.description('Initalize a given day')
22+
.option(
23+
'-n, --name-template [template',
24+
'The template filename',
25+
defaultNameTemplate,
26+
)
27+
.option(
28+
'-t, --template-file [filepath]',
29+
'The path to the template file',
30+
defaultTemplateFile,
31+
)
32+
.action((day, command) => {
33+
action = init();
34+
});
35+
36+
program.parse(args);
37+
38+
return action;
39+
};
40+
41+
module.exports = main;

src/init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const init = config => {
2+
return Promise.all([]);
3+
};
4+
5+
module.exports = init;

src/templates/day.js

Whitespace-only changes.

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
728728
dependencies:
729729
delayed-stream "~1.0.0"
730730

731+
commander@^2.19.0:
732+
version "2.19.0"
733+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
734+
integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==
735+
731736
commander@~2.17.1:
732737
version "2.17.1"
733738
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy