Add `version` command (#129)

This commit is contained in:
Piotr Rogowski 2022-10-18 12:48:40 +02:00 committed by GitHub
parent 781dd7579d
commit d80fbc7571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 8 deletions

View File

@ -28,10 +28,14 @@ npm i --save @hyper-tuner/ini
You can also run this package as a CLI tool.
First you need to provide PAT as a ENV:
First you need to authenticate to GitHub Packages:
```bash
export NPM_GITHUB_TOKEN=my_github_personal_access_token
npm login --scope=@hyper-tuner --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
```
No you can run the tool:

View File

@ -2,8 +2,10 @@
import { INI } from './ini';
import fs from 'fs';
import { version } from '.';
enum Commands {
VERSION = 'version',
VALIDATE = 'validate',
}
@ -18,6 +20,10 @@ const showUsage = () => {
process.exit(1);
};
const showVersion = () => {
console.info(`\n Version: ${version}`);
};
const validate = (filename: string) => {
const ini = new INI(loadFile(filename));
@ -41,17 +47,21 @@ if (!command) {
process.exit(1);
}
if (!filename) {
console.info('❗️ Please provide a file name');
showUsage();
process.exit(1);
}
switch (command) {
case Commands.VALIDATE:
if (!filename) {
console.info('❗️ Please provide a file name');
showUsage();
process.exit(1);
}
showVersion();
validate(filename);
break;
case Commands.VERSION:
showVersion();
break;
default:
console.info(`❗️ Unknown command: ${command}, please use one of: [${Object.values(Commands).join(', ')}]`);
process.exit(1);

View File

@ -1 +1,2 @@
export * from './ini';
export const version = '0.5.1';