Skip to content

Commit

Permalink
Merge pull request #3 from phukon/next
Browse files Browse the repository at this point in the history
chore: semantic-release dependency and handle unknown args gracefully
  • Loading branch information
phukon authored Jan 12, 2025
2 parents 14658c5 + f465305 commit 239fade
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1,872 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- next

permissions:
contents: write
Expand All @@ -29,4 +28,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run semantic-release
run: npm run publish
80 changes: 54 additions & 26 deletions bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#!/usr/bin/env node
import arg from "arg";
import chalk from "chalk";
import { fileURLToPath } from 'url';
import { start } from "../src/commands/start";
import { reset } from "../src/commands/reset";
import { importKey } from "../src/commands/import";
import createLogger from "../src/utils/logger";
import boxen from 'boxen';
import { GitKeyKitCodes } from "../src/gitkeykitCodes";
import { dirname, join } from "path";
import { readFileSync } from "fs";

process.on("SIGINT", () => process.exit(GitKeyKitCodes.SUCCESS));
process.on("SIGTERM", () => process.exit(GitKeyKitCodes.SUCCESS));

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageJson = JSON.parse(
readFileSync(join(__dirname, '../package.json'), 'utf8')
);
const { version } = packageJson;

const logger = createLogger("bin");

function usage() {
console.log("\n");
console.log(chalk.blueBright(boxen('GitKeyKit - Simplify PGP key🔑 setup and signing commits on Linux and Windows.', {padding: 1, borderStyle: 'round'})));
console.log(chalk.blueBright(boxen('GitKeyKit - Simplify PGP key🔑 setup and signing commits on Linux and Windows machines.', {padding: 1, borderStyle: 'round'})));
console.log(chalk.whiteBright("Usage: gitkeykit\n"));
console.log(chalk.whiteBright("Options:"));
console.log(chalk.blueBright("--reset\t\t\tReset Git and GPG configurations"));
Expand Down Expand Up @@ -58,36 +68,54 @@ async function handleReset(): Promise<number> {
}

async function main(): Promise<number> {
const args = arg({
"--reset": Boolean,
"--help": Boolean,
"--import": String,
});
try {
const args = arg({
"--reset": Boolean,
"--help": Boolean,
"--import": String,
"--version": Boolean
});

logger.debug("Received args", args);
logger.debug("Received args", args);

// Handle commands similar to C version
if (Object.keys(args).length === 1) {
await start();
return GitKeyKitCodes.SUCCESS;
}
if (Object.keys(args).length === 1) {
await start();
return GitKeyKitCodes.SUCCESS;
}

if (args["--reset"]) {
return handleReset();
}
if (args["--reset"]) {
return handleReset();
}

if (args["--help"]) {
usage();
return GitKeyKitCodes.SUCCESS;
}
if (args["--help"]) {
usage();
return GitKeyKitCodes.SUCCESS;
}

if (args["--import"]) {
const keyPath = args["--import"];
return handleImport(keyPath);
}
if (args["--import"]) {
const keyPath = args["--import"];
return handleImport(keyPath);
}

if (args["--version"]) {
console.log(`v${version}`);
return GitKeyKitCodes.SUCCESS;
}

usage();
return GitKeyKitCodes.ERR_INVALID_ARGS;
usage();
return GitKeyKitCodes.ERR_INVALID_ARGS;
} catch (error: any) {
if (error?.code === 'ARG_UNKNOWN_OPTION') {
logger.error(`Invalid argument: ${error.message}`);
console.log('------');
usage();
return GitKeyKitCodes.ERR_INVALID_ARGS;
}

// Handle any other unexpected errors
logger.error('An unexpected error occurred:', error);
return GitKeyKitCodes.ERR_INVALID_ARGS;
}
}

// Execute and handle exit codes
Expand All @@ -96,4 +124,4 @@ main()
.catch(error => {
console.error('Unexpected error:', error);
process.exit(1);
});
});
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitkeykit",
"version": "2.0.5",
"version": "2.1.1",
"description": "Setup pgp keys and sign commits with ease on Linux and Windows machines.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down Expand Up @@ -28,8 +28,7 @@
"prebuild": "npm run clean",
"build": "tsup",
"preversion": "npm run build",
"postversion": "git push --tags",
"semantic-release": "semantic-release"
"postversion": "git push --tags"
},
"author": "Riki Phukon",
"license": "MIT",
Expand All @@ -45,7 +44,6 @@
"@types/debug": "^4.1.12",
"@types/node": "^20.11.30",
"rimraf": "^5.0.5",
"semantic-release": "^24.2.1",
"tsup": "^8.0.2",
"typescript": "^5.4.3"
}
Expand Down
Loading

0 comments on commit 239fade

Please sign in to comment.