Skip to content

Commit db10b77

Browse files
Merge pull request #2 from udithavithanage/cli/add-commands
Implement version command in CLI
2 parents 7ed9055 + b037105 commit db10b77

File tree

6 files changed

+172
-14
lines changed

6 files changed

+172
-14
lines changed

.gitignore

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# -------------------------
2+
# OS-SPECIFIC FILES
3+
# -------------------------
4+
5+
# macOS
6+
.DS_Store
7+
.AppleDouble
8+
.LSOverride
9+
10+
# Windows
11+
Thumbs.db
12+
Thumbs.db:encryptable
13+
Desktop.ini
14+
$RECYCLE.BIN/
15+
16+
# Linux
17+
*~
18+
19+
# -------------------------
20+
# EDITORS / IDEs
21+
# -------------------------
22+
23+
# VS Code
24+
.vscode/
25+
*.code-workspace
26+
27+
# JetBrains IDEs (IntelliJ, PyCharm, WebStorm, etc.)
28+
.idea/
29+
*.iml
30+
out/
31+
gen/
32+
33+
# Sublime Text
34+
*.sublime-workspace
35+
*.sublime-project
36+
37+
# Vim
38+
*.swp
39+
*.swo
40+
41+
# Emacs
42+
*~
43+
44+
# -------------------------
45+
# PROGRAMMING LANGUAGES
46+
# -------------------------
47+
48+
# Node / JavaScript
49+
node_modules/
50+
npm-debug.log*
51+
yarn-debug.log*
52+
yarn-error.log*
53+
pnpm-debug.log*
54+
dist/
55+
build/
56+
.env
57+
.env.*.local
58+
59+
# Python
60+
__pycache__/
61+
*.py[cod]
62+
*.pyo
63+
*.pyd
64+
*.pdb
65+
*.egg-info/
66+
.eggs/
67+
.env/
68+
.venv/
69+
venv/
70+
pip-log.txt
71+
72+
# Java
73+
*.class
74+
*.jar
75+
*.war
76+
*.ear
77+
target/
78+
hs_err_pid*
79+
80+
# Go
81+
bin/
82+
vendor/
83+
*.exe
84+
85+
# Rust
86+
target/
87+
Cargo.lock
88+
89+
# PHP / Composer
90+
vendor/
91+
composer.lock
92+
93+
# Ruby
94+
.bundle/
95+
log/
96+
tmp/
97+
*.gem
98+
99+
# C/C++
100+
*.o
101+
*.obj
102+
*.so
103+
*.exe
104+
*.dll
105+
*.dylib
106+
107+
# -------------------------
108+
# VERSION CONTROL
109+
# -------------------------
110+
111+
# Git
112+
*.orig
113+
*.bak
114+
115+
# -------------------------
116+
# PROJECT FILES
117+
# -------------------------
118+
119+
# Logs
120+
logs/
121+
*.log
122+
npm-debug.log*
123+
yarn-debug.log*
124+
125+
# Temporary files
126+
tmp/
127+
temp/
128+
.cache/
129+
130+
# Compiled files
131+
*.out
132+
*.class
133+
134+
# Environment settings
135+
.env
136+
.env.local
137+
.env.*.local

bin/thyra.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env node
22

3-
import { run } from "../src/cli.js";
4-
5-
run();
3+
import "../src/cli.js";

src/cli.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ConfigStore } from "./configStore.js";
22
import { runConfig } from "./commands/config.js";
3+
import { runVersion } from "./commands/version.js";
34
import { runOpen } from "./commands/open.js";
45
import { runList } from "./commands/list.js";
56
import { runHelp } from "./commands/help.js";
67
import { getConfigFilePath } from "./configStore.js";
78

8-
export function run() {
9+
(function run() {
910
const [, , command, ...rest] = process.argv;
1011

1112
const configPath = getConfigFilePath();
@@ -21,6 +22,11 @@ export function run() {
2122
return;
2223
}
2324

25+
if (command === "version" || command === "--version" || command === "-v") {
26+
runVersion();
27+
return;
28+
}
29+
2430
switch (command) {
2531
case "config":
2632
runConfig(store, rest);
@@ -39,4 +45,4 @@ export function run() {
3945
runHelp(1);
4046
break;
4147
}
42-
}
48+
})();

src/commands/help.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
export function runHelp(exitCode) {
22
console.log(`
33
thyra - Quick shortcut manager for project folders
4+
`);
45

5-
Usage:
6-
thyra config <name> <folder_path> Save a folder path
7-
thyra open <name> Open folder in your editor
8-
thyra list Show all saved paths
9-
thyra help Show this help
6+
console.table([
7+
{
8+
Command: "thyra config <name> <folder_path>",
9+
Description: "Save a folder path",
10+
},
11+
{ Command: "thyra open <name>", Description: "Open folder in your editor" },
12+
{ Command: "thyra list", Description: "Show all saved paths" },
13+
{ Command: "thyra --version", Description: "Show CLI version" },
14+
{ Command: "thyra --help", Description: "Show this help" },
15+
]);
1016

17+
console.log(`
1118
Examples:
1219
thyra config my-app ~/projects/my-app
1320
thyra open my-app
21+
thyra --version
1422
1523
Environment:
1624
THYRA_EDITOR Editor command (default: "code")

src/commands/list.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export function runList(store) {
88
return;
99
}
1010

11-
console.log("Saved folders:");
12-
for (const key of keys) {
13-
console.log(` ${key} -> ${all[key]}`);
14-
}
11+
const rows = keys.map((key) => ({
12+
Name: key,
13+
Path: all[key],
14+
}));
15+
16+
console.log("\nSaved folders:\n");
17+
console.table(rows);
1518
}

src/commands/version.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import fs from "fs";
2+
3+
export function runVersion() {
4+
const data = JSON.parse(fs.readFileSync("package.json", "utf8"));
5+
console.log(`v${data.version}`);
6+
}

0 commit comments

Comments
 (0)