Skip to content

Commit 11d84f4

Browse files
authored
feat: Enhance help command output with styled text and dynamic options (#63)
- Updated the `help` function in `commands.mjs` to include styled text for better readability. - Added dynamic generation of command options based on the configuration, improving the help output's clarity and usability. - Refactored the import statements in `index.mjs` for consistency and improved module loading.
1 parent 13bb61f commit 11d84f4

2 files changed

Lines changed: 53 additions & 20 deletions

File tree

β€Žcli/commands.mjsβ€Ž

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as fs from 'node:fs/promises';
33
import { homedir } from 'node:os';
44
import { dirname, resolve } from 'node:path';
55
import { fileURLToPath } from 'node:url';
6+
import { styleText } from 'node:util';
7+
import { config } from './index.mjs';
68
import { downloadFiles, downloadSelectedFiles } from './utils/download-files.mjs';
79
import { findPackageRoot } from './utils/find-package-root.mjs';
810
import { interactiveCategorySelection, prepareMenu, scanAvailableRules, selectRules } from './utils/interactive-menu.mjs';
@@ -15,26 +17,58 @@ const defaultOutput = resolve(homedir(), 'Downloads', '.cursor');
1517

1618
/** @returns {void} */
1719
export const help = () => {
18-
const repository = packageJson?.repository?.url?.replace('git+', '').replace('.git', '') ?? 'https://github.com/usrrname/cursorrules';
20+
21+
const repository = packageJson?.repository?.url?.replace('git+', '').replace('.git', '') ?? 'https://github.com/usrrname/cursorrules'
22+
23+
const repoLink = styleText('underline', repository)
1924
const version = packageJson?.version;
25+
const title = styleText(['bgMagenta'], `@usrrname/cursorrules v${version}`)
26+
const description = packageJson?.description + ` ✦`;
27+
const usage = styleText('magentaBright', `npx @usrrname/cursorrules`)
28+
const options = styleText('dim', `[options]`)
29+
30+
/** @param {string} key */
31+
const getFlagDescription = (key) => {
32+
switch (key) {
33+
case 'flat':
34+
return styleText('green', 'install all rules without parent directory');
35+
case 'help':
36+
return styleText('green', 'help instructions');
37+
case 'interactive':
38+
return styleText('green', 'select the rules you want');
39+
case 'output':
40+
return styleText('green', 'set output directory (Default: .cursor/)');
41+
case 'version':
42+
return styleText('green', 'show package version');
43+
case 'interactive':
44+
return styleText('green', 'select the rules you want');
45+
}
46+
}
47+
const tableContent = Object.entries(config?.options || {}).map(([key, value]) => {
48+
return {
49+
flag: `-${value?.short}`,
50+
name: `--${key}`,
51+
description: getFlagDescription(key),
52+
type: value?.type,
53+
default: value?.default ? `(Default: ${value?.default})` : '',
54+
}
55+
})
2056

2157
console.info(`
22-
╔══════════════════════════════════════╗
23-
β•‘ @usrrname/cursorrules v${version} β•‘
24-
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
25-
A standard library of Cursor Rules ...with otaku vibes (βœΏα΄—ΝˆΛ¬α΄—Νˆ)⁾⁾
26-
27-
Usage:
28-
=======================================
29-
npx @usrrname/cursorrules [options]
30-
31-
Options:
32-
-f, --flat: Install all rules without parent directory
33-
-h, --help: Help instructions <----- You are here
34-
-i, --interactive: Select the rules you want
35-
-o, --output: Set output directory (Default: .cursor/)
36-
-v, --version: Show package version
37-
${repository}
58+
╔══════════════════════════════════════╗
59+
β•‘ ${title} β•‘
60+
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
61+
(βœΏα΄—ΝˆΛ¬α΄—Νˆ)⁾⁾
62+
63+
${description}
64+
65+
Usage:
66+
========================================
67+
${usage} ${options}
68+
69+
${tableContent.map(item => `${item.name} ${item.flag} ${item.type} ${item.description} ${item.default}`).join('\n')}
70+
71+
${repoLink}
3872
`);
3973
}
4074

β€Žcli/index.mjsβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
'use strict'
33
import { join, resolve } from 'node:path';
44
import { parseArgs } from 'node:util';
5-
const { downloadFiles } = await import('./utils/download-files.mjs');
6-
const { help, interactiveMode, output, version } = await import('./commands.mjs');
7-
5+
import { help, interactiveMode, output, version } from './commands.mjs';
6+
import { downloadFiles } from './utils/download-files.mjs';
87
/** project root @type {string} */
98
export const projectRoot = resolve(import.meta.dirname, '..')
109
export const defaultCursorPath = join(projectRoot, '.cursor');

0 commit comments

Comments
Β (0)