-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env tsx | ||
import process from 'node:process' | ||
|
||
import arg from 'arg' | ||
import camelcaseKeys from 'camelcase-keys' | ||
|
||
import {cliClient} from './modules/cli-client.js' | ||
import Umbreld, {type UmbreldOptions} from './index.js' | ||
|
||
// Quick trpc client for testing | ||
if (process.argv.includes('client')) { | ||
const clientIndex = process.argv.indexOf('client') | ||
const query = process.argv[clientIndex + 1] | ||
const args = process.argv.slice(clientIndex + 2) | ||
|
||
await cliClient({query, args}) | ||
process.exit(0) | ||
} | ||
|
||
const showHelp = () => | ||
console.log(` | ||
Usage | ||
$ umbreld | ||
Options | ||
--help Shows this help message | ||
--data-directory Your Umbrel data directory | ||
--port The port to listen on | ||
--log-level The logging intensity: silent|normal|verbose | ||
--default-app-store-repo The default app store repository | ||
Examples | ||
$ umbreld --data-directory ~/umbrel | ||
`) | ||
|
||
const args = camelcaseKeys( | ||
arg({ | ||
'--help': Boolean, | ||
'--data-directory': String, | ||
'--port': Number, | ||
'--log-level': String, | ||
'--default-app-store-repo': String, | ||
}), | ||
) | ||
|
||
if (args.help) { | ||
showHelp() | ||
process.exit(0) | ||
} | ||
|
||
// TODO: Validate these args are valid | ||
const umbreld = new Umbreld(args as UmbreldOptions) | ||
|
||
process.once('uncaughtException', async () => { | ||
umbreld.logger.log(`Received signal, shutting down cleanly...`) | ||
await umbreld.stop() | ||
process.exit(0) | ||
}) | ||
|
||
process.once('SIGINT', () => { throw new Error('SIGINT') }) | ||
process.once('SIGTERM', () => { throw new Error('SIGTERM') }) | ||
|
||
try { | ||
await umbreld.start() | ||
} catch (error) { | ||
console.error(process.env.NODE_ENV === 'production' ? (error as Error).message : error) | ||
process.exit(1) | ||
} |