@rhseung/ps-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/utils/problem-id.ts
4
+ function detectProblemIdFromPath(cwd = process.cwd()) {
5
+ const normalizedPath = cwd.replace(/\\/g, "/");
6
+ const problemsIndex = normalizedPath.indexOf("/problems/");
7
+ if (problemsIndex === -1) {
8
+ return null;
9
+ }
10
+ const afterProblems = normalizedPath.substring(
11
+ problemsIndex + "/problems/".length
12
+ );
13
+ if (!afterProblems) {
14
+ return null;
15
+ }
16
+ const firstSegment = afterProblems.split("/")[0];
17
+ if (!firstSegment) {
18
+ return null;
19
+ }
20
+ const problemId = parseInt(firstSegment, 10);
21
+ if (isNaN(problemId) || problemId <= 0) {
22
+ return null;
23
+ }
24
+ if (firstSegment !== problemId.toString()) {
25
+ return null;
26
+ }
27
+ return problemId;
28
+ }
29
+ function getProblemId(args, cwd = process.cwd()) {
30
+ if (args.length > 0 && args[0]) {
31
+ const problemId = parseInt(args[0], 10);
32
+ if (!isNaN(problemId) && problemId > 0) {
33
+ return problemId;
34
+ }
35
+ }
36
+ return detectProblemIdFromPath(cwd);
37
+ }
38
+
39
+ export {
40
+ detectProblemIdFromPath,
41
+ getProblemId
42
+ };
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/utils/language.ts
4
+ var SUPPORTED_LANGUAGES = ["python", "cpp"];
5
+ function getSupportedLanguages() {
6
+ return [...SUPPORTED_LANGUAGES];
7
+ }
8
+ function getSupportedLanguagesString() {
9
+ return SUPPORTED_LANGUAGES.join(", ");
10
+ }
11
+ var LANGUAGE_CONFIGS = {
12
+ python: {
13
+ extension: "py",
14
+ templateFile: "solution.py",
15
+ runCommand: "python3",
16
+ bojLangId: 28
17
+ // Python 3
18
+ },
19
+ cpp: {
20
+ extension: "cpp",
21
+ templateFile: "solution.cpp",
22
+ // 절대 경로로 에러를 표시해서 에디터에서 문제 디렉토리의 파일로 바로 이동할 수 있도록 함
23
+ compileCommand: "g++ -fdiagnostics-absolute-paths -o solution solution.cpp",
24
+ runCommand: "./solution",
25
+ bojLangId: 84
26
+ // C++17
27
+ }
28
+ };
29
+ function getLanguageConfig(language) {
30
+ return LANGUAGE_CONFIGS[language];
31
+ }
32
+ function detectLanguageFromFile(filename) {
33
+ const ext = filename.split(".").pop()?.toLowerCase();
34
+ if (!ext) return null;
35
+ switch (ext) {
36
+ case "py":
37
+ return "python";
38
+ case "cpp":
39
+ case "cc":
40
+ case "cxx":
41
+ return "cpp";
42
+ default:
43
+ return null;
44
+ }
45
+ }
46
+
47
+ export {
48
+ getSupportedLanguages,
49
+ getSupportedLanguagesString,
50
+ getLanguageConfig,
51
+ detectLanguageFromFile
52
+ };
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ getAutoOpenEditor,
4
+ getBojSessionCookie,
5
+ getCodeOpen,
6
+ getDefaultLanguage,
7
+ getEditor,
8
+ getSolvedAcHandle,
9
+ setAutoOpenEditor,
10
+ setBojSessionCookie,
11
+ setCodeOpen,
12
+ setDefaultLanguage,
13
+ setEditor,
14
+ setSolvedAcHandle
15
+ } from "../chunk-KFQFQJYT.js";
16
+ import {
17
+ getSupportedLanguages,
18
+ getSupportedLanguagesString
19
+ } from "../chunk-TQXMB7XV.js";
20
+ import "../chunk-FYS2JH42.js";
21
+
22
+ // src/commands/config.tsx
23
+ import { render, Text, Box } from "ink";
24
+ import { jsx, jsxs } from "react/jsx-runtime";
25
+ function getConfigHelp() {
26
+ return `
27
+ \uC0AC\uC6A9\uBC95:
28
+ $ ps config <\uD0A4> [\uAC12]
29
+ $ ps config <\uD0A4> --get
30
+ $ ps config --list
31
+
32
+ \uC124\uBA85:
33
+ \uC0AC\uC6A9\uC790 \uC124\uC815\uC744 \uAD00\uB9AC\uD569\uB2C8\uB2E4.
34
+ \uC124\uC815\uC740 ~/.config/ps-cli/config.json\uC5D0 \uC800\uC7A5\uB429\uB2C8\uB2E4.
35
+
36
+ \uC124\uC815 \uD0A4:
37
+ boj-session-cookie BOJ \uC138\uC158 \uCFE0\uD0A4
38
+ default-language \uAE30\uBCF8 \uC5B8\uC5B4 (${getSupportedLanguagesString()})
39
+ code-open \uCF54\uB4DC \uACF5\uAC1C \uC5EC\uBD80 (true/false)
40
+ editor \uC5D0\uB514\uD130 \uBA85\uB839\uC5B4 (\uC608: code, vim, nano)
41
+ auto-open-editor fetch \uD6C4 \uC790\uB3D9\uC73C\uB85C \uC5D0\uB514\uD130 \uC5F4\uAE30 (true/false)
42
+ solved-ac-handle Solved.ac \uD578\uB4E4 (stats \uBA85\uB839\uC5B4\uC6A9)
43
+
44
+ \uC635\uC158:
45
+ --get \uC124\uC815 \uAC12 \uC870\uD68C
46
+ --list \uBAA8\uB4E0 \uC124\uC815 \uC870\uD68C
47
+ --help, -h \uB3C4\uC6C0\uB9D0 \uD45C\uC2DC
48
+
49
+ \uC608\uC81C:
50
+ $ ps config boj-session-cookie "boj_session=xxx"
51
+ $ ps config default-language python
52
+ $ ps config solved-ac-handle myhandle
53
+ $ ps config solved-ac-handle --get
54
+ $ ps config --list
55
+ `;
56
+ }
57
+ var configHelp = getConfigHelp();
58
+ function ConfigCommand({
59
+ configKey,
60
+ value,
61
+ get,
62
+ list,
63
+ onComplete
64
+ }) {
65
+ if (list) {
66
+ const bojCookie = getBojSessionCookie();
67
+ const defaultLang = getDefaultLanguage();
68
+ const codeOpen = getCodeOpen();
69
+ const editor = getEditor();
70
+ const autoOpen = getAutoOpenEditor();
71
+ const handle = getSolvedAcHandle();
72
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
73
+ /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, children: "\uD604\uC7AC \uC124\uC815:" }) }),
74
+ /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
75
+ /* @__PURE__ */ jsxs(Text, { children: [
76
+ "boj-session-cookie:",
77
+ " ",
78
+ /* @__PURE__ */ jsx(Text, { color: bojCookie ? "green" : "gray", children: bojCookie ? "\uC124\uC815\uB428" : "\uC124\uC815 \uC548 \uB428" })
79
+ ] }),
80
+ /* @__PURE__ */ jsxs(Text, { children: [
81
+ "default-language: ",
82
+ /* @__PURE__ */ jsx(Text, { bold: true, children: defaultLang })
83
+ ] }),
84
+ /* @__PURE__ */ jsxs(Text, { children: [
85
+ "code-open: ",
86
+ /* @__PURE__ */ jsx(Text, { bold: true, children: codeOpen ? "true" : "false" })
87
+ ] }),
88
+ /* @__PURE__ */ jsxs(Text, { children: [
89
+ "editor: ",
90
+ /* @__PURE__ */ jsx(Text, { bold: true, children: editor })
91
+ ] }),
92
+ /* @__PURE__ */ jsxs(Text, { children: [
93
+ "auto-open-editor: ",
94
+ /* @__PURE__ */ jsx(Text, { bold: true, children: autoOpen ? "true" : "false" })
95
+ ] }),
96
+ /* @__PURE__ */ jsxs(Text, { children: [
97
+ "solved-ac-handle: ",
98
+ /* @__PURE__ */ jsx(Text, { bold: true, children: handle || "\uC124\uC815 \uC548 \uB428" })
99
+ ] })
100
+ ] })
101
+ ] });
102
+ }
103
+ if (get && configKey) {
104
+ let configValue;
105
+ switch (configKey) {
106
+ case "boj-session-cookie":
107
+ configValue = getBojSessionCookie();
108
+ break;
109
+ case "default-language":
110
+ configValue = getDefaultLanguage();
111
+ break;
112
+ case "code-open":
113
+ configValue = getCodeOpen() ? "true" : "false";
114
+ break;
115
+ case "editor":
116
+ configValue = getEditor();
117
+ break;
118
+ case "auto-open-editor":
119
+ configValue = getAutoOpenEditor() ? "true" : "false";
120
+ break;
121
+ case "solved-ac-handle":
122
+ configValue = getSolvedAcHandle();
123
+ break;
124
+ default:
125
+ console.error(`\uC54C \uC218 \uC5C6\uB294 \uC124\uC815 \uD0A4: ${configKey}`);
126
+ process.exit(1);
127
+ }
128
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { children: configValue || "(\uC124\uC815 \uC548 \uB428)" }) });
129
+ }
130
+ if (configKey && value !== void 0) {
131
+ switch (configKey) {
132
+ case "boj-session-cookie":
133
+ setBojSessionCookie(value);
134
+ break;
135
+ case "default-language":
136
+ const supportedLanguages = getSupportedLanguages();
137
+ if (!supportedLanguages.includes(value)) {
138
+ console.error(
139
+ `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5B8\uC5B4\uC785\uB2C8\uB2E4: ${value}
140
+ \uC9C0\uC6D0 \uC5B8\uC5B4: ${getSupportedLanguagesString()}`
141
+ );
142
+ process.exit(1);
143
+ }
144
+ setDefaultLanguage(value);
145
+ break;
146
+ case "code-open":
147
+ setCodeOpen(value === "true");
148
+ break;
149
+ case "editor":
150
+ setEditor(value);
151
+ break;
152
+ case "auto-open-editor":
153
+ setAutoOpenEditor(value === "true");
154
+ break;
155
+ case "solved-ac-handle":
156
+ setSolvedAcHandle(value);
157
+ break;
158
+ default:
159
+ console.error(`\uC54C \uC218 \uC5C6\uB294 \uC124\uC815 \uD0A4: ${configKey}`);
160
+ process.exit(1);
161
+ }
162
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: "green", children: [
163
+ "\u2713 \uC124\uC815\uC774 \uC800\uC7A5\uB418\uC5C8\uC2B5\uB2C8\uB2E4: ",
164
+ configKey,
165
+ " = ",
166
+ value
167
+ ] }) });
168
+ }
169
+ return null;
170
+ }
171
+ async function configCommand(configKey, value, get, list) {
172
+ return new Promise((resolve) => {
173
+ const { unmount } = render(
174
+ /* @__PURE__ */ jsx(
175
+ ConfigCommand,
176
+ {
177
+ configKey,
178
+ value,
179
+ get,
180
+ list,
181
+ onComplete: () => {
182
+ unmount();
183
+ resolve();
184
+ }
185
+ }
186
+ )
187
+ );
188
+ setTimeout(() => {
189
+ unmount();
190
+ resolve();
191
+ }, 100);
192
+ });
193
+ }
194
+ async function configExecute(args, flags) {
195
+ if (flags.help) {
196
+ console.log(getConfigHelp().trim());
197
+ process.exit(0);
198
+ return;
199
+ }
200
+ if (flags.list) {
201
+ await configCommand(void 0, void 0, false, true);
202
+ return;
203
+ }
204
+ const key = args[0];
205
+ const value = args[1];
206
+ if (!key) {
207
+ console.error("\uC624\uB958: \uC124\uC815 \uD0A4\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694.");
208
+ console.error(`\uC0AC\uC6A9\uBC95: ps config <\uD0A4> [\uAC12]`);
209
+ console.error(`\uB3C4\uC6C0\uB9D0: ps config --help`);
210
+ process.exit(1);
211
+ }
212
+ if (flags.get) {
213
+ await configCommand(key, void 0, true, false);
214
+ } else if (value !== void 0) {
215
+ await configCommand(key, value, false, false);
216
+ } else {
217
+ console.error("\uC624\uB958: \uC124\uC815 \uAC12\uC744 \uC785\uB825\uD558\uAC70\uB098 --get \uC635\uC158\uC744 \uC0AC\uC6A9\uD574\uC8FC\uC138\uC694.");
218
+ console.error(`\uC0AC\uC6A9\uBC95: ps config <\uD0A4> <\uAC12>`);
219
+ console.error(`\uC0AC\uC6A9\uBC95: ps config <\uD0A4> --get`);
220
+ process.exit(1);
221
+ }
222
+ }
223
+ var configCommandDef = {
224
+ name: "config",
225
+ help: configHelp,
226
+ execute: configExecute
227
+ };
228
+ var config_default = configCommandDef;
229
+ export {
230
+ configExecute,
231
+ configHelp,
232
+ config_default as default,
233
+ getConfigHelp
234
+ };