mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: cli: detect mongosh
This commit is contained in:
1 parent
092c0ee4eb
commit
aac27b3f83
1 file changed
+7
@@ -60,7 +60,14 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
|||||||
cli.command('db').action(() => {
|
cli.command('db').action(() => {
|
||||||
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
|
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
|
||||||
const url = buildUrl(JSON.parse(dbConfig));
|
const url = buildUrl(JSON.parse(dbConfig));
|
||||||
|
try {
|
||||||
|
console.log('Detecting mongosh...');
|
||||||
|
const mongosh = child.execSync('mongosh --version').toString();
|
||||||
|
if (/\d+\.\d+\.\d+/.test(mongosh)) child.spawn('mongosh', [url], { stdio: 'inherit' });
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Cannot run mongosh. Trying legacy mongo client...');
|
||||||
child.spawn('mongo', [url], { stdio: 'inherit' });
|
child.spawn('mongo', [url], { stdio: 'inherit' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
cli.command('backup').action(() => {
|
cli.command('backup').action(() => {
|
||||||
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
|
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
|
||||||
|
|||||||
Reference in new issue
Block a user