new command: debug, to toggle debug messages
Massimo Melina committed
Mar 11, 2026 at 21:35 UTC
bec9bf5a6f7ca56f9f17dbb9a5ed3776edced7e0
2 files changed
+15
-5
src/commands.ts
+15
-3
@@ -17,6 +17,8 @@ import apiMonitor from './api.monitor'
17
import { argv } from './argv'
18
import { getServerStatus } from './listen'
19
20
+let debugEnabled = argv.debug || process.env.HFS_DEBUG
21
+
22
if (!argv.updating && !showHelp) {
23
try {
24
// Not sure if the try is necessary for when stdin is unavailable, but someone reported a problem using nohup https://github.com/rejetto/hfs/issues/74 and I've found this example try-catching https://github.com/DefinitelyTyped/DefinitelyTyped/blob/dda83a906914489e09ca28afea12948529015d4a/types/node/readline.d.ts#L489
@@ -27,7 +29,7 @@ if (!argv.updating && !showHelp) {
29
30
let isClean = true
31
const showPrompt = tty && _.debounce(() => {
30
- if (quitting || !tty) return
32
+ if (quitting || !tty || !isClean) return
33
prompter.prompt(true)
34
isClean = false
35
}, 100)
@@ -40,11 +42,12 @@ if (!argv.updating && !showHelp) {
42
43
showPrompt?.()
44
for (const k of ['log', 'warn', 'error', 'debug'] as const) {
43
- const v = console[k]
45
+ const original = console[k]
46
;(console as any)[k] = (...args: any[]) => {
47
+ if (k === 'debug' && !debugEnabled) return
48
if (!quitting && tty)
49
clean()
47
- try { v(...args) }
50
+ try { original(...args) }
51
finally {
52
showPrompt?.()
53
}
@@ -54,6 +57,8 @@ if (!argv.updating && !showHelp) {
57
}
58
catch {
59
console.log("console commands not available")
60
+ const original = console.debug
61
+ console.debug = (...args: any[]) => debugEnabled && original(...args)
62
}
63
}
64
@@ -155,6 +160,13 @@ const commands = {
160
console.log(VERSION, 'build', BUILD_TIMESTAMP)
161
}
162
},
163
+ debug: {
164
+ params: '',
165
+ cb() {
166
+ debugEnabled = !debugEnabled
167
+ console.log(`debug messages ${debugEnabled ? "on" : "off"}`)
168
+ }
169
+ },
170
'start-plugin': {
171
params: '<name>',
172
cb: startPlugin,
src/const.ts
-2
@@ -46,13 +46,11 @@ if (DEV) {
46
console.clear()
47
process.env.DEBUG = 'acme-client'
48
}
49
-else if (!argv.debug && !process.env.HFS_DEBUG) console.debug = ()=>{}
49
console.log(`HFS ~ HTTP File Server`)
50
console.log(`© Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt`)
51
console.log('started', formatTimestamp(HFS_STARTED), DEV)
52
console.log('version', VERSION||'-')
53
console.log('build', BUILD_TIMESTAMP||'-')
55
-console.debug('arguments', argv)
54
// still considering whether to use ".hfs" with Windows users, who may be less accustomed to it
55
const dir = argv.cwd || useHomeDir() && join(homedir(), '.hfs')
56
if (dir) {